Remove creation of default policy, resource and permission upon enabling authorization for a client

Closes #43867

Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
vramik
2025-11-05 13:32:54 +01:00
committed by Pedro Igor
parent 5c04124d86
commit 748b58bf64
12 changed files with 148 additions and 159 deletions

View File

@@ -14,7 +14,6 @@ import {
} from "../utils/table.ts";
import {
assertClipboardHasText,
assertDefaultResource,
assertDownload,
clickAuthenticationSaveButton,
clickCopyButton,
@@ -69,9 +68,8 @@ test.describe.serial("Client authentication subtab", () => {
test("Should create a resource", async ({ page }) => {
await goToResourcesSubTab(page);
await assertDefaultResource(page);
await createResource(page, {
name: "Resource",
name: "Test Resource",
displayName: "The display name",
type: "type",
uris: ["one", "two"],
@@ -83,7 +81,7 @@ test.describe.serial("Client authentication subtab", () => {
test("Edit a resource", async ({ page }) => {
await goToResourcesSubTab(page);
await clickTableRowItem(page, "Default Resource");
await clickTableRowItem(page, "Test Resource");
await fillForm(page, { displayName: "updated" });
await clickSaveButton(page);
@@ -115,7 +113,7 @@ test.describe.serial("Client authentication subtab", () => {
name: "Permission name",
description: "Something describing this permission",
});
await selectResource(page, "Default Resource");
await selectResource(page, "Test Resource");
await clickSaveButton(page);
await assertNotificationMessage(
@@ -139,7 +137,7 @@ test.describe.serial("Client authentication subtab", () => {
test("Should delete a policy", async ({ page }) => {
await goToPoliciesSubTab(page);
await deletePolicy(page, "Default Policy");
await deletePolicy(page, "Regex Policy");
await assertNotificationMessage(page, "The Policy successfully deleted");
});
@@ -175,6 +173,7 @@ test.describe.serial("Client authentication subtab", () => {
test.describe
.serial("Client authorization tab access for view-realm-authorization", () => {
const clientId = `realm-view-authz-client-${crypto.randomUUID()}`;
const resourceName = `test-resource-${crypto.randomUUID()}`;
test.beforeAll(async () => {
await adminClient.createRealm("realm-view-authz");
@@ -197,6 +196,10 @@ test.describe
serviceAccountsEnabled: true,
standardFlowEnabled: true,
});
await adminClient.createResource(clientId, {
realm: "realm-view-authz",
name: resourceName,
});
});
test.afterAll(async () => {
@@ -219,7 +222,7 @@ test.describe
await goToAuthorizationTab(page);
await goToResourcesSubTab(page);
await clickTableRowItem(page, "Default Resource");
await clickTableRowItem(page, resourceName);
await page.goBack();
await goToScopesSubTab(page);

View File

@@ -21,12 +21,6 @@ export async function clickAuthenticationSaveButton(page: Page) {
await page.getByTestId("authenticationSettings-save").click();
}
export async function assertDefaultResource(page: Page) {
await expect(page.getByTestId("name-column-Default Resource")).toHaveText(
"Default Resource",
);
}
export async function assertResource(page: Page, name: string) {
await expect(getRowByCellText(page, name)).toBeVisible();
}
@@ -35,7 +29,11 @@ export async function createResource(
page: Page,
resource: ResourceRepresentation,
) {
await page.getByTestId("createResource").click();
await page
.locator(
'[data-testid="createResource"], [data-testid="no-resources-empty-action"]',
)
.click();
await fillForm(page, resource);
}
@@ -81,7 +79,11 @@ export async function createPolicy(
type: string,
policy: { [key: string]: string },
) {
await page.getByTestId("createPolicy").click();
await page
.locator(
'[data-testid="createPolicy"], [data-testid="no-policies-empty-action"]',
)
.click();
await page.getByRole("gridcell", { name: type, exact: true }).click();
await fillForm(page, policy);
}
@@ -106,7 +108,13 @@ export async function createPermission(
type: string,
permission: PolicyRepresentation,
) {
await page.getByTestId("permissionCreateDropdown").click();
const dropdown = page.getByTestId("permissionCreateDropdown");
const hasDropdown = (await dropdown.count()) > 0;
if (hasDropdown) {
await dropdown.click();
}
await page.getByTestId(`create-${type}`).click();
await fillForm(page, permission);
}

View File

@@ -4,6 +4,7 @@ import type ClientScopeRepresentation from "@keycloak/keycloak-admin-client/lib/
import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation.js";
import type OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation.js";
import type PolicyRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyRepresentation.js";
import type ResourceRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceRepresentation.js";
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation.js";
import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation.js";
import type { RoleMappingPayload } from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation.js";
@@ -495,6 +496,25 @@ class AdminClient {
);
}
async createResource(
clientId: string,
resource: ResourceRepresentation & { realm?: string },
) {
await this.#login();
const { realm = this.#client.realmName, ...payload } = resource;
const client = (await this.#client.clients.find({ clientId, realm }))[0];
if (!client?.id) {
throw new Error(`Client ${clientId} not found in realm ${realm}`);
}
return await this.#client.clients.createResource(
{ id: client.id, realm },
payload,
);
}
async findUserByUsername(
realm: string,
username: string,