2021-03-08 22:35:20 +00:00
|
|
|
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
|
2021-04-20 04:08:25 +01:00
|
|
|
import { CosmosClient, PermissionMode } from "@azure/cosmos";
|
|
|
|
import { jest } from "@jest/globals";
|
|
|
|
import "expect-playwright";
|
2024-04-09 18:55:08 +01:00
|
|
|
import { generateUniqueName, getAzureCLICredentials } from "../utils/shared";
|
2021-04-20 04:08:25 +01:00
|
|
|
jest.setTimeout(120000);
|
2021-03-08 22:35:20 +00:00
|
|
|
|
2024-04-09 18:55:08 +01:00
|
|
|
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"] ?? "";
|
2021-03-08 22:35:20 +00:00
|
|
|
const resourceGroupName = "runners";
|
2021-01-19 22:31:55 +00:00
|
|
|
|
2021-04-20 04:08:25 +01:00
|
|
|
test("Resource token", async () => {
|
2024-04-09 18:55:08 +01:00
|
|
|
const credentials = await getAzureCLICredentials();
|
2021-04-20 04:08:25 +01:00
|
|
|
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
2022-05-05 02:24:34 +01:00
|
|
|
const account = await armClient.databaseAccounts.get(resourceGroupName, "portal-sql-runner-west-us");
|
|
|
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, "portal-sql-runner-west-us");
|
2021-04-21 18:45:34 +01:00
|
|
|
const dbId = generateUniqueName("db");
|
2021-04-20 04:08:25 +01:00
|
|
|
const collectionId = generateUniqueName("col");
|
|
|
|
const client = new CosmosClient({
|
|
|
|
endpoint: account.documentEndpoint,
|
|
|
|
key: keys.primaryMasterKey,
|
|
|
|
});
|
|
|
|
const { database } = await client.databases.createIfNotExists({ id: dbId });
|
|
|
|
const { container } = await database.containers.createIfNotExists({ id: collectionId });
|
|
|
|
const { user } = await database.users.upsert({ id: "testUser" });
|
|
|
|
const { resource: containerPermission } = await user.permissions.upsert({
|
|
|
|
id: "partitionLevelPermission",
|
|
|
|
permissionMode: PermissionMode.All,
|
|
|
|
resource: container.url,
|
|
|
|
});
|
|
|
|
const resourceTokenConnectionString = `AccountEndpoint=${account.documentEndpoint};DatabaseId=${database.id};CollectionId=${container.id};${containerPermission._token}`;
|
2021-01-19 22:31:55 +00:00
|
|
|
|
2021-04-20 04:08:25 +01:00
|
|
|
await page.goto("https://localhost:1234/hostedExplorer.html");
|
|
|
|
await page.waitForSelector("div > p.switchConnectTypeText");
|
|
|
|
await page.click("div > p.switchConnectTypeText");
|
|
|
|
await page.type("input[class='inputToken']", resourceTokenConnectionString);
|
|
|
|
await page.click("input[value='Connect']");
|
|
|
|
await page.waitForSelector("iframe");
|
2023-07-10 09:59:05 +01:00
|
|
|
const explorer = await page.frame({
|
2021-04-20 04:08:25 +01:00
|
|
|
name: "explorer",
|
2021-01-19 22:31:55 +00:00
|
|
|
});
|
2021-04-20 04:08:25 +01:00
|
|
|
await explorer.textContent(`css=.dataResourceTree >> "${collectionId}"`);
|
2021-01-19 22:31:55 +00:00
|
|
|
});
|