mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-19 17:12:47 +01:00
Mock container copy target permissions
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||||
import { ContainerCopy, getAccountName, TestAccount } from "../../fx";
|
import { ContainerCopy, getAccountName, resourceGroupName, subscriptionId, TestAccount } from "../../fx";
|
||||||
|
|
||||||
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
||||||
|
|
||||||
@@ -160,11 +160,11 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
await expect(pitrBtn).not.toBeVisible();
|
await expect(pitrBtn).not.toBeVisible();
|
||||||
await page.unroute(sourceAccountRoute);
|
await page.unroute(sourceAccountRoute);
|
||||||
|
|
||||||
// Setup additional API mocks for role assignments and permissions
|
// Setup additional API mocks for role assignments and permissions.
|
||||||
// In the redesigned flow, role assignments are checked on the SOURCE account (current account = sourceAccountName).
|
const targetAccountScope = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/${targetAccountName}`;
|
||||||
// The destination account (selectedAccountName) manages identity; source account holds the role assignments.
|
const targetRoleDefinitionId = `${targetAccountScope}/sqlRoleDefinitions/77-88-99`;
|
||||||
await page.route(
|
await page.route(
|
||||||
`**/Microsoft.DocumentDB/databaseAccounts/${sourceAccountName}/sqlRoleAssignments*`,
|
`**/Microsoft.DocumentDB/databaseAccounts/${targetAccountName}/sqlRoleAssignments*`,
|
||||||
async (route) => {
|
async (route) => {
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -172,8 +172,14 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
value: [
|
value: [
|
||||||
{
|
{
|
||||||
principalId: "00-11-22-33",
|
id: `${targetAccountScope}/sqlRoleAssignments/mock-role-assignment`,
|
||||||
roleDefinitionId: `Microsoft.DocumentDB/databaseAccounts/${sourceAccountName}/77-88-99`,
|
name: "mock-role-assignment",
|
||||||
|
type: "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments",
|
||||||
|
properties: {
|
||||||
|
principalId: "00-11-22-33",
|
||||||
|
roleDefinitionId: targetRoleDefinitionId,
|
||||||
|
scope: `${targetAccountScope}/`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@@ -181,20 +187,25 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.route("**/Microsoft.DocumentDB/databaseAccounts/*/77-88-99**", async (route) => {
|
await page.route(
|
||||||
await route.fulfill({
|
`**/Microsoft.DocumentDB/databaseAccounts/${targetAccountName}/sqlRoleDefinitions/77-88-99*`,
|
||||||
status: 200,
|
async (route) => {
|
||||||
contentType: "application/json",
|
await route.fulfill({
|
||||||
body: JSON.stringify({
|
status: 200,
|
||||||
value: [
|
contentType: "application/json",
|
||||||
{
|
body: JSON.stringify({
|
||||||
// Built-in Cosmos DB Data Contributor role (read-write), required by checkTargetHasReadWriteRoleOnSource
|
id: targetRoleDefinitionId,
|
||||||
name: "00000000-0000-0000-0000-000000000002",
|
name: "00000000-0000-0000-0000-000000000002",
|
||||||
},
|
type: "Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions",
|
||||||
],
|
assignableScopes: [targetAccountScope],
|
||||||
}),
|
permissions: [],
|
||||||
});
|
resourceGroup: resourceGroupName,
|
||||||
});
|
roleName: "Cosmos DB Built-in Data Contributor",
|
||||||
|
typePropertiesType: "BuiltInRole",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Return the completed identity state only for the managed-identity action.
|
// Return the completed identity state only for the managed-identity action.
|
||||||
await page.route(sourceAccountRoute, async (route) => {
|
await page.route(sourceAccountRoute, async (route) => {
|
||||||
@@ -272,13 +283,25 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
response.url().includes(`/databaseAccounts/${sourceAccountName}`) &&
|
response.url().includes(`/databaseAccounts/${sourceAccountName}`) &&
|
||||||
response.url().includes("api-version=2025-05-01-preview"),
|
response.url().includes("api-version=2025-05-01-preview"),
|
||||||
);
|
);
|
||||||
|
const roleAssignmentsPromise = page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.request().method() === "GET" &&
|
||||||
|
response.url().includes(`/databaseAccounts/${targetAccountName}/sqlRoleAssignments`) &&
|
||||||
|
response.url().includes("api-version=2025-04-15"),
|
||||||
|
);
|
||||||
|
const roleDefinitionPromise = page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.request().method() === "GET" &&
|
||||||
|
response.url().includes(`/databaseAccounts/${targetAccountName}/sqlRoleDefinitions/77-88-99`) &&
|
||||||
|
response.url().includes("api-version=2025-04-15"),
|
||||||
|
);
|
||||||
await yesButton.click({ force: true });
|
await yesButton.click({ force: true });
|
||||||
const [identityUpdateResponse, accountRefreshResponse] = await Promise.all([
|
const [identityUpdateResponse, accountRefreshResponse, roleAssignmentsResponse, roleDefinitionResponse] =
|
||||||
identityUpdatePromise,
|
await Promise.all([identityUpdatePromise, accountRefreshPromise, roleAssignmentsPromise, roleDefinitionPromise]);
|
||||||
accountRefreshPromise,
|
|
||||||
]);
|
|
||||||
expect(identityUpdateResponse.ok()).toBe(true);
|
expect(identityUpdateResponse.ok()).toBe(true);
|
||||||
expect(accountRefreshResponse.ok()).toBe(true);
|
expect(accountRefreshResponse.ok()).toBe(true);
|
||||||
|
expect(roleAssignmentsResponse.ok()).toBe(true);
|
||||||
|
expect(roleDefinitionResponse.ok()).toBe(true);
|
||||||
|
|
||||||
// Verify the refreshed account state completes the permission section.
|
// Verify the refreshed account state completes the permission section.
|
||||||
await expect(popover).toBeHidden({ timeout: VISIBLE_TIMEOUT_MS });
|
await expect(popover).toBeHidden({ timeout: VISIBLE_TIMEOUT_MS });
|
||||||
|
|||||||
Reference in New Issue
Block a user