2024-06-05 20:46:32 +01:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
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";
|
2024-06-05 20:46:32 +01:00
|
|
|
import {
|
|
|
|
DataExplorer,
|
|
|
|
TestAccount,
|
|
|
|
generateUniqueName,
|
|
|
|
getAccountName,
|
|
|
|
getAzureCLICredentials,
|
|
|
|
resourceGroupName,
|
|
|
|
subscriptionId,
|
|
|
|
} from "../fx";
|
2021-01-19 22:31:55 +00:00
|
|
|
|
2024-06-05 20:46:32 +01:00
|
|
|
test("SQL account using Resource token", async ({ page }) => {
|
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);
|
2024-06-05 20:46:32 +01:00
|
|
|
const accountName = getAccountName(TestAccount.SQL);
|
|
|
|
const account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
|
|
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
2021-04-21 18:45:34 +01:00
|
|
|
const dbId = generateUniqueName("db");
|
2024-08-15 21:29:57 +01:00
|
|
|
const collectionId = "testcollection";
|
2021-04-20 04:08:25 +01:00
|
|
|
const client = new CosmosClient({
|
2024-05-29 17:56:27 +01:00
|
|
|
endpoint: account.documentEndpoint!,
|
2021-04-20 04:08:25 +01:00
|
|
|
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,
|
|
|
|
});
|
2024-06-05 20:46:32 +01:00
|
|
|
await expect(containerPermission).toBeDefined();
|
|
|
|
|
|
|
|
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");
|
2024-06-05 20:46:32 +01:00
|
|
|
const switchConnectionLink = page.getByTestId("Link:SwitchConnectionType");
|
|
|
|
await switchConnectionLink.waitFor();
|
|
|
|
await switchConnectionLink.click();
|
|
|
|
await page.getByPlaceholder("Please enter a connection string").fill(resourceTokenConnectionString);
|
|
|
|
await page.getByRole("button", { name: "Connect" }).click();
|
|
|
|
|
|
|
|
const explorer = await DataExplorer.waitForExplorer(page);
|
|
|
|
|
2024-08-01 18:02:36 +01:00
|
|
|
const collectionNode = explorer.treeNode(`${collectionId}`);
|
2024-06-05 20:46:32 +01:00
|
|
|
await collectionNode.element.waitFor();
|
|
|
|
await expect(collectionNode.element).toBeAttached();
|
2024-05-29 17:56:27 +01:00
|
|
|
|
2024-06-05 20:46:32 +01:00
|
|
|
await database.delete();
|
2021-01-19 22:31:55 +00:00
|
|
|
});
|