Skip to content

Commit

Permalink
Fix search by attribute tests (keycloak#27670)
Browse files Browse the repository at this point in the history
Closes keycloak#16948

Signed-off-by: twobiers <[email protected]>
  • Loading branch information
twobiers authored Mar 11, 2024
1 parent c09da66 commit a71d07d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions js/libs/keycloak-admin-client/test/users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type GroupRepresentation from "../src/defs/groupRepresentation.js";
import { RequiredActionAlias } from "../src/defs/requiredActionProviderRepresentation.js";
import type RoleRepresentation from "../src/defs/roleRepresentation.js";
import type UserRepresentation from "../src/defs/userRepresentation.js";
import { UnmanagedAttributePolicy } from "../src/defs/userProfileMetadata.js";
import { credentials } from "./constants.js";

const expect = chai.expect;
Expand All @@ -24,6 +25,14 @@ describe("Users", () => {
before(async () => {
kcAdminClient = new KeycloakAdminClient();
await kcAdminClient.auth(credentials);

// Enable unmanaged attributes
const currentProfileConfig = await kcAdminClient.users.getProfile();
await kcAdminClient.users.updateProfile({
...currentProfileConfig,
unmanagedAttributePolicy: UnmanagedAttributePolicy.Enabled,
});

// initialize user
const username = faker.internet.userName();
const user = await kcAdminClient.users.create({
Expand Down Expand Up @@ -95,10 +104,19 @@ describe("Users", () => {
expect(profile).to.be.ok;
});

it.skip("find users by custom attributes", async () => {
it("find users by custom attributes", async () => {
// Searching by attributes is only available from Keycloak > 15
const users = await kcAdminClient.users.find({ q: "key:value" });
expect(users.length).to.be.equal(1);
expect(users[0]).to.be.deep.include(currentUser);
});

it("find users by builtin attributes", async () => {
// Searching by attributes is only available from Keycloak > 15
const users = await kcAdminClient.users.find({ key: "value" });
expect(users.length).to.be.equal(2);
const users = await kcAdminClient.users.find({
q: `email:${currentUser.email}`,
});
expect(users.length).to.be.equal(1);
expect(users[0]).to.be.deep.include(currentUser);
});

Expand Down

0 comments on commit a71d07d

Please sign in to comment.