mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
removed inRealm and fixed stabilization (#35337)
fixes: #35219 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
c5d9750490
commit
f5d515aeb4
@ -11,7 +11,6 @@ import {
|
||||
deleteIdentityProvider,
|
||||
deleteUser,
|
||||
findClientByClientId,
|
||||
inRealm,
|
||||
} from "../admin-client";
|
||||
import { SERVER_URL } from "../constants";
|
||||
import groupsIdPClient from "../realms/groups-idp.json" assert { type: "json" };
|
||||
@ -23,7 +22,11 @@ test.describe("Account linking", () => {
|
||||
let user: string;
|
||||
// Tests for keycloak account console, section Account linking in Account security
|
||||
test.beforeAll(async () => {
|
||||
user = await createRandomUserWithPassword("user-" + randomUUID(), "pwd");
|
||||
user = await createRandomUserWithPassword(
|
||||
"user-" + randomUUID(),
|
||||
"pwd",
|
||||
realm,
|
||||
);
|
||||
|
||||
const kcGroupsIdpId = await findClientByClientId("groups-idp");
|
||||
if (kcGroupsIdpId) {
|
||||
@ -49,17 +52,17 @@ test.describe("Account linking", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await inRealm(realm, () => createIdentityProvider(idp));
|
||||
await createIdentityProvider(idp, realm);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteUser(user);
|
||||
await deleteUser(user, realm);
|
||||
});
|
||||
test.afterAll(async () => {
|
||||
await deleteClient(groupIdPClientId);
|
||||
});
|
||||
test.afterAll(async () => {
|
||||
await inRealm(realm, () => deleteIdentityProvider("master-idp"));
|
||||
await deleteIdentityProvider("master-idp", realm);
|
||||
});
|
||||
|
||||
test("Linking", async ({ page }) => {
|
||||
|
||||
@ -30,16 +30,6 @@ export async function useTheme() {
|
||||
);
|
||||
}
|
||||
|
||||
export async function inRealm<T>(realm: string, fn: () => Promise<T>) {
|
||||
const prevRealm = adminClient.realmName;
|
||||
adminClient.realmName = realm;
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
adminClient.realmName = prevRealm;
|
||||
}
|
||||
}
|
||||
|
||||
export async function importRealm(realm: RealmRepresentation) {
|
||||
await adminClient.realms.create(realm);
|
||||
}
|
||||
@ -66,12 +56,16 @@ export async function deleteClient(id: string) {
|
||||
|
||||
export async function createIdentityProvider(
|
||||
idp: IdentityProviderRepresentation,
|
||||
realm = DEFAULT_REALM,
|
||||
): Promise<string> {
|
||||
return adminClient.identityProviders.create(idp)["id"];
|
||||
return adminClient.identityProviders.create({ ...idp, realm })["id"];
|
||||
}
|
||||
|
||||
export async function deleteIdentityProvider(alias: string) {
|
||||
await adminClient.identityProviders.del({ alias });
|
||||
export async function deleteIdentityProvider(
|
||||
alias: string,
|
||||
realm = DEFAULT_REALM,
|
||||
) {
|
||||
await adminClient.identityProviders.del({ alias, realm });
|
||||
}
|
||||
|
||||
export async function importUserProfile(
|
||||
@ -93,9 +87,12 @@ export async function enableLocalization(realm = DEFAULT_REALM) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function createUser(user: UserRepresentation) {
|
||||
export async function createUser(
|
||||
user: UserRepresentation,
|
||||
realm = DEFAULT_REALM,
|
||||
) {
|
||||
try {
|
||||
await adminClient.users.create(user);
|
||||
await adminClient.users.create({ ...user, realm });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
@ -104,19 +101,29 @@ export async function createUser(user: UserRepresentation) {
|
||||
export async function createRandomUserWithPassword(
|
||||
username: string,
|
||||
password: string,
|
||||
realm: string,
|
||||
props?: UserRepresentation,
|
||||
): Promise<string> {
|
||||
return createUser({
|
||||
username: username,
|
||||
enabled: true,
|
||||
credentials: [
|
||||
{
|
||||
type: "password",
|
||||
value: password,
|
||||
},
|
||||
],
|
||||
...props,
|
||||
}).then(() => username);
|
||||
await adminClient.auth({
|
||||
username: "admin",
|
||||
password: "admin",
|
||||
grantType: "password",
|
||||
clientId: "admin-cli",
|
||||
});
|
||||
return createUser(
|
||||
{
|
||||
username: username,
|
||||
enabled: true,
|
||||
credentials: [
|
||||
{
|
||||
type: "password",
|
||||
value: password,
|
||||
},
|
||||
],
|
||||
...props,
|
||||
},
|
||||
realm,
|
||||
).then(() => username);
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username: string, realm: string) {
|
||||
@ -124,11 +131,15 @@ export async function getUserByUsername(username: string, realm: string) {
|
||||
return users.length > 0 ? users[0] : undefined;
|
||||
}
|
||||
|
||||
export async function deleteUser(username: string) {
|
||||
export async function deleteUser(username: string, realm = DEFAULT_REALM) {
|
||||
try {
|
||||
const users = await adminClient.users.find({ username });
|
||||
const users = await adminClient.users.find({ username, realm });
|
||||
if (users.length === 0) {
|
||||
console.warn(`User ${username} not found in realm ${realm}`);
|
||||
return;
|
||||
}
|
||||
const { id } = users[0];
|
||||
await adminClient.users.del({ id: id! });
|
||||
await adminClient.users.del({ id: id!, realm });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import {
|
||||
deleteUser,
|
||||
enableLocalization,
|
||||
importUserProfile,
|
||||
inRealm,
|
||||
} from "../admin-client";
|
||||
import { login } from "../login";
|
||||
import userProfileConfig from "./user-profile.json" assert { type: "json" };
|
||||
@ -16,11 +15,8 @@ const realm = "user-profile";
|
||||
test.describe("Personal info page", () => {
|
||||
const user = "user-" + randomUUID();
|
||||
|
||||
test.beforeAll(
|
||||
async () =>
|
||||
await inRealm(realm, () => createRandomUserWithPassword(user, "pwd")),
|
||||
);
|
||||
test.afterAll(async () => await inRealm(realm, () => deleteUser(user)));
|
||||
test.beforeAll(() => createRandomUserWithPassword(user, "pwd", realm));
|
||||
test.afterAll(async () => deleteUser(user, realm));
|
||||
|
||||
test("sets basic information", async ({ page }) => {
|
||||
await login(page, user, "pwd", realm);
|
||||
@ -39,8 +35,11 @@ test.describe("Personal info with userprofile enabled", () => {
|
||||
let user: string;
|
||||
test.beforeAll(async () => {
|
||||
await importUserProfile(userProfileConfig as UserProfileConfig, realm);
|
||||
user = await inRealm(realm, () =>
|
||||
createRandomUserWithPassword("user-" + randomUUID(), "jdoe", {
|
||||
user = await createRandomUserWithPassword(
|
||||
"user-" + randomUUID(),
|
||||
"jdoe",
|
||||
realm,
|
||||
{
|
||||
email: "jdoe@keycloak.org",
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
@ -48,11 +47,11 @@ test.describe("Personal info with userprofile enabled", () => {
|
||||
clientRoles: {
|
||||
account: ["manage-account"],
|
||||
},
|
||||
}),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => await inRealm(realm, () => deleteUser(user)));
|
||||
test.afterAll(() => deleteUser(user, realm));
|
||||
|
||||
test("render user profile fields", async ({ page }) => {
|
||||
await login(page, user, "jdoe", realm);
|
||||
@ -121,8 +120,10 @@ test.describe("Personal info with userprofile enabled", () => {
|
||||
test.describe("Realm localization", () => {
|
||||
test.beforeAll(() => enableLocalization());
|
||||
test("change locale", async ({ page }) => {
|
||||
const user = await inRealm(realm, () =>
|
||||
createRandomUserWithPassword("user-" + randomUUID(), "pwd"),
|
||||
const user = await createRandomUserWithPassword(
|
||||
"user-" + randomUUID(),
|
||||
"pwd",
|
||||
realm,
|
||||
);
|
||||
|
||||
await login(page, user, "pwd", realm);
|
||||
|
||||
@ -105,53 +105,6 @@
|
||||
}
|
||||
],
|
||||
"clients": [
|
||||
{
|
||||
"clientId": "security-admin-console-v2",
|
||||
"rootUrl": "http://localhost:8080/",
|
||||
"adminUrl": "http://localhost:8080/",
|
||||
"surrogateAuthRequired": false,
|
||||
"enabled": true,
|
||||
"alwaysDisplayInConsole": false,
|
||||
"clientAuthenticatorType": "client-secret",
|
||||
"redirectUris": [
|
||||
"http://localhost:8080/*"
|
||||
],
|
||||
"webOrigins": [
|
||||
"http://localhost:8080"
|
||||
],
|
||||
"notBefore": 0,
|
||||
"bearerOnly": false,
|
||||
"consentRequired": false,
|
||||
"standardFlowEnabled": true,
|
||||
"implicitFlowEnabled": false,
|
||||
"directAccessGrantsEnabled": true,
|
||||
"serviceAccountsEnabled": false,
|
||||
"publicClient": true,
|
||||
"frontchannelLogout": false,
|
||||
"protocol": "openid-connect",
|
||||
"attributes": {},
|
||||
"authenticationFlowBindingOverrides": {},
|
||||
"fullScopeAllowed": true,
|
||||
"nodeReRegistrationTimeout": -1,
|
||||
"defaultClientScopes": [
|
||||
"web-origins",
|
||||
"role_list",
|
||||
"roles",
|
||||
"profile",
|
||||
"email"
|
||||
],
|
||||
"optionalClientScopes": [
|
||||
"address",
|
||||
"phone",
|
||||
"offline_access",
|
||||
"microprofile-jwt"
|
||||
],
|
||||
"access": {
|
||||
"view": true,
|
||||
"configure": true,
|
||||
"manage": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"identityProviders": [
|
||||
{
|
||||
|
||||
@ -191,53 +191,6 @@
|
||||
],
|
||||
"decisionStrategy": "UNANIMOUS"
|
||||
}
|
||||
},
|
||||
{
|
||||
"clientId": "security-admin-console-v2",
|
||||
"rootUrl": "http://localhost:8080/",
|
||||
"adminUrl": "http://localhost:8080/",
|
||||
"surrogateAuthRequired": false,
|
||||
"enabled": true,
|
||||
"alwaysDisplayInConsole": false,
|
||||
"clientAuthenticatorType": "client-secret",
|
||||
"redirectUris": [
|
||||
"http://localhost:8080/*"
|
||||
],
|
||||
"webOrigins": [
|
||||
"http://localhost:8080"
|
||||
],
|
||||
"notBefore": 0,
|
||||
"bearerOnly": false,
|
||||
"consentRequired": false,
|
||||
"standardFlowEnabled": true,
|
||||
"implicitFlowEnabled": false,
|
||||
"directAccessGrantsEnabled": true,
|
||||
"serviceAccountsEnabled": false,
|
||||
"publicClient": true,
|
||||
"frontchannelLogout": false,
|
||||
"protocol": "openid-connect",
|
||||
"attributes": {},
|
||||
"authenticationFlowBindingOverrides": {},
|
||||
"fullScopeAllowed": true,
|
||||
"nodeReRegistrationTimeout": -1,
|
||||
"defaultClientScopes": [
|
||||
"web-origins",
|
||||
"role_list",
|
||||
"roles",
|
||||
"profile",
|
||||
"email"
|
||||
],
|
||||
"optionalClientScopes": [
|
||||
"address",
|
||||
"phone",
|
||||
"offline_access",
|
||||
"microprofile-jwt"
|
||||
],
|
||||
"access": {
|
||||
"view": true,
|
||||
"configure": true,
|
||||
"manage": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -103,49 +103,6 @@
|
||||
}
|
||||
],
|
||||
"clients": [
|
||||
{
|
||||
"clientId": "security-admin-console-v2",
|
||||
"rootUrl": "http://localhost:8080/",
|
||||
"adminUrl": "http://localhost:8080/",
|
||||
"surrogateAuthRequired": false,
|
||||
"enabled": true,
|
||||
"alwaysDisplayInConsole": false,
|
||||
"clientAuthenticatorType": "client-secret",
|
||||
"redirectUris": ["http://localhost:8080/*"],
|
||||
"webOrigins": ["http://localhost:8080"],
|
||||
"notBefore": 0,
|
||||
"bearerOnly": false,
|
||||
"consentRequired": false,
|
||||
"standardFlowEnabled": true,
|
||||
"implicitFlowEnabled": false,
|
||||
"directAccessGrantsEnabled": true,
|
||||
"serviceAccountsEnabled": false,
|
||||
"publicClient": true,
|
||||
"frontchannelLogout": false,
|
||||
"protocol": "openid-connect",
|
||||
"attributes": {},
|
||||
"authenticationFlowBindingOverrides": {},
|
||||
"fullScopeAllowed": true,
|
||||
"nodeReRegistrationTimeout": -1,
|
||||
"defaultClientScopes": [
|
||||
"web-origins",
|
||||
"role_list",
|
||||
"roles",
|
||||
"profile",
|
||||
"email"
|
||||
],
|
||||
"optionalClientScopes": [
|
||||
"address",
|
||||
"phone",
|
||||
"offline_access",
|
||||
"microprofile-jwt"
|
||||
],
|
||||
"access": {
|
||||
"view": true,
|
||||
"configure": true,
|
||||
"manage": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"users": [
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user