/ opencodehub / tests / unit / scim-saml.test.ts
Swadhin Biswas Feature/ai code reviewer (#73) · 8/2/2026
105a287
56 lines · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { describe, it, expect } from "vitest";
import { formatSCIMUser, SCIM_SCHEMAS, createSCIMError } from "../../src/lib/scim";
import { generateSPMetadata } from "../../src/lib/saml";
import { handleDockerV2Ping } from "../../src/lib/packages-server";

describe("SCIM 2.0 Engine", () => {
    it("formats a user object into a valid SCIM 2.0 resource", () => {
        const mockUser = {
            id: "user-123",
            username: "johndoe",
            email: "[email protected]",
            displayName: "John Doe",
            createdAt: new Date("2026-01-01T00:00:00Z"),
            updatedAt: new Date("2026-01-02T00:00:00Z"),
        };

        const scimUser = formatSCIMUser(mockUser, "https://git.example.com");

        expect(scimUser.schemas).toContain(SCIM_SCHEMAS.USER);
        expect(scimUser.id).toBe("user-123");
        expect(scimUser.userName).toBe("johndoe");
        expect(scimUser.emails[0].value).toBe("[email protected]");
        expect(scimUser.active).toBe(true);
        expect(scimUser.meta.location).toBe("https://git.example.com/api/scim/v2/Users/user-123");
    });

    it("creates standard SCIM error objects", () => {
        const err = createSCIMError(404, "User not found");
        expect(err.schemas).toContain(SCIM_SCHEMAS.ERROR);
        expect(err.status).toBe("404");
        expect(err.detail).toBe("User not found");
    });
});

describe("SAML 2.0 Engine", () => {
    it("generates valid Service Provider metadata XML", () => {
        const xml = generateSPMetadata({
            spEntityId: "https://git.example.com/saml/metadata",
            callbackUrl: "https://git.example.com/saml/callback",
        });

        expect(xml).toContain("https://git.example.com/saml/metadata");
        expect(xml).toContain("https://git.example.com/saml/callback");
        expect(xml).toContain("md:EntityDescriptor");
        expect(xml).toContain("md:SPSSODescriptor");
    });
});

describe("OCI Container Registry Server", () => {
    it("returns 200 with Docker-Distribution-Api-Version header on ping", () => {
        const ping = handleDockerV2Ping();
        expect(ping.status).toBe(200);
        expect(ping.headers["Docker-Distribution-Api-Version"]).toBe("registry/2.0");
    });
});