feat(auth) : add admin account management
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
isAllowedAdminRegistration,
|
||||
isAuthorizedAdmin,
|
||||
isConfiguredAdminEmail,
|
||||
} from "./authorization";
|
||||
|
||||
const verified = {
|
||||
@@ -13,61 +11,14 @@ const verified = {
|
||||
};
|
||||
|
||||
describe("admin authorization", () => {
|
||||
it("recognizes only the exact configured administrator email", () => {
|
||||
expect(isConfiguredAdminEmail(verified.email, "[email protected]")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isConfiguredAdminEmail(verified.email, "[email protected]")).toBe(
|
||||
false,
|
||||
);
|
||||
expect(isConfiguredAdminEmail(verified.email, undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("supports a comma-separated administrator email list", () => {
|
||||
it("allows any verified credential user", () => {
|
||||
expect(isAuthorizedAdmin(verified)).toBe(true);
|
||||
expect(
|
||||
isConfiguredAdminEmail(
|
||||
"[email protected]",
|
||||
"[email protected], [email protected]",
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isConfiguredAdminEmail(
|
||||
"[email protected]",
|
||||
"[email protected], [email protected]",
|
||||
),
|
||||
isAuthorizedAdmin({ ...verified, emailVerified: false }),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("allows only credential registration for the configured administrator", () => {
|
||||
expect(
|
||||
isAllowedAdminRegistration(
|
||||
verified.email,
|
||||
"email-password",
|
||||
verified.email,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isAllowedAdminRegistration(
|
||||
"[email protected]",
|
||||
"email-password",
|
||||
verified.email,
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isAllowedAdminRegistration(verified.email, "oauth", verified.email),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("requires an exact verified email match", () => {
|
||||
expect(isAuthorizedAdmin(verified, "[email protected]")).toBe(true);
|
||||
expect(isAuthorizedAdmin(verified, "[email protected]")).toBe(false);
|
||||
expect(
|
||||
isAuthorizedAdmin({ ...verified, emailVerified: false }, verified.email),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("denies missing users and missing configuration", () => {
|
||||
expect(isAuthorizedAdmin(null, verified.email)).toBe(false);
|
||||
expect(isAuthorizedAdmin(verified, undefined)).toBe(false);
|
||||
it("denies missing users", () => {
|
||||
expect(isAuthorizedAdmin(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user