mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { isValidRpId } from "./domain-utils";
|
|
|
|
// Spec: If options.rp.id is not a registrable domain suffix of and is not equal to effectiveDomain, return a DOMException whose name is "SecurityError", and terminate this algorithm.
|
|
describe("validateRpId", () => {
|
|
it("should not be valid when rpId is more specific than origin", () => {
|
|
const rpId = "sub.login.bitwarden.com";
|
|
const origin = "https://login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(false);
|
|
});
|
|
|
|
it("should not be valid when effective domains of rpId and origin do not match", () => {
|
|
const rpId = "passwordless.dev";
|
|
const origin = "https://login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(false);
|
|
});
|
|
|
|
it("should not be valid when subdomains are the same but effective domains of rpId and origin do not match", () => {
|
|
const rpId = "login.passwordless.dev";
|
|
const origin = "https://login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(false);
|
|
});
|
|
|
|
it("should be valid when domains of rpId and origin are the same", () => {
|
|
const rpId = "bitwarden.com";
|
|
const origin = "https://bitwarden.com";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(true);
|
|
});
|
|
|
|
it("should be valid when origin is a subdomain of rpId", () => {
|
|
const rpId = "bitwarden.com";
|
|
const origin = "https://login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(true);
|
|
});
|
|
|
|
it("should be valid when domains of rpId and origin are the same and they are both subdomains", () => {
|
|
const rpId = "login.bitwarden.com";
|
|
const origin = "https://login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(true);
|
|
});
|
|
|
|
it("should be valid when origin is a subdomain of rpId and they are both subdomains", () => {
|
|
const rpId = "login.bitwarden.com";
|
|
const origin = "https://sub.login.bitwarden.com:1337";
|
|
|
|
expect(isValidRpId(rpId, origin)).toBe(true);
|
|
});
|
|
});
|