mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-26 13:04:43 +01:00
Stabilize container copy permissions E2E test (#2597)
* Stabilize container copy permissions E2E test * Scope container copy account mocks by phase * Mock container copy target permissions
This commit is contained in:
@@ -1,7 +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 { set } from "lodash";
|
import { ContainerCopy, getAccountName, resourceGroupName, subscriptionId, TestAccount } from "../../fx";
|
||||||
import { ContainerCopy, getAccountName, TestAccount } from "../../fx";
|
|
||||||
|
|
||||||
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
||||||
|
|
||||||
@@ -103,35 +102,15 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
await expect(permissionScreen.getByText("Online container copy", { exact: true })).toBeVisible();
|
await expect(permissionScreen.getByText("Online container copy", { exact: true })).toBeVisible();
|
||||||
await expect(permissionScreen.getByText("Cross-account container copy", { exact: true })).toBeVisible();
|
await expect(permissionScreen.getByText("Cross-account container copy", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
// Setup API mocking for the source account
|
const sourceAccountRoute = `**/Microsoft.DocumentDB/databaseAccounts/${sourceAccountName}**`;
|
||||||
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${sourceAccountName}**`, async (route) => {
|
|
||||||
const mockData = {
|
|
||||||
identity: {
|
|
||||||
type: "SystemAssigned",
|
|
||||||
principalId: "00-11-22-33",
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
defaultIdentity: "SystemAssignedIdentity",
|
|
||||||
backupPolicy: {
|
|
||||||
type: "Continuous",
|
|
||||||
},
|
|
||||||
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (route.request().method() === "GET") {
|
|
||||||
const response = await route.fetch();
|
|
||||||
const actualData = await response.json();
|
|
||||||
const mergedData = { ...actualData };
|
|
||||||
|
|
||||||
set(mergedData, "identity", mockData.identity);
|
|
||||||
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
|
||||||
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
|
||||||
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
|
||||||
|
|
||||||
|
// Keep PITR polling deterministic without changing the source account state.
|
||||||
|
await page.route(sourceAccountRoute, async (route) => {
|
||||||
|
if (route.request().method() === "GET" && route.request().url().includes("api-version=2025-05-01-preview")) {
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
body: JSON.stringify(mergedData),
|
body: JSON.stringify({ properties: { backupPolicy: { type: "Periodic" } } }),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await route.continue();
|
await route.continue();
|
||||||
@@ -157,16 +136,16 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
|
|
||||||
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
||||||
await expect(pitrBtn).toBeVisible();
|
await expect(pitrBtn).toBeVisible();
|
||||||
await pitrBtn.click({ force: true });
|
|
||||||
|
|
||||||
// Verify new page opens with correct URL pattern
|
// Verify new page opens with correct URL pattern
|
||||||
page.context().on("page", async (newPage) => {
|
const newPagePromise = page.context().waitForEvent("page");
|
||||||
const expectedUrlEndPattern = new RegExp(
|
await pitrBtn.click({ force: true });
|
||||||
`/providers/Microsoft.(DocumentDB|DocumentDb)/databaseAccounts/${sourceAccountName}/backupRestore`,
|
const newPage = await newPagePromise;
|
||||||
);
|
const expectedUrlEndPattern = new RegExp(
|
||||||
expect(newPage.url()).toMatch(expectedUrlEndPattern);
|
`/providers/Microsoft.(DocumentDB|DocumentDb)/databaseAccounts/${sourceAccountName}/backupRestore`,
|
||||||
await newPage.close();
|
);
|
||||||
});
|
await expect(newPage).toHaveURL(expectedUrlEndPattern);
|
||||||
|
await newPage.close();
|
||||||
|
|
||||||
const loadingOverlay = frame.locator("[data-test='loading-overlay']");
|
const loadingOverlay = frame.locator("[data-test='loading-overlay']");
|
||||||
await expect(loadingOverlay).toBeVisible();
|
await expect(loadingOverlay).toBeVisible();
|
||||||
@@ -179,12 +158,13 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
|
|
||||||
await expect(refreshBtn).toBeVisible({ timeout: 5000 });
|
await expect(refreshBtn).toBeVisible({ timeout: 5000 });
|
||||||
await expect(pitrBtn).not.toBeVisible();
|
await expect(pitrBtn).not.toBeVisible();
|
||||||
|
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,
|
||||||
@@ -192,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}/`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@@ -201,23 +187,34 @@ 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",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${sourceAccountName}**`, async (route) => {
|
// Return the completed identity state only for the managed-identity action.
|
||||||
|
await page.route(sourceAccountRoute, async (route) => {
|
||||||
const mockData = {
|
const mockData = {
|
||||||
|
id: new URL(route.request().url()).pathname,
|
||||||
|
name: sourceAccountName,
|
||||||
|
location: "East US",
|
||||||
|
type: "Microsoft.DocumentDB/databaseAccounts",
|
||||||
|
kind: "GlobalDocumentDB",
|
||||||
identity: {
|
identity: {
|
||||||
type: "SystemAssigned",
|
type: "SystemAssigned",
|
||||||
principalId: "00-11-22-33",
|
principalId: "00-11-22-33",
|
||||||
@@ -230,7 +227,6 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (route.request().method() === "PATCH") {
|
if (route.request().method() === "PATCH") {
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -238,18 +234,10 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
body: JSON.stringify({ status: "Succeeded" }),
|
body: JSON.stringify({ status: "Succeeded" }),
|
||||||
});
|
});
|
||||||
} else if (route.request().method() === "GET") {
|
} else if (route.request().method() === "GET") {
|
||||||
const response = await route.fetch();
|
|
||||||
const actualData = await response.json();
|
|
||||||
const mergedData = { ...actualData };
|
|
||||||
set(mergedData, "identity", mockData.identity);
|
|
||||||
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
|
||||||
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
|
||||||
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
|
||||||
|
|
||||||
await route.fulfill({
|
await route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
body: JSON.stringify(mergedData),
|
body: JSON.stringify(mockData),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await route.continue();
|
await route.continue();
|
||||||
@@ -283,12 +271,40 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
await expect(yesButton).toBeVisible();
|
await expect(yesButton).toBeVisible();
|
||||||
await expect(noButton).toBeVisible();
|
await expect(noButton).toBeVisible();
|
||||||
|
|
||||||
|
const identityUpdatePromise = page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.request().method() === "PATCH" &&
|
||||||
|
response.url().includes(`/databaseAccounts/${sourceAccountName}`) &&
|
||||||
|
response.url().includes("api-version=2025-04-15"),
|
||||||
|
);
|
||||||
|
const accountRefreshPromise = page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.request().method() === "GET" &&
|
||||||
|
response.url().includes(`/databaseAccounts/${sourceAccountName}`) &&
|
||||||
|
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, roleAssignmentsResponse, roleDefinitionResponse] =
|
||||||
|
await Promise.all([identityUpdatePromise, accountRefreshPromise, roleAssignmentsPromise, roleDefinitionPromise]);
|
||||||
|
expect(identityUpdateResponse.ok()).toBe(true);
|
||||||
|
expect(accountRefreshResponse.ok()).toBe(true);
|
||||||
|
expect(roleAssignmentsResponse.ok()).toBe(true);
|
||||||
|
expect(roleDefinitionResponse.ok()).toBe(true);
|
||||||
|
|
||||||
// Verify loading states
|
// Verify the refreshed account state completes the permission section.
|
||||||
await expect(loadingOverlay).toBeVisible();
|
await expect(popover).toBeHidden({ timeout: VISIBLE_TIMEOUT_MS });
|
||||||
await expect(loadingOverlay).toBeHidden({ timeout: 10 * 1000 });
|
|
||||||
await expect(popover).toBeHidden({ timeout: 10 * 1000 });
|
|
||||||
|
|
||||||
// Cancel the panel to clean up
|
// Cancel the panel to clean up
|
||||||
await panel.getByRole("button", { name: "Cancel" }).click({ force: true });
|
await panel.getByRole("button", { name: "Cancel" }).click({ force: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user