diff --git a/apps/account-ui/src/components/alerts/Alerts.tsx b/apps/account-ui/src/components/alerts/Alerts.tsx index d25c8ac734..2839f2d4ff 100644 --- a/apps/account-ui/src/components/alerts/Alerts.tsx +++ b/apps/account-ui/src/components/alerts/Alerts.tsx @@ -26,7 +26,7 @@ export const AlertContext = createContext(undefined); export const useAlerts = () => useContext(AlertContext)!; export type AlertType = { - id: number; + id: string; message: string; variant: AlertVariant; description?: string; @@ -36,7 +36,7 @@ export const AlertProvider = ({ children }: PropsWithChildren) => { const { t } = useTranslation(); const [alerts, setAlerts] = useState([]); - const hideAlert = (id: number) => { + const hideAlert = (id: string) => { setAlerts((alerts) => alerts.filter((alert) => alert.id !== id)); }; @@ -47,7 +47,7 @@ export const AlertProvider = ({ children }: PropsWithChildren) => { ) => { setAlerts([ { - id: Math.random() * 100, + id: crypto.randomUUID(), //@ts-ignore message: t(message), variant, diff --git a/apps/admin-ui/cypress/e2e/client_authorization_test.spec.ts b/apps/admin-ui/cypress/e2e/client_authorization_test.spec.ts index 49af92dc64..115ac18a04 100644 --- a/apps/admin-ui/cypress/e2e/client_authorization_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/client_authorization_test.spec.ts @@ -20,8 +20,7 @@ describe("Client authentication subtab", () => { const clientDetailsPage = new ClientDetailsPage(); const policiesSubTab = new PoliciesTab(); const permissionsSubTab = new PermissionsTab(); - const clientId = - "client-authentication-" + (Math.random() + 1).toString(36).substring(7); + const clientId = "client-authentication-" + crypto.randomUUID(); before(() => { keycloakBefore(); diff --git a/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts b/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts index 1ca3b5243f..3d555125d3 100644 --- a/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts @@ -299,7 +299,7 @@ describe("Client Scopes test", () => { }); it("Client scope CRUD test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create listingPage.itemExist(itemId, false).goToCreateItem(); diff --git a/apps/admin-ui/cypress/e2e/clients_test.spec.ts b/apps/admin-ui/cypress/e2e/clients_test.spec.ts index 0b35e94d4b..8173f1a351 100644 --- a/apps/admin-ui/cypress/e2e/clients_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/clients_test.spec.ts @@ -316,7 +316,7 @@ describe("Clients test", () => { }); it("Client CRUD test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create commonPage.tableUtils().checkRowItemExists(itemId, false); @@ -491,7 +491,7 @@ describe("Clients test", () => { loginPage.logIn(); commonPage.sidebar().goToClients(); - client = "client_" + (Math.random() + 1).toString(36).substring(7); + client = "client_" + crypto.randomUUID(); commonPage.tableToolbarUtils().createClient(); @@ -703,7 +703,7 @@ describe("Clients test", () => { beforeEach(() => { commonPage.sidebar().goToClients(); - client = "client_" + (Math.random() + 1).toString(36).substring(7); + client = "client_" + crypto.randomUUID(); commonPage.tableToolbarUtils().createClient(); createClientPage .selectClientType("openid-connect") diff --git a/apps/admin-ui/cypress/e2e/group_test.spec.ts b/apps/admin-ui/cypress/e2e/group_test.spec.ts index b504c3319e..51e1d1d757 100644 --- a/apps/admin-ui/cypress/e2e/group_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/group_test.spec.ts @@ -55,7 +55,7 @@ describe("Group test", () => { keycloakBefore(); loginPage.logIn(); sidebarPage.goToGroups(); - groupName = groupNamePrefix + (Math.random() + 1).toString(36).substring(7); + groupName = groupNamePrefix + crypto.randomUUID(); groupNames.push(groupName); }); diff --git a/apps/admin-ui/cypress/e2e/realm_roles_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_roles_test.spec.ts index af94430dc8..7c85fd4178 100644 --- a/apps/admin-ui/cypress/e2e/realm_roles_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_roles_test.spec.ts @@ -46,7 +46,7 @@ describe("Realm roles test", () => { }); it("Realm role CRUD test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create listingPage.itemExist(itemId, false).goToCreateItem(); @@ -69,7 +69,7 @@ describe("Realm roles test", () => { }); it("should delete role from details action", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); listingPage.goToCreateItem(); createRealmRolePage.fillRealmRoleData(itemId).save(); masthead.checkNotificationMessage("Role created", true); @@ -89,7 +89,7 @@ describe("Realm roles test", () => { }); it("Add associated roles test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create listingPage.itemExist(itemId, false).goToCreateItem(); @@ -183,7 +183,7 @@ describe("Realm roles test", () => { it("Should delete associated roles from list test", () => { itemId = "realm_role_crud"; - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create listingPage.itemExist(itemId, false).goToCreateItem(); diff --git a/apps/admin-ui/cypress/e2e/realm_settings_client_policies_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_client_policies_test.spec.ts index 313a402c29..db6ce1ee49 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_client_policies_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_client_policies_test.spec.ts @@ -12,7 +12,7 @@ const modalUtils = new ModalUtils(); const masthead = new Masthead(); describe("Realm settings client policies tab tests", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); const realmSettingsPage = new RealmSettingsPage(realmName); beforeEach(() => { diff --git a/apps/admin-ui/cypress/e2e/realm_settings_client_profiles_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_client_profiles_test.spec.ts index 92ffde6e78..53c352bd81 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_client_profiles_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_client_profiles_test.spec.ts @@ -14,7 +14,7 @@ const masthead = new Masthead(); describe("Realm settings client profiles tab tests", () => { const profileName = "Test"; const editedProfileName = "Edit"; - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); const realmSettingsPage = new RealmSettingsPage(realmName); beforeEach(() => { diff --git a/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts index 1d37563fb4..7db201c5b9 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts @@ -14,7 +14,7 @@ const modalUtils = new ModalUtils(); const realmSettingsPage = new RealmSettingsPage(); describe("Realm settings events tab tests", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); const listingPage = new ListingPage(); beforeEach(() => { @@ -88,8 +88,8 @@ describe("Realm settings events tab tests", () => { const addBundle = () => { realmSettingsPage.addKeyValuePair( - "key_" + (Math.random() + 1).toString(36).substring(7), - "value_" + (Math.random() + 1).toString(36).substring(7) + "key_" + crypto.randomUUID(), + "value_" + crypto.randomUUID() ); return this; diff --git a/apps/admin-ui/cypress/e2e/realm_settings_general_tab_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_general_tab_test.spec.ts index 5944159107..89c49c9e50 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_general_tab_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_general_tab_test.spec.ts @@ -11,7 +11,7 @@ const masthead = new Masthead(); const realmSettingsPage = new RealmSettingsPage(); describe("Realm settings general tab tests", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); beforeEach(() => { keycloakBefore(); diff --git a/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts index 55714f2328..17d8fda75a 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts @@ -11,7 +11,7 @@ const masthead = new Masthead(); const realmSettingsPage = new RealmSettingsPage(); describe("Realm settings tabs tests", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); beforeEach(() => { keycloakBefore(); diff --git a/apps/admin-ui/cypress/e2e/realm_settings_user_profile_tab.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_user_profile_tab.spec.ts index f3c557981d..99fd14f127 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_user_profile_tab.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_user_profile_tab.spec.ts @@ -23,7 +23,7 @@ const clickCreateAttributeButton = () => userProfileTab.createAttributeButtonClick(); describe("User profile tabs", () => { - const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmName = "Realm_" + crypto.randomUUID(); const attributeName = "Test"; before(() => { diff --git a/apps/admin-ui/cypress/e2e/realm_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_test.spec.ts index 0017931b3b..f005845c44 100644 --- a/apps/admin-ui/cypress/e2e/realm_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_test.spec.ts @@ -14,12 +14,9 @@ const createRealmPage = new CreateRealmPage(); const realmSettings = new RealmSettings(); const modalUtils = new ModalUtils(); -const testRealmName = - "Test-realm-" + (Math.random() + 1).toString(36).substring(7); -const newRealmName = - "New-Test-realm-" + (Math.random() + 1).toString(36).substring(7); -const editedRealmName = - "Edited-Test-realm-" + (Math.random() + 1).toString(36).substring(7); +const testRealmName = "Test-realm-" + crypto.randomUUID(); +const newRealmName = "New-Test-realm-" + crypto.randomUUID(); +const editedRealmName = "Edited-Test-realm-" + crypto.randomUUID(); const testDisabledName = "Test-Disabled"; describe("Realm tests", () => { diff --git a/apps/admin-ui/cypress/e2e/users_test.spec.ts b/apps/admin-ui/cypress/e2e/users_test.spec.ts index b2e10c3ff5..2f19daf336 100644 --- a/apps/admin-ui/cypress/e2e/users_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/users_test.spec.ts @@ -37,7 +37,7 @@ describe("User creation", () => { before(() => { for (let i = 0; i <= 2; i++) { - groupName += "_" + (Math.random() + 1).toString(36).substring(7); + groupName += "_" + crypto.randomUUID(); adminClient.createGroup(groupName); groupsList = [...groupsList, groupName]; } @@ -63,7 +63,7 @@ describe("User creation", () => { }); it("Create user test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + itemId += "_" + crypto.randomUUID(); // Create createUserPage.goToCreateUser(); @@ -75,7 +75,7 @@ describe("User creation", () => { }); it("Create user with groups test", () => { - itemIdWithGroups += (Math.random() + 1).toString(36).substring(7); + itemIdWithGroups += crypto.randomUUID(); // Add user from search bar createUserPage.goToCreateUser(); @@ -97,7 +97,7 @@ describe("User creation", () => { }); it("Create user with credentials test", () => { - itemIdWithCred += "_" + (Math.random() + 1).toString(36).substring(7); + itemIdWithCred += "_" + crypto.randomUUID(); // Add user from search bar createUserPage.goToCreateUser(); diff --git a/apps/admin-ui/cypress/support/pages/admin-ui/manage/users/user_details/UserDetailsPage.ts b/apps/admin-ui/cypress/support/pages/admin-ui/manage/users/user_details/UserDetailsPage.ts index 76983ea332..c94870605a 100644 --- a/apps/admin-ui/cypress/support/pages/admin-ui/manage/users/user_details/UserDetailsPage.ts +++ b/apps/admin-ui/cypress/support/pages/admin-ui/manage/users/user_details/UserDetailsPage.ts @@ -19,10 +19,7 @@ export default class UserDetailsPage extends PageObject { this.cancelBtn = "cancel-create-user"; this.emailInput = "email-input"; this.emailValue = () => - "example" + - "_" + - (Math.random() + 1).toString(36).substring(7) + - "@example.com"; + "example" + "_" + crypto.randomUUID() + "@example.com"; this.firstNameInput = "firstName-input"; this.firstNameValue = "firstname"; this.lastNameInput = "lastName-input"; diff --git a/apps/admin-ui/src/components/alert/AlertPanel.tsx b/apps/admin-ui/src/components/alert/AlertPanel.tsx index 5d61bf8e2e..6f2a4b6b1a 100644 --- a/apps/admin-ui/src/components/alert/AlertPanel.tsx +++ b/apps/admin-ui/src/components/alert/AlertPanel.tsx @@ -8,7 +8,7 @@ import type { AlertEntry } from "./Alerts"; type AlertPanelProps = { alerts: AlertEntry[]; - onCloseAlert: (id: number) => void; + onCloseAlert: (id: string) => void; }; export function AlertPanel({ alerts, onCloseAlert }: AlertPanelProps) { diff --git a/apps/admin-ui/src/components/alert/Alerts.tsx b/apps/admin-ui/src/components/alert/Alerts.tsx index 5fa82c7d05..aee955c417 100644 --- a/apps/admin-ui/src/components/alert/Alerts.tsx +++ b/apps/admin-ui/src/components/alert/Alerts.tsx @@ -31,7 +31,7 @@ export const AlertContext = createNamedContext( export const useAlerts = () => useRequiredContext(AlertContext); export type AlertEntry = { - id: number; + id: string; message: string; variant: AlertVariant; description?: string; @@ -42,13 +42,13 @@ export const AlertProvider = ({ children }: PropsWithChildren) => { const setTimeout = useSetTimeout(); const [alerts, setAlerts] = useState([]); - const removeAlert = (id: number) => + const removeAlert = (id: string) => setAlerts((alerts) => alerts.filter((alert) => alert.id !== id)); const addAlert = useCallback( (message, variant = AlertVariant.success, description) => { const alert: AlertEntry = { - id: Math.random(), + id: crypto.randomUUID(), message, variant, description, diff --git a/apps/admin-ui/src/components/dynamic/MapComponent.tsx b/apps/admin-ui/src/components/dynamic/MapComponent.tsx index b40316af7d..d40831a6f5 100644 --- a/apps/admin-ui/src/components/dynamic/MapComponent.tsx +++ b/apps/admin-ui/src/components/dynamic/MapComponent.tsx @@ -18,11 +18,9 @@ import type { ComponentProps } from "./components"; import { convertToName } from "./DynamicComponents"; type IdKeyValueType = KeyValueType & { - id: number; + id: string; }; -const generateId = () => Math.floor(Math.random() * 100); - export const MapComponent = ({ name, label, helpText }: ComponentProps) => { const { t } = useTranslation("dynamic"); @@ -36,7 +34,7 @@ export const MapComponent = ({ name, label, helpText }: ComponentProps) => { if (!values.length) { values.push({ key: "", value: "" }); } - setMap(values.map((value) => ({ ...value, id: generateId() }))); + setMap(values.map((value) => ({ ...value, id: crypto.randomUUID() }))); }, [register, getValues]); const update = (val = map) => { @@ -130,7 +128,7 @@ export const MapComponent = ({ name, label, helpText }: ComponentProps) => { variant="link" icon={} onClick={() => - setMap([...map, { key: "", value: "", id: generateId() }]) + setMap([...map, { key: "", value: "", id: crypto.randomUUID() }]) } > {t("common:addAttribute")}