Move resourceToken test to portal runner sub (#499)

Co-authored-by: Steve Faulkner <stfaul@microsoft.com>
This commit is contained in:
Steve Faulkner 2021-03-08 16:35:20 -06:00 committed by GitHub
parent 4e702716bd
commit c844986c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -3,6 +3,14 @@ import "expect-puppeteer";
import { Frame } from "puppeteer"; import { Frame } from "puppeteer";
import { generateDatabaseName, generateUniqueName } from "../utils/shared"; import { generateDatabaseName, generateUniqueName } from "../utils/shared";
import { CosmosClient, PermissionMode } from "@azure/cosmos"; import { CosmosClient, PermissionMode } from "@azure/cosmos";
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
const clientId = process.env["NOTEBOOKS_TEST_RUNNER_CLIENT_ID"];
const secret = process.env["NOTEBOOKS_TEST_RUNNER_CLIENT_SECRET"];
const tenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47";
const subscriptionId = "69e02f2d-f059-4409-9eac-97e8a276ae2c";
const resourceGroupName = "runners";
jest.setTimeout(300000); jest.setTimeout(300000);
const RETRY_DELAY = 5000; const RETRY_DELAY = 5000;
@ -10,11 +18,16 @@ const CREATE_DELAY = 10000;
describe("Collection Add and Delete SQL spec", () => { describe("Collection Add and Delete SQL spec", () => {
it("creates a collection", async () => { it("creates a collection", async () => {
const credentials = await msRestNodeAuth.loginWithServicePrincipalSecret(clientId, secret, tenantId);
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
const account = await armClient.databaseAccounts.get(resourceGroupName, "portal-sql-runner");
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, "portal-sql-runner");
const dbId = generateDatabaseName(); const dbId = generateDatabaseName();
const collectionId = generateUniqueName("col"); const collectionId = generateUniqueName("col");
const connectionString = process.env.PORTAL_RUNNER_CONNECTION_STRING; const client = new CosmosClient({
const client = new CosmosClient(connectionString); endpoint: account.documentEndpoint,
const endpoint = /AccountEndpoint=(.*);/.exec(connectionString)[1]; key: keys.primaryMasterKey,
});
const { database } = await client.databases.createIfNotExists({ id: dbId }); const { database } = await client.databases.createIfNotExists({ id: dbId });
const { container } = await database.containers.createIfNotExists({ id: collectionId }); const { container } = await database.containers.createIfNotExists({ id: collectionId });
const { user } = await database.users.upsert({ id: "testUser" }); const { user } = await database.users.upsert({ id: "testUser" });
@ -23,7 +36,7 @@ describe("Collection Add and Delete SQL spec", () => {
permissionMode: PermissionMode.All, permissionMode: PermissionMode.All,
resource: container.url, resource: container.url,
}); });
const resourceTokenConnectionString = `AccountEndpoint=${endpoint};DatabaseId=${database.id};CollectionId=${container.id};${containerPermission._token}`; const resourceTokenConnectionString = `AccountEndpoint=${account.documentEndpoint};DatabaseId=${database.id};CollectionId=${container.id};${containerPermission._token}`;
try { try {
await page.goto(process.env.DATA_EXPLORER_ENDPOINT); await page.goto(process.env.DATA_EXPLORER_ENDPOINT);
await page.waitFor("div > p.switchConnectTypeText", { visible: true }); await page.waitFor("div > p.switchConnectTypeText", { visible: true });