mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-19 09:02:41 +01:00
Use dedicated accounts for connection string tests
This commit is contained in:
@@ -7,8 +7,8 @@ import {
|
|||||||
ONE_MINUTE_MS,
|
ONE_MINUTE_MS,
|
||||||
TestAccount,
|
TestAccount,
|
||||||
generateUniqueName,
|
generateUniqueName,
|
||||||
getAccountName,
|
|
||||||
getAzureCLICredentials,
|
getAzureCLICredentials,
|
||||||
|
getConnectionStringAccountName,
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
} from "../fx";
|
} from "../fx";
|
||||||
@@ -44,7 +44,7 @@ test.describe("Cassandra account using connection string login", () => {
|
|||||||
test.beforeAll("Seed Test Keyspace", async () => {
|
test.beforeAll("Seed Test Keyspace", async () => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
||||||
accountName = getAccountName(TestAccount.Cassandra);
|
accountName = getConnectionStringAccountName(TestAccount.Cassandra);
|
||||||
|
|
||||||
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
|
|||||||
+31
-26
@@ -41,8 +41,10 @@ export async function getAzureCLICredentialsToken(): Promise<string> {
|
|||||||
export enum TestAccount {
|
export enum TestAccount {
|
||||||
Tables = "Tables",
|
Tables = "Tables",
|
||||||
Cassandra = "Cassandra",
|
Cassandra = "Cassandra",
|
||||||
|
CassandraConnectionString = "CassandraConnectionString",
|
||||||
Gremlin = "Gremlin",
|
Gremlin = "Gremlin",
|
||||||
Mongo = "Mongo",
|
Mongo = "Mongo",
|
||||||
|
MongoConnectionString = "MongoConnectionString",
|
||||||
MongoConnectionStringPublicNetworkAccessDisabled = "MongoConnectionStringPublicNetworkAccessDisabled",
|
MongoConnectionStringPublicNetworkAccessDisabled = "MongoConnectionStringPublicNetworkAccessDisabled",
|
||||||
MongoReadonly = "MongoReadOnly",
|
MongoReadonly = "MongoReadOnly",
|
||||||
Mongo32 = "Mongo32",
|
Mongo32 = "Mongo32",
|
||||||
@@ -55,11 +57,6 @@ export enum TestAccount {
|
|||||||
GremlinConnectionString = "GremlinConnectionString",
|
GremlinConnectionString = "GremlinConnectionString",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TestAuthType {
|
|
||||||
EntraID = "EntraID",
|
|
||||||
ConnectionString = "ConnectionString",
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDefaultAccountName(accountType: TestAccount): string {
|
export function getDefaultAccountName(accountType: TestAccount): string {
|
||||||
const accountNamePrefix = process.env.DE_ACCOUNT_PREFIX;
|
const accountNamePrefix = process.env.DE_ACCOUNT_PREFIX;
|
||||||
if (!accountNamePrefix) {
|
if (!accountNamePrefix) {
|
||||||
@@ -71,10 +68,14 @@ export function getDefaultAccountName(accountType: TestAccount): string {
|
|||||||
return `${accountNamePrefix}-de-test-table-1`;
|
return `${accountNamePrefix}-de-test-table-1`;
|
||||||
case TestAccount.Cassandra:
|
case TestAccount.Cassandra:
|
||||||
return `${accountNamePrefix}-de-test-cassandra-1`;
|
return `${accountNamePrefix}-de-test-cassandra-1`;
|
||||||
|
case TestAccount.CassandraConnectionString:
|
||||||
|
return `${accountNamePrefix}-de-test-cassandra-connstring-1`;
|
||||||
case TestAccount.Gremlin:
|
case TestAccount.Gremlin:
|
||||||
return `${accountNamePrefix}-de-test-gremlin-1`;
|
return `${accountNamePrefix}-de-test-gremlin-1`;
|
||||||
case TestAccount.Mongo:
|
case TestAccount.Mongo:
|
||||||
return `${accountNamePrefix}-de-test-mongo-1`;
|
return `${accountNamePrefix}-de-test-mongo-1`;
|
||||||
|
case TestAccount.MongoConnectionString:
|
||||||
|
return `${accountNamePrefix}-de-test-mongo-connstring-1`;
|
||||||
case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled:
|
case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled:
|
||||||
return `${accountNamePrefix}-de-test-mongo-connstring-nopublic-1`;
|
return `${accountNamePrefix}-de-test-mongo-connstring-nopublic-1`;
|
||||||
case TestAccount.MongoReadonly:
|
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.
|
type ConnectionStringTestAccount =
|
||||||
const connectionStringAccountTypes: Partial<Record<TestAccount, TestAccount>> = {
|
| TestAccount.SQL
|
||||||
|
| TestAccount.Tables
|
||||||
|
| TestAccount.Cassandra
|
||||||
|
| TestAccount.Gremlin
|
||||||
|
| TestAccount.Mongo;
|
||||||
|
|
||||||
|
const connectionStringAccountTypes: Record<ConnectionStringTestAccount, TestAccount> = {
|
||||||
[TestAccount.SQL]: TestAccount.SQLConnectionString,
|
[TestAccount.SQL]: TestAccount.SQLConnectionString,
|
||||||
[TestAccount.Tables]: TestAccount.TableConnectionString,
|
[TestAccount.Tables]: TestAccount.TableConnectionString,
|
||||||
|
[TestAccount.Cassandra]: TestAccount.CassandraConnectionString,
|
||||||
[TestAccount.Gremlin]: TestAccount.GremlinConnectionString,
|
[TestAccount.Gremlin]: TestAccount.GremlinConnectionString,
|
||||||
|
[TestAccount.Mongo]: TestAccount.MongoConnectionString,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getAccountName(accountType: TestAccount, authType: TestAuthType = TestAuthType.EntraID): string {
|
export function getAccountName(accountType: TestAccount): 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
process.env[`DE_TEST_ACCOUNT_NAME_${accountType.toLocaleUpperCase()}`] ??
|
process.env[`DE_TEST_ACCOUNT_NAME_${accountType.toLocaleUpperCase()}`] ??
|
||||||
tryGetStandardName(accountType) ??
|
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 = {
|
type TestExplorerUrlOptions = {
|
||||||
iframeSrc?: string;
|
iframeSrc?: string;
|
||||||
enablecontainercopy?: boolean;
|
enablecontainercopy?: boolean;
|
||||||
@@ -265,6 +268,8 @@ export async function getTestExplorerUrl(accountType: TestAccount, options?: Tes
|
|||||||
|
|
||||||
case TestAccount.SQLConnectionString:
|
case TestAccount.SQLConnectionString:
|
||||||
case TestAccount.SQLConnectionStringPublicNetworkAccessDisabled:
|
case TestAccount.SQLConnectionStringPublicNetworkAccessDisabled:
|
||||||
|
case TestAccount.CassandraConnectionString:
|
||||||
|
case TestAccount.MongoConnectionString:
|
||||||
case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled:
|
case TestAccount.MongoConnectionStringPublicNetworkAccessDisabled:
|
||||||
case TestAccount.TableConnectionString:
|
case TestAccount.TableConnectionString:
|
||||||
case TestAccount.GremlinConnectionString:
|
case TestAccount.GremlinConnectionString:
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ import {
|
|||||||
Editor,
|
Editor,
|
||||||
ONE_MINUTE_MS,
|
ONE_MINUTE_MS,
|
||||||
TestAccount,
|
TestAccount,
|
||||||
TestAuthType,
|
|
||||||
generateUniqueName,
|
generateUniqueName,
|
||||||
getAccountName,
|
|
||||||
getAzureCLICredentials,
|
getAzureCLICredentials,
|
||||||
|
getConnectionStringAccountName,
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
} from "../fx";
|
} from "../fx";
|
||||||
@@ -25,7 +24,7 @@ test.describe("Gremlin account using connection string login", () => {
|
|||||||
test.beforeAll("Seed Test Database", async () => {
|
test.beforeAll("Seed Test Database", async () => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
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 account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
const keys = await armClient.databaseAccounts.listKeys(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 }) => {
|
test("reads a vertex after connection string login", async ({ page }) => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
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 account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
generateUniqueName,
|
generateUniqueName,
|
||||||
getAccountName,
|
getAccountName,
|
||||||
getAzureCLICredentials,
|
getAzureCLICredentials,
|
||||||
|
getConnectionStringAccountName,
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
} from "../fx";
|
} from "../fx";
|
||||||
@@ -44,7 +45,7 @@ test.describe("Mongo account using connection string login", () => {
|
|||||||
test.beforeAll("Seed Test Database", async () => {
|
test.beforeAll("Seed Test Database", async () => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
||||||
accountName = getAccountName(TestAccount.Mongo);
|
accountName = getConnectionStringAccountName(TestAccount.Mongo);
|
||||||
|
|
||||||
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import {
|
|||||||
DataExplorer,
|
DataExplorer,
|
||||||
ONE_MINUTE_MS,
|
ONE_MINUTE_MS,
|
||||||
TestAccount,
|
TestAccount,
|
||||||
TestAuthType,
|
|
||||||
generateUniqueName,
|
generateUniqueName,
|
||||||
getAccountName,
|
|
||||||
getAzureCLICredentials,
|
getAzureCLICredentials,
|
||||||
|
getConnectionStringAccountName,
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
} from "../fx";
|
} from "../fx";
|
||||||
@@ -36,7 +35,7 @@ test.describe("SQL account using connection string login", () => {
|
|||||||
test.beforeAll("Seed Test Database", async () => {
|
test.beforeAll("Seed Test Database", async () => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
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 account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
||||||
documentEndpoint = account.documentEndpoint!;
|
documentEndpoint = account.documentEndpoint!;
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import {
|
|||||||
DataExplorer,
|
DataExplorer,
|
||||||
ONE_MINUTE_MS,
|
ONE_MINUTE_MS,
|
||||||
TestAccount,
|
TestAccount,
|
||||||
TestAuthType,
|
|
||||||
generateUniqueName,
|
generateUniqueName,
|
||||||
getAccountName,
|
|
||||||
getAzureCLICredentials,
|
getAzureCLICredentials,
|
||||||
|
getConnectionStringAccountName,
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
} from "../fx";
|
} from "../fx";
|
||||||
@@ -26,7 +25,7 @@ test.describe("Tables account using connection string login", () => {
|
|||||||
test.beforeAll("Seed Test Table", async () => {
|
test.beforeAll("Seed Test Table", async () => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
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 account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
const keys = await armClient.databaseAccounts.listKeys(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 }) => {
|
test("reads an entity after connection string login", async ({ page }) => {
|
||||||
const credentials = getAzureCLICredentials();
|
const credentials = getAzureCLICredentials();
|
||||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
||||||
const accountName = getAccountName(TestAccount.Tables, TestAuthType.ConnectionString);
|
const accountName = getConnectionStringAccountName(TestAccount.Tables);
|
||||||
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
const { connectionStrings = [] } = await armClient.databaseAccounts.listConnectionStrings(
|
||||||
resourceGroupName,
|
resourceGroupName,
|
||||||
accountName,
|
accountName,
|
||||||
|
|||||||
Reference in New Issue
Block a user