diff --git a/test/cassandra/connectionStringLogin.spec.ts b/test/cassandra/connectionStringLogin.spec.ts index 228d067ec..030729e57 100644 --- a/test/cassandra/connectionStringLogin.spec.ts +++ b/test/cassandra/connectionStringLogin.spec.ts @@ -7,8 +7,8 @@ import { ONE_MINUTE_MS, TestAccount, generateUniqueName, - getAccountName, getAzureCLICredentials, + getConnectionStringAccountName, resourceGroupName, subscriptionId, } from "../fx"; @@ -44,7 +44,7 @@ test.describe("Cassandra account using connection string login", () => { test.beforeAll("Seed Test Keyspace", async () => { const credentials = getAzureCLICredentials(); armClient = new CosmosDBManagementClient(credentials, subscriptionId); - accountName = getAccountName(TestAccount.Cassandra); + accountName = getConnectionStringAccountName(TestAccount.Cassandra); const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings( resourceGroupName, diff --git a/test/fx.ts b/test/fx.ts index a128e2cee..8e53a8616 100644 --- a/test/fx.ts +++ b/test/fx.ts @@ -41,8 +41,10 @@ export async function getAzureCLICredentialsToken(): Promise { export enum TestAccount { Tables = "Tables", Cassandra = "Cassandra", + CassandraConnectionString = "CassandraConnectionString", Gremlin = "Gremlin", Mongo = "Mongo", + MongoConnectionString = "MongoConnectionString", MongoConnectionStringPublicNetworkAccessDisabled = "MongoConnectionStringPublicNetworkAccessDisabled", MongoReadonly = "MongoReadOnly", Mongo32 = "Mongo32", @@ -55,11 +57,6 @@ export enum TestAccount { GremlinConnectionString = "GremlinConnectionString", } -export enum TestAuthType { - EntraID = "EntraID", - ConnectionString = "ConnectionString", -} - export function getDefaultAccountName(accountType: TestAccount): string { const accountNamePrefix = process.env.DE_ACCOUNT_PREFIX; if (!accountNamePrefix) { @@ -71,10 +68,14 @@ export function getDefaultAccountName(accountType: TestAccount): string { return `${accountNamePrefix}-de-test-table-1`; case TestAccount.Cassandra: return `${accountNamePrefix}-de-test-cassandra-1`; + case TestAccount.CassandraConnectionString: + return `${accountNamePrefix}-de-test-cassandra-connstring-1`; case TestAccount.Gremlin: return `${accountNamePrefix}-de-test-gremlin-1`; case TestAccount.Mongo: return `${accountNamePrefix}-de-test-mongo-1`; + case TestAccount.MongoConnectionString: + return `${accountNamePrefix}-de-test-mongo-connstring-1`; case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled: return `${accountNamePrefix}-de-test-mongo-connstring-nopublic-1`; case TestAccount.MongoReadonly: @@ -123,32 +124,22 @@ function tryGetStandardName(accountType: TestAccount) { } } -// Maps a base API account type to its dedicated connection string (account key) account. -const connectionStringAccountTypes: Partial> = { +type ConnectionStringTestAccount = + | TestAccount.SQL + | TestAccount.Tables + | TestAccount.Cassandra + | TestAccount.Gremlin + | TestAccount.Mongo; + +const connectionStringAccountTypes: Record = { [TestAccount.SQL]: TestAccount.SQLConnectionString, [TestAccount.Tables]: TestAccount.TableConnectionString, + [TestAccount.Cassandra]: TestAccount.CassandraConnectionString, [TestAccount.Gremlin]: TestAccount.GremlinConnectionString, + [TestAccount.Mongo]: TestAccount.MongoConnectionString, }; -export function getAccountName(accountType: TestAccount, authType: TestAuthType = TestAuthType.EntraID): string { - // Connection string (account key) login uses dedicated *-connstring accounts that are only - // provisioned in CI (resolved via DE_ACCOUNT_PREFIX). Local runs use DE_TEST_ACCOUNT_PREFIX and - // typically don't have those accounts, so they fall back to the standard API account for the same - // API (which also has key auth enabled). - if (authType === TestAuthType.ConnectionString) { - const connectionStringType = connectionStringAccountTypes[accountType]; - if (!connectionStringType) { - throw new Error(`No connection string account defined for account type ${accountType}`); - } - const override = process.env[`DE_TEST_ACCOUNT_NAME_${connectionStringType.toLocaleUpperCase()}`]; - if (override) { - return override; - } - if (!process.env.DE_TEST_ACCOUNT_PREFIX) { - return getAccountName(connectionStringType); - } - } - +export function getAccountName(accountType: TestAccount): string { return ( process.env[`DE_TEST_ACCOUNT_NAME_${accountType.toLocaleUpperCase()}`] ?? tryGetStandardName(accountType) ?? @@ -156,6 +147,18 @@ export function getAccountName(accountType: TestAccount, authType: TestAuthType ); } +export function getConnectionStringAccountName(accountType: ConnectionStringTestAccount): string { + const connectionStringType = connectionStringAccountTypes[accountType]; + const override = process.env[`DE_TEST_ACCOUNT_NAME_${connectionStringType.toLocaleUpperCase()}`]; + if (override) { + return override; + } + + // Dedicated connection-string accounts are provisioned in CI. Local accounts normally support + // key authentication, so local runs use the standard account for the requested API. + return process.env.DE_TEST_ACCOUNT_PREFIX ? getAccountName(accountType) : getAccountName(connectionStringType); +} + type TestExplorerUrlOptions = { iframeSrc?: string; enablecontainercopy?: boolean; @@ -265,6 +268,8 @@ export async function getTestExplorerUrl(accountType: TestAccount, options?: Tes case TestAccount.SQLConnectionString: case TestAccount.SQLConnectionStringPublicNetworkAccessDisabled: + case TestAccount.CassandraConnectionString: + case TestAccount.MongoConnectionString: case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled: case TestAccount.TableConnectionString: case TestAccount.GremlinConnectionString: diff --git a/test/gremlin/connectionStringLogin.spec.ts b/test/gremlin/connectionStringLogin.spec.ts index 50289d867..c369c7b88 100644 --- a/test/gremlin/connectionStringLogin.spec.ts +++ b/test/gremlin/connectionStringLogin.spec.ts @@ -7,10 +7,9 @@ import { Editor, ONE_MINUTE_MS, TestAccount, - TestAuthType, generateUniqueName, - getAccountName, getAzureCLICredentials, + getConnectionStringAccountName, resourceGroupName, subscriptionId, } from "../fx"; @@ -25,7 +24,7 @@ test.describe("Gremlin account using connection string login", () => { test.beforeAll("Seed Test Database", async () => { const credentials = getAzureCLICredentials(); const armClient = new CosmosDBManagementClient(credentials, subscriptionId); - const accountName = getAccountName(TestAccount.Gremlin, TestAuthType.ConnectionString); + const accountName = getConnectionStringAccountName(TestAccount.Gremlin); const account = await armClient.databaseAccounts.get(resourceGroupName, accountName); const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName); @@ -46,7 +45,7 @@ test.describe("Gremlin account using connection string login", () => { test("reads a vertex after connection string login", async ({ page }) => { const credentials = getAzureCLICredentials(); const armClient = new CosmosDBManagementClient(credentials, subscriptionId); - const accountName = getAccountName(TestAccount.Gremlin, TestAuthType.ConnectionString); + const accountName = getConnectionStringAccountName(TestAccount.Gremlin); const account = await armClient.databaseAccounts.get(resourceGroupName, accountName); const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName); diff --git a/test/mongo/connectionStringLogin.spec.ts b/test/mongo/connectionStringLogin.spec.ts index 96ddfe1c2..fdbf98621 100644 --- a/test/mongo/connectionStringLogin.spec.ts +++ b/test/mongo/connectionStringLogin.spec.ts @@ -9,6 +9,7 @@ import { generateUniqueName, getAccountName, getAzureCLICredentials, + getConnectionStringAccountName, resourceGroupName, subscriptionId, } from "../fx"; @@ -44,7 +45,7 @@ test.describe("Mongo account using connection string login", () => { test.beforeAll("Seed Test Database", async () => { const credentials = getAzureCLICredentials(); armClient = new CosmosDBManagementClient(credentials, subscriptionId); - accountName = getAccountName(TestAccount.Mongo); + accountName = getConnectionStringAccountName(TestAccount.Mongo); const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings( resourceGroupName, diff --git a/test/sql/connectionStringLogin.spec.ts b/test/sql/connectionStringLogin.spec.ts index 88293bd64..46036c9dd 100644 --- a/test/sql/connectionStringLogin.spec.ts +++ b/test/sql/connectionStringLogin.spec.ts @@ -6,10 +6,9 @@ import { DataExplorer, ONE_MINUTE_MS, TestAccount, - TestAuthType, generateUniqueName, - getAccountName, getAzureCLICredentials, + getConnectionStringAccountName, resourceGroupName, subscriptionId, } from "../fx"; @@ -36,7 +35,7 @@ test.describe("SQL account using connection string login", () => { test.beforeAll("Seed Test Database", async () => { const credentials = getAzureCLICredentials(); const armClient = new CosmosDBManagementClient(credentials, subscriptionId); - const accountName = getAccountName(TestAccount.SQL, TestAuthType.ConnectionString); + const accountName = getConnectionStringAccountName(TestAccount.SQL); const account = await armClient.databaseAccounts.get(resourceGroupName, accountName); const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName); documentEndpoint = account.documentEndpoint!; diff --git a/test/tables/connectionStringLogin.spec.ts b/test/tables/connectionStringLogin.spec.ts index 02db382a2..d078894b6 100644 --- a/test/tables/connectionStringLogin.spec.ts +++ b/test/tables/connectionStringLogin.spec.ts @@ -6,10 +6,9 @@ import { DataExplorer, ONE_MINUTE_MS, TestAccount, - TestAuthType, generateUniqueName, - getAccountName, getAzureCLICredentials, + getConnectionStringAccountName, resourceGroupName, subscriptionId, } from "../fx"; @@ -26,7 +25,7 @@ test.describe("Tables account using connection string login", () => { test.beforeAll("Seed Test Table", async () => { const credentials = getAzureCLICredentials(); const armClient = new CosmosDBManagementClient(credentials, subscriptionId); - const accountName = getAccountName(TestAccount.Tables, TestAuthType.ConnectionString); + const accountName = getConnectionStringAccountName(TestAccount.Tables); const account = await armClient.databaseAccounts.get(resourceGroupName, accountName); const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName); @@ -50,7 +49,7 @@ test.describe("Tables account using connection string login", () => { test("reads an entity after connection string login", async ({ page }) => { const credentials = getAzureCLICredentials(); const armClient = new CosmosDBManagementClient(credentials, subscriptionId); - const accountName = getAccountName(TestAccount.Tables, TestAuthType.ConnectionString); + const accountName = getConnectionStringAccountName(TestAccount.Tables); const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings( resourceGroupName, accountName,