Skip to content

Commit

Permalink
Use crypto.randomUUID() instead of uuid module (keycloak#35678)
Browse files Browse the repository at this point in the history
Closes keycloak#35714

Signed-off-by: Niklas Mollenhauer <[email protected]>
  • Loading branch information
nikeee authored Dec 9, 2024
1 parent 745a6fe commit 8f2c3a7
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
import IdentityProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderRepresentation";
import { Page, expect, test } from "@playwright/test";
import { randomUUID } from "node:crypto";

import {
createClient,
Expand All @@ -23,7 +22,7 @@ test.describe("Account linking", () => {
// Tests for keycloak account console, section Account linking in Account security
test.beforeAll(async () => {
user = await createRandomUserWithPassword(
"user-" + randomUUID(),
"user-" + crypto.randomUUID(),
"pwd",
realm,
);
Expand Down
7 changes: 3 additions & 4 deletions js/apps/account-ui/test/personal-info/personal-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import {
} from "../admin-client";
import { login } from "../login";
import userProfileConfig from "./user-profile.json" assert { type: "json" };
import { randomUUID } from "crypto";

const realm = "user-profile";

test.describe("Personal info page", () => {
const user = "user-" + randomUUID();
const user = "user-" + crypto.randomUUID();

test.beforeAll(() => createRandomUserWithPassword(user, "pwd", realm));
test.afterAll(async () => deleteUser(user, realm));
Expand All @@ -36,7 +35,7 @@ test.describe("Personal info with userprofile enabled", () => {
test.beforeAll(async () => {
await importUserProfile(userProfileConfig as UserProfileConfig, realm);
user = await createRandomUserWithPassword(
"user-" + randomUUID(),
"user-" + crypto.randomUUID(),
"jdoe",
realm,
{
Expand Down Expand Up @@ -121,7 +120,7 @@ test.describe("Realm localization", () => {
test.beforeAll(() => enableLocalization());
test("change locale", async ({ page }) => {
const user = await createRandomUserWithPassword(
"user-" + randomUUID(),
"user-" + crypto.randomUUID(),
"pwd",
realm,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import Form from "../support/forms/Form";
import FormValidation from "../support/forms/FormValidation";
import Select from "../support/forms/Select";
Expand All @@ -12,7 +11,7 @@ const loginPage = new LoginPage();
const sidebarPage = new SidebarPage();

describe("Authentication - Policies - CIBA", () => {
const realmName = uuid();
const realmName = crypto.randomUUID();

before(() => adminClient.createRealm(realmName));

Expand Down
3 changes: 1 addition & 2 deletions js/apps/admin-ui/cypress/e2e/authentication_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
Expand All @@ -22,7 +21,7 @@ const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const commonPage = new CommonPage();
const listingPage = new ListingPage();
const realmName = "test" + uuid();
const realmName = "test" + crypto.randomUUID();

describe("Authentication test", () => {
const detailPage = new FlowDetails();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
import LoginPage from "../support/pages/LoginPage";
Expand All @@ -21,7 +20,7 @@ describe("Client authentication subtab", () => {
const clientDetailsPage = new ClientDetailsPage();
const policiesSubTab = new PoliciesTab();
const permissionsSubTab = new PermissionsTab();
const clientId = "client-authentication-" + uuid();
const clientId = "client-authentication-" + crypto.randomUUID();

before(() =>
adminClient.createClient({
Expand Down Expand Up @@ -196,7 +195,7 @@ describe("Client authentication subtab", () => {
});

describe("Client authorization tab access for view-realm-authorization", () => {
const clientId = "realm-view-authz-client-" + uuid();
const clientId = "realm-view-authz-client-" + crypto.randomUUID();

beforeEach(async () => {
const [, testUser] = await Promise.all([
Expand Down
5 changes: 2 additions & 3 deletions js/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import LoginPage from "../support/pages/LoginPage";
import Masthead from "../support/pages/admin-ui/Masthead";
import ListingPage, {
Expand Down Expand Up @@ -302,7 +301,7 @@ describe("Client Scopes test", () => {
});

it("Client scope CRUD test", () => {
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();

// Create
listingPage.itemExist(itemId, false).goToCreateItem();
Expand Down Expand Up @@ -430,7 +429,7 @@ describe("Client Scopes test", () => {
cy.injectAxe();
});

const scopeName = "a11y_" + uuid();
const scopeName = "a11y_" + crypto.randomUUID();

after(async () => {
await adminClient.deleteClientScope(scopeName);
Expand Down
13 changes: 6 additions & 7 deletions js/apps/admin-ui/cypress/e2e/clients_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import LoginPage from "../support/pages/LoginPage";
import ListingPage, {
Filter,
Expand Down Expand Up @@ -34,7 +33,7 @@ const dedicatedScopesMappersTab = new DedicatedScopesMappersTab();
const realmSettings = new RealmSettingsPage();

describe("Clients test", () => {
const realmName = `clients-realm-${uuid()}`;
const realmName = `clients-realm-${crypto.randomUUID()}`;

before(() => adminClient.createRealm(realmName));

Expand Down Expand Up @@ -428,7 +427,7 @@ describe("Clients test", () => {
});

it("Client CRUD test", () => {
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();

// Create
commonPage.tableUtils().checkRowItemExists(itemId, false);
Expand Down Expand Up @@ -602,8 +601,8 @@ describe("Clients test", () => {

describe("Roles tab test", () => {
const rolesTab = new ClientRolesTab();
const client = "client_" + uuid();
const createRealmRoleName = `create-realm-${uuid()}`;
const client = "client_" + crypto.randomUUID();
const createRealmRoleName = `create-realm-${crypto.randomUUID()}`;

before(async () => {
await adminClient.inRealm(realmName, () =>
Expand Down Expand Up @@ -825,7 +824,7 @@ describe("Clients test", () => {
keycloakBefore();
commonPage.sidebar().goToRealm(realmName);
commonPage.sidebar().goToClients();
client = "client_" + uuid();
client = "client_" + crypto.randomUUID();
commonPage.tableToolbarUtils().createClient();
createClientPage
.selectClientType("OpenID Connect")
Expand Down Expand Up @@ -959,7 +958,7 @@ describe("Clients test", () => {
describe("Service account tab test", () => {
const serviceAccountTab = new RoleMappingTab("user");
const serviceAccountName = "service-account-client";
const createRealmRoleName = `create-realm-${uuid()}`;
const createRealmRoleName = `create-realm-${crypto.randomUUID()}`;
const createRealmRoleType = `roles`;

before(async () => {
Expand Down
5 changes: 2 additions & 3 deletions js/apps/admin-ui/cypress/e2e/events_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import UserEventsTab, {
Expand Down Expand Up @@ -34,7 +33,7 @@ describe.skip("Events tests", () => {
const eventsTestUser = {
eventsTestUserId: "",
userRepresentation: {
username: "events-test" + uuid(),
username: "events-test" + crypto.randomUUID(),
enabled: true,
credentials: [{ value: "events-test" }],
},
Expand Down Expand Up @@ -269,7 +268,7 @@ describe.skip("Events tests", () => {
});

describe("Admin events list", () => {
const realmName = uuid();
const realmName = crypto.randomUUID();

before(() => adminClient.createRealm(realmName));

Expand Down
3 changes: 1 addition & 2 deletions js/apps/admin-ui/cypress/e2e/group_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import GroupModal from "../support/pages/admin-ui/manage/groups/GroupModal";
import GroupDetailPage from "../support/pages/admin-ui/manage/groups/group_details/GroupDetailPage";
import AttributesTab from "../support/pages/admin-ui/manage/AttributesTab";
Expand Down Expand Up @@ -67,7 +66,7 @@ describe("Group test", () => {
loginPage.logIn();
keycloakBefore();
sidebarPage.goToGroups();
groupName = groupNamePrefix + uuid();
groupName = groupNamePrefix + crypto.randomUUID();
groupNames.push(groupName);
});

Expand Down
5 changes: 2 additions & 3 deletions js/apps/admin-ui/cypress/e2e/masthead_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import Masthead from "../support/pages/admin-ui/Masthead";
Expand Down Expand Up @@ -67,8 +66,8 @@ describe("Masthead tests", () => {
});

describe("Login works for unprivileged users", () => {
const realmName = `test-realm-${uuid()}`;
const username = `test-user-${uuid()}`;
const realmName = `test-realm-${crypto.randomUUID()}`;
const username = `test-user-${crypto.randomUUID()}`;

before(async () => {
await adminClient.createRealm(realmName, { enabled: true });
Expand Down
9 changes: 4 additions & 5 deletions js/apps/admin-ui/cypress/e2e/realm_roles_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import LoginPage from "../support/pages/LoginPage";
import Masthead from "../support/pages/admin-ui/Masthead";
import ModalUtils from "../support/util/ModalUtils";
Expand Down Expand Up @@ -47,7 +46,7 @@ describe("Realm roles test", () => {
});

it("Realm role CRUD test", () => {
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();

// Create
listingPage.itemExist(itemId, false).goToCreateItem();
Expand All @@ -70,7 +69,7 @@ describe("Realm roles test", () => {
});

it("should delete role from details action", () => {
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();
listingPage.goToCreateItem();
createRealmRolePage.fillRealmRoleData(itemId).save();
masthead.checkNotificationMessage("Role created", true);
Expand All @@ -90,7 +89,7 @@ describe("Realm roles test", () => {
});

it("Add associated roles test", () => {
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();

// Create
listingPage.itemExist(itemId, false).goToCreateItem();
Expand Down Expand Up @@ -201,7 +200,7 @@ describe("Realm roles test", () => {

it("Should delete associated roles from list test", () => {
itemId = "realm_role_crud";
itemId += "_" + uuid();
itemId += "_" + crypto.randomUUID();

// Create
listingPage.itemExist(itemId, false).goToCreateItem();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import RealmSettingsPage from "../support/pages/admin-ui/manage/realm_settings/RealmSettingsPage";
Expand All @@ -13,7 +12,7 @@ const modalUtils = new ModalUtils();
const masthead = new Masthead();

describe("Realm settings client policies tab tests", () => {
const realmName = "Realm_" + uuid();
const realmName = "Realm_" + crypto.randomUUID();
const realmSettingsPage = new RealmSettingsPage(realmName);

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import RealmSettingsPage from "../support/pages/admin-ui/manage/realm_settings/RealmSettingsPage";
Expand All @@ -15,7 +14,7 @@ const masthead = new Masthead();
describe("Realm settings client profiles tab tests", () => {
const profileName = "Test";
const editedProfileName = "Edit";
const realmName = "Realm_" + uuid();
const realmName = "Realm_" + crypto.randomUUID();
const realmSettingsPage = new RealmSettingsPage(realmName);

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import RealmSettingsPage from "../support/pages/admin-ui/manage/realm_settings/RealmSettingsPage";
Expand All @@ -17,7 +16,7 @@ const realmSettingsPage = new RealmSettingsPage();
const keysTab = new KeysTab();

describe("Realm settings events tab tests", () => {
const realmName = "Realm_" + uuid();
const realmName = "Realm_" + crypto.randomUUID();
const listingPage = new ListingPage();

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from "uuid";
import { SERVER_URL } from "../support/constants";
import LoginPage from "../support/pages/LoginPage";
import Masthead from "../support/pages/admin-ui/Masthead";
Expand All @@ -13,7 +12,7 @@ const masthead = new Masthead();
const realmSettingsPage = new RealmSettingsPage();

describe("Realm settings general tab tests", () => {
const realmName = "Realm_" + uuid();
const realmName = "Realm_" + crypto.randomUUID();

beforeEach(() => {
loginPage.logIn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { v4 as uuid } from "uuid";

import FormValidation from "../support/forms/FormValidation";
import LoginPage from "../support/pages/LoginPage";
import Masthead from "../support/pages/admin-ui/Masthead";
Expand All @@ -20,7 +18,7 @@ const keysTab = new KeysTab();
const modalUtils = new ModalUtils();

describe("Realm settings tabs tests", () => {
const realmName = "Realm_" + uuid();
const realmName = "Realm_" + crypto.randomUUID();

beforeEach(() => {
loginPage.logIn();
Expand Down
Loading

0 comments on commit 8f2c3a7

Please sign in to comment.