87 lines
2.1 KiB
JavaScript
87 lines
2.1 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { resolveRequiredGroups } from "./authentik-sync.mjs";
|
|
|
|
const user = {
|
|
id: "user_device_engineer",
|
|
email: "engineer@example.test",
|
|
name: "Device Engineer",
|
|
globalStatus: "active",
|
|
};
|
|
const client = { id: "client_dctouch", status: "active" };
|
|
const membership = {
|
|
id: "membership_device_engineer",
|
|
clientId: client.id,
|
|
userId: user.id,
|
|
role: "member",
|
|
status: "active",
|
|
};
|
|
const service = {
|
|
id: "service_device_core_contract",
|
|
slug: "device-core",
|
|
status: "active",
|
|
authentikApplicationSlug: "device-core",
|
|
authentikGroupName: "nodedc:device-core:access",
|
|
};
|
|
|
|
function data(grants = [], exceptions = []) {
|
|
return {
|
|
users: [user],
|
|
clients: [client],
|
|
memberships: [membership],
|
|
groups: [],
|
|
services: [service],
|
|
grants,
|
|
exceptions,
|
|
};
|
|
}
|
|
|
|
describe("generic service Authentik group projection", () => {
|
|
it("projects the service group only after an effective grant", () => {
|
|
const withoutGrant = resolveRequiredGroups(data(), user);
|
|
const withGrant = resolveRequiredGroups(
|
|
data([
|
|
{
|
|
id: "grant_device_core_dctouch",
|
|
serviceId: service.id,
|
|
targetType: "client",
|
|
targetId: client.id,
|
|
appRole: "admin",
|
|
status: "active",
|
|
},
|
|
]),
|
|
user
|
|
);
|
|
|
|
expect(withoutGrant).not.toContain("nodedc:device-core:access");
|
|
expect(withGrant).toContain("nodedc:device-core:access");
|
|
});
|
|
|
|
it("does not project the group when a deny exception wins", () => {
|
|
const groups = resolveRequiredGroups(
|
|
data(
|
|
[
|
|
{
|
|
id: "grant_device_core_dctouch",
|
|
serviceId: service.id,
|
|
targetType: "client",
|
|
targetId: client.id,
|
|
appRole: "admin",
|
|
status: "active",
|
|
},
|
|
],
|
|
[
|
|
{
|
|
id: "deny_device_core_engineer",
|
|
serviceId: service.id,
|
|
userId: user.id,
|
|
type: "deny",
|
|
},
|
|
]
|
|
),
|
|
user
|
|
);
|
|
|
|
expect(groups).not.toContain("nodedc:device-core:access");
|
|
});
|
|
});
|