Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+40
-30
@@ -1,32 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { extractAdminSsoClaims, hasAllowedAdminGroup, isAllowedAdminGroup, mapGroupsToRole } from "./claims.server";
|
||||
|
||||
describe("mapGroupsToRole", () => {
|
||||
it("maps hivegrid-admin to super_admin", () => {
|
||||
expect(mapGroupsToRole(["hivegrid-admin"])).toBe("super_admin");
|
||||
});
|
||||
|
||||
it("maps hivegrid-staff to staff", () => {
|
||||
expect(mapGroupsToRole(["hivegrid-staff"])).toBe("staff");
|
||||
});
|
||||
|
||||
it("prefers super_admin when both groups are present", () => {
|
||||
expect(mapGroupsToRole(["hivegrid-staff", "hivegrid-admin"])).toBe("super_admin");
|
||||
});
|
||||
|
||||
it("returns null for an unknown group", () => {
|
||||
expect(mapGroupsToRole(["random-group"])).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for an empty list", () => {
|
||||
expect(mapGroupsToRole([])).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for null/undefined input", () => {
|
||||
expect(mapGroupsToRole(undefined)).toBeNull();
|
||||
expect(mapGroupsToRole(null)).toBeNull();
|
||||
});
|
||||
});
|
||||
import { extractAdminSsoClaims, hasAllowedAdminGroup, isAllowedAdminGroup } from "./claims.server";
|
||||
|
||||
describe("isAllowedAdminGroup / hasAllowedAdminGroup", () => {
|
||||
it("recognizes the two allowlisted groups", () => {
|
||||
@@ -44,6 +17,12 @@ describe("isAllowedAdminGroup / hasAllowedAdminGroup", () => {
|
||||
it("returns true when at least one allowed group is present", () => {
|
||||
expect(hasAllowedAdminGroup(["other", "hivegrid-staff"])).toBe(true);
|
||||
});
|
||||
|
||||
it("treats both allowed groups identically as access gates", () => {
|
||||
expect(hasAllowedAdminGroup(["hivegrid-admin"])).toBe(true);
|
||||
expect(hasAllowedAdminGroup(["hivegrid-staff"])).toBe(true);
|
||||
expect(hasAllowedAdminGroup(["hivegrid-staff", "hivegrid-admin"])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractAdminSsoClaims", () => {
|
||||
@@ -53,6 +32,7 @@ describe("extractAdminSsoClaims", () => {
|
||||
email_verified: true,
|
||||
name: "Admin Person",
|
||||
groups: ["hivegrid-admin"],
|
||||
amr: ["pwd", "mfa"],
|
||||
};
|
||||
|
||||
it("extracts and normalizes a valid claim set", () => {
|
||||
@@ -64,6 +44,7 @@ describe("extractAdminSsoClaims", () => {
|
||||
expect(result.claims.name).toBe("Admin Person");
|
||||
expect(result.claims.groups).toEqual(["hivegrid-admin"]);
|
||||
expect(result.claims.emailVerified).toBe(true);
|
||||
expect(result.claims.authenticationMethods).toEqual(["pwd", "mfa"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -97,11 +78,18 @@ describe("extractAdminSsoClaims", () => {
|
||||
if (!result.ok) expect(result.reason).toBe("email-not-verified");
|
||||
});
|
||||
|
||||
it("treats missing email_verified as true (Authentik does not always emit it)", () => {
|
||||
it("rejects a missing email_verified claim", () => {
|
||||
const claims = { ...validClaims } as Record<string, unknown>;
|
||||
delete claims.email_verified;
|
||||
const result = extractAdminSsoClaims(claims);
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.reason).toBe("email-not-verified");
|
||||
});
|
||||
|
||||
it("rejects malformed truthy email_verified claims", () => {
|
||||
const result = extractAdminSsoClaims({ ...validClaims, email_verified: "true" });
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.reason).toBe("email-not-verified");
|
||||
});
|
||||
|
||||
it("filters non-string entries from groups", () => {
|
||||
@@ -110,6 +98,28 @@ describe("extractAdminSsoClaims", () => {
|
||||
if (result.ok) expect(result.claims.groups).toEqual(["hivegrid-admin", "ok"]);
|
||||
});
|
||||
|
||||
it("canonicalizes duplicate groups emitted by overlapping Authentik scope mappings", () => {
|
||||
const result = extractAdminSsoClaims({
|
||||
...validClaims,
|
||||
groups: ["authentik Admins", "sogo-users", "hivegrid-admin", "authentik Admins", "sogo-users", "hivegrid-admin"],
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.claims.groups).toEqual(["authentik Admins", "sogo-users", "hivegrid-admin"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("extracts only string authentication methods and defaults missing amr to an empty list", () => {
|
||||
const filtered = extractAdminSsoClaims({ ...validClaims, amr: ["pwd", null, 7, "mfa"] });
|
||||
expect(filtered.ok).toBe(true);
|
||||
if (filtered.ok) expect(filtered.claims.authenticationMethods).toEqual(["pwd", "mfa"]);
|
||||
|
||||
const missing = extractAdminSsoClaims({ ...validClaims, amr: undefined });
|
||||
expect(missing.ok).toBe(true);
|
||||
if (missing.ok) expect(missing.claims.authenticationMethods).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns missing-sub for null claims", () => {
|
||||
const result = extractAdminSsoClaims(null);
|
||||
expect(result.ok).toBe(false);
|
||||
|
||||
Reference in new issue
Block a user