mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
* Tests: stabilize detect-secrets fixtures * Tests: fix rebased detect-secrets false positives * Docs: keep snippets valid under detect-secrets * Tests: finalize detect-secrets false-positive fixes * Tests: reduce detect-secrets false positives * Tests: keep detect-secrets pragmas inline * Tests: remediate next detect-secrets batch * Tests: tighten detect-secrets allowlists * Tests: stabilize detect-secrets formatter drift
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import { hasConfiguredMSTeamsCredentials, resolveMSTeamsCredentials } from "./token.js";
|
|
|
|
const ORIGINAL_ENV = {
|
|
appId: process.env.MSTEAMS_APP_ID,
|
|
appPassword: process.env.MSTEAMS_APP_PASSWORD,
|
|
tenantId: process.env.MSTEAMS_TENANT_ID,
|
|
};
|
|
|
|
afterEach(() => {
|
|
if (ORIGINAL_ENV.appId === undefined) {
|
|
delete process.env.MSTEAMS_APP_ID;
|
|
} else {
|
|
process.env.MSTEAMS_APP_ID = ORIGINAL_ENV.appId;
|
|
}
|
|
if (ORIGINAL_ENV.appPassword === undefined) {
|
|
delete process.env.MSTEAMS_APP_PASSWORD;
|
|
} else {
|
|
process.env.MSTEAMS_APP_PASSWORD = ORIGINAL_ENV.appPassword;
|
|
}
|
|
if (ORIGINAL_ENV.tenantId === undefined) {
|
|
delete process.env.MSTEAMS_TENANT_ID;
|
|
} else {
|
|
process.env.MSTEAMS_TENANT_ID = ORIGINAL_ENV.tenantId;
|
|
}
|
|
});
|
|
|
|
describe("resolveMSTeamsCredentials", () => {
|
|
it("returns configured credentials for plaintext values", () => {
|
|
const resolved = resolveMSTeamsCredentials({
|
|
appId: " app-id ",
|
|
appPassword: " app-password ",
|
|
tenantId: " tenant-id ",
|
|
});
|
|
|
|
expect(resolved).toEqual({
|
|
appId: "app-id",
|
|
appPassword: "app-password", // pragma: allowlist secret
|
|
tenantId: "tenant-id",
|
|
});
|
|
});
|
|
|
|
it("throws when appPassword remains an unresolved SecretRef object", () => {
|
|
expect(() =>
|
|
resolveMSTeamsCredentials({
|
|
appId: "app-id",
|
|
appPassword: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "MSTEAMS_APP_PASSWORD",
|
|
},
|
|
tenantId: "tenant-id",
|
|
}),
|
|
).toThrow(/channels\.msteams\.appPassword: unresolved SecretRef/i);
|
|
});
|
|
});
|
|
|
|
describe("hasConfiguredMSTeamsCredentials", () => {
|
|
it("treats SecretRef appPassword as configured", () => {
|
|
const configured = hasConfiguredMSTeamsCredentials({
|
|
appId: "app-id",
|
|
appPassword: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "MSTEAMS_APP_PASSWORD",
|
|
},
|
|
tenantId: "tenant-id",
|
|
});
|
|
|
|
expect(configured).toBe(true);
|
|
});
|
|
});
|