test(auth): cover OIDC profile name fallbacks
This commit is contained in:
1 parent
05047ee5f7
commit
36f197aa6d
2 files changed
+31
-2
No files matched your search
@@ -37,6 +37,35 @@ describe("getProfileValueByPath", () => {
|
||||
});
|
||||
|
||||
describe("extractProfileName", () => {
|
||||
test("uses preferred_username when overwrite is not set", () => {
|
||||
const profile = {
|
||||
sub: "user-id",
|
||||
preferred_username: "johndoe",
|
||||
} satisfies Profile;
|
||||
|
||||
expect(extractProfileName(profile)).toBe("johndoe");
|
||||
});
|
||||
|
||||
test("uses name when preferred_username is an email", () => {
|
||||
const profile = {
|
||||
sub: "user-id",
|
||||
preferred_username: "john@example.com",
|
||||
name: "John Doe",
|
||||
} satisfies Profile;
|
||||
|
||||
expect(extractProfileName(profile)).toBe("John Doe");
|
||||
});
|
||||
|
||||
test("returns undefined when the fallback name is null", () => {
|
||||
const profile = {
|
||||
sub: "user-id",
|
||||
preferred_username: "john@example.com",
|
||||
name: null,
|
||||
} satisfies Profile;
|
||||
|
||||
expect(extractProfileName(profile)).toBeUndefined();
|
||||
});
|
||||
|
||||
test("uses a nested name claim when configured", () => {
|
||||
mockEnv.AUTH_OIDC_NAME_ATTRIBUTE_OVERWRITE = "user.profile.display_name";
|
||||
const profile = {
|
||||
|
||||
Reference in new issue
Block a user