8d72f8a705
* upgrade cypress * fixed delete now has dialog * also check "unAssign" * client type no longer required * providers and group changes * grp creation working * moved create realm button ouside the dropdown * sped up test and added cleanup * Revert "moved create realm button ouside the dropdown" This reverts commit e2076a5305808417de910ba8fada8e528e5c356a. * make test re-runnable * removed un needed navigation * Fix misformed Cypress config for GitHub Action * cleanup after test * fixed cleanup * temporary removed this test * also remove user "new" * try adding a wait for CI * get different modal id * add {force: true} to modal functions * mv grp search last and ignore 401 * try using cy.get and disable video for testing * add back video artifacts Co-authored-by: mfrances <mfrances@redhat.com> Co-authored-by: Jon Koops <jonkoops@gmail.com> Co-authored-by: jenny-s51 <jshandel@redhat.com>
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import KeycloakAdminClient from "keycloak-admin";
|
|
import UserRepresentation from "keycloak-admin/lib/defs/userRepresentation";
|
|
import ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
|
|
|
export default class AdminClient {
|
|
private client: KeycloakAdminClient;
|
|
constructor() {
|
|
this.client = new KeycloakAdminClient({
|
|
baseUrl: "http://localhost:8180/auth",
|
|
realmName: "master",
|
|
});
|
|
}
|
|
|
|
private async login() {
|
|
await this.client.auth({
|
|
username: "admin",
|
|
password: "admin",
|
|
grantType: "password",
|
|
clientId: "admin-cli",
|
|
});
|
|
}
|
|
|
|
async createRealm(realm: string) {
|
|
await this.login();
|
|
await this.client.realms.create({ realm });
|
|
}
|
|
|
|
async deleteRealm(realm: string) {
|
|
await this.login();
|
|
await this.client.realms.del({ realm });
|
|
}
|
|
|
|
async createClient(client: ClientRepresentation) {
|
|
await this.login();
|
|
await this.client.clients.create(client);
|
|
}
|
|
|
|
async deleteClient(clientName: string) {
|
|
await this.login();
|
|
const client = (
|
|
await this.client.clients.find({ clientId: clientName })
|
|
)[0];
|
|
await this.client.clients.del({ id: client.id! });
|
|
}
|
|
|
|
async createSubGroups(groups: string[]) {
|
|
await this.login();
|
|
let parentGroup = undefined;
|
|
const createdGroups = [];
|
|
for (const group of groups) {
|
|
if (!parentGroup) {
|
|
parentGroup = await this.client.groups.create({ name: group });
|
|
} else {
|
|
parentGroup = await this.client.groups.setOrCreateChild(
|
|
{ id: parentGroup.id },
|
|
{ name: group }
|
|
);
|
|
}
|
|
createdGroups.push(parentGroup);
|
|
}
|
|
return createdGroups;
|
|
}
|
|
|
|
async deleteGroups() {
|
|
await this.login();
|
|
const groups = await this.client.groups.find();
|
|
for (const group of groups) {
|
|
await this.client.groups.del({ id: group.id! });
|
|
}
|
|
}
|
|
|
|
async createUser(user: UserRepresentation) {
|
|
await this.login();
|
|
return await this.client.users.create(user);
|
|
}
|
|
|
|
async createUserInGroup(username: string, groupId: string) {
|
|
await this.login();
|
|
const user = await this.createUser({ username, enabled: true });
|
|
await this.client.users.addToGroup({ id: user.id!, groupId });
|
|
}
|
|
|
|
async deleteUser(username: string) {
|
|
await this.login();
|
|
const user = await this.client.users.find({ username });
|
|
await this.client.users.del({ id: user[0].id! });
|
|
}
|
|
}
|