Reject incomplete tenant identity metadata (#13)
This commit is contained in:
1 parent
ade7156c01
commit
d6e9b505ea
3 files changed
+42
-23
No files matched your search
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
||||
import { CorpConfig, HoseSealSource } from "../config/types.js";
|
||||
import {
|
||||
HOSE_STANDARD_DOMAINS,
|
||||
assertHoseAssistTenantMatches,
|
||||
defaultSealUrl,
|
||||
exchangeHoseAssistLink,
|
||||
fetchHoseStaffDetails,
|
||||
@@ -182,4 +183,15 @@ describe("hose auth helpers", () => {
|
||||
expiresIn: 1800
|
||||
});
|
||||
});
|
||||
|
||||
test("requires complete and consistent tenant identity metadata", () => {
|
||||
expect(() => assertHoseAssistTenantMatches("acme-01", {})).toThrow("tenant mismatch");
|
||||
expect(() => assertHoseAssistTenantMatches("acme-01", {
|
||||
tenantSlug: "acme-01",
|
||||
hoseCorpConfig: { corporationId: "other-corp" }
|
||||
})).toThrow("tenant mismatch");
|
||||
expect(() => assertHoseAssistTenantMatches("Acme-01", {
|
||||
hoseCorpConfig: { corporationId: " ACME-01 " }
|
||||
})).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -198,7 +198,14 @@ export function assertHoseAssistTenantMatches(corpId: string, tenant: Record<str
|
||||
: undefined;
|
||||
const candidates = [tenant.tenantSlug, hoseCorpConfig?.corporationId]
|
||||
.filter((value): value is string => typeof value === "string" && Boolean(value));
|
||||
if (candidates.length > 0 && !candidates.some((value) => value.toLowerCase() === corpId)) {
|
||||
const expectedCorpId = corpId.trim().toLowerCase();
|
||||
const normalizedCandidates = candidates
|
||||
.map((value) => value.trim().toLowerCase())
|
||||
.filter(Boolean);
|
||||
if (
|
||||
normalizedCandidates.length === 0 ||
|
||||
normalizedCandidates.some((value) => value !== expectedCorpId)
|
||||
) {
|
||||
throw new Error("Hose assistance link tenant mismatch: the Seal tenant does not match ekbCorpId");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user