Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript
1.8 KB
Raw Blame
import { afterEach, describe, expect, it } from "bun:test";
import {
	googleHostedDomainHint,
	hasSignInAllowList,
	isWorkspaceEmail,
	primaryWorkspaceDomain,
} from "../src/workspace";

const originalAllowList = process.env.ALLOWED_SIGN_IN;

afterEach(() => {
	if (originalAllowList === undefined) delete process.env.ALLOWED_SIGN_IN;
	else process.env.ALLOWED_SIGN_IN = originalAllowList;
});

describe("Google hosted-domain hint", () => {
	it("uses the configured domain", () => {
		process.env.ALLOWED_SIGN_IN = "acme.com";
		expect(googleHostedDomainHint()).toBe("acme.com");
	});

	it("uses the common host from an address-only allow-list", () => {
		process.env.ALLOWED_SIGN_IN = "[email protected],[email protected]";
		expect(googleHostedDomainHint()).toBe("acme.com");
	});

	it("withholds the hint when allowed addresses use different hosts", () => {
		process.env.ALLOWED_SIGN_IN = "[email protected],[email protected]";
		expect(googleHostedDomainHint()).toBeUndefined();
	});

	it("does not widen access for an address-only allow-list", () => {
		process.env.ALLOWED_SIGN_IN = "[email protected]";
		expect(googleHostedDomainHint()).toBe("acme.com");
		expect(primaryWorkspaceDomain()).toBeUndefined();
		expect(isWorkspaceEmail("[email protected]")).toBe(false);
	});
});

describe("malformed allow-list hosts", () => {
	it.each([
		"https://acme.com",
		"-acme.com",
		"acme..com",
		"[email protected]",
		"owner@@acme.com",
	])("rejects %s", (entry) => {
		process.env.ALLOWED_SIGN_IN = entry;
		expect(hasSignInAllowList()).toBe(false);
		expect(googleHostedDomainHint()).toBeUndefined();
	});

	it.each(["[email protected]", "[email protected]", "owner @acme.com"])(
		"rejects the sign-in address %s",
		(email) => {
			process.env.ALLOWED_SIGN_IN = email;
			expect(isWorkspaceEmail(email)).toBe(false);
		},
	);
});