864 lines
39 KiB
JavaScript
864 lines
39 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const crypto = require("crypto");
|
|
|
|
const {
|
|
encryptAssistantProviderToken,
|
|
decryptAssistantProviderToken,
|
|
migrateAssistantProviderSecretsV1ToV2,
|
|
createDashboardAssistantService,
|
|
} = require("./dashboard-assistant-service");
|
|
|
|
const SECRET_ENV_KEYS = [
|
|
"DASHBOARD_ASSISTANT_ENCRYPTION_SECRET",
|
|
"SESSION_SECRET",
|
|
"SECRET_KEY",
|
|
];
|
|
const CONTEXT = "adpanel:dashboard-assistant:provider-key:v1";
|
|
|
|
// Mirrors the legacy enc-v1 scheme: unsalted SHA-256 over context\0secret.
|
|
function legacyEncryptV1(token, secret) {
|
|
const key = crypto
|
|
.createHash("sha256")
|
|
.update(CONTEXT)
|
|
.update("\0")
|
|
.update(secret)
|
|
.digest();
|
|
const iv = crypto.randomBytes(12);
|
|
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
const ciphertext = Buffer.concat([cipher.update(token, "utf8"), cipher.final()]);
|
|
return [
|
|
"enc-v1",
|
|
iv.toString("base64"),
|
|
cipher.getAuthTag().toString("base64"),
|
|
ciphertext.toString("base64"),
|
|
].join(":");
|
|
}
|
|
|
|
// Mirrors the current enc-v2 scheme (scrypt over context\0salt, per-value
|
|
// salt) but lets the test choose the keying secret. Needed because the
|
|
// service itself no longer mints under SESSION_SECRET — tests must recreate
|
|
// the envelopes that OLDER versions produced via its deprecated fallback.
|
|
function encryptV2With(token, secret) {
|
|
const salt = crypto.randomBytes(16);
|
|
const saltInput = Buffer.concat([Buffer.from(CONTEXT), Buffer.from([0]), salt]);
|
|
const key = crypto.scryptSync(secret, saltInput, 32, {
|
|
N: 2 ** 15,
|
|
r: 8,
|
|
p: 1,
|
|
maxmem: 64 * 1024 * 1024,
|
|
});
|
|
const iv = crypto.randomBytes(12);
|
|
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
const ciphertext = Buffer.concat([cipher.update(token, "utf8"), cipher.final()]);
|
|
return [
|
|
"enc-v2",
|
|
salt.toString("base64"),
|
|
iv.toString("base64"),
|
|
cipher.getAuthTag().toString("base64"),
|
|
ciphertext.toString("base64"),
|
|
].join(":");
|
|
}
|
|
|
|
function withSecretEnv(overrides, fn) {
|
|
const saved = new Map(SECRET_ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
try {
|
|
for (const key of SECRET_ENV_KEYS) delete process.env[key];
|
|
for (const [key, value] of Object.entries(overrides)) {
|
|
process.env[key] = value;
|
|
}
|
|
return fn();
|
|
} finally {
|
|
for (const key of SECRET_ENV_KEYS) {
|
|
const previous = saved.get(key);
|
|
if (previous === undefined) delete process.env[key];
|
|
else process.env[key] = previous;
|
|
}
|
|
}
|
|
}
|
|
|
|
test("minting fails closed without the dedicated secret (no SESSION_SECRET fallback)", () => {
|
|
withSecretEnv({ SESSION_SECRET: "session-only-secret" }, () => {
|
|
// The deprecated fallback that minted under SESSION_SECRET is gone: a
|
|
// shared session-signing secret must never key new provider ciphertexts.
|
|
// (Older values minted under it stay DECRYPTABLE — covered below.)
|
|
assert.throws(() => encryptAssistantProviderToken("token-under-session"), (error) =>
|
|
error.message.includes("DASHBOARD_ASSISTANT_ENCRYPTION_SECRET")
|
|
);
|
|
// The curated error text is load-bearing: routes/dashboard-assistant.js
|
|
// classifies it as a user-facing 503 instead of a generic 500.
|
|
assert.throws(() => encryptAssistantProviderToken("token-under-session"), (error) =>
|
|
error.message.includes("encryption secret is unavailable")
|
|
);
|
|
});
|
|
});
|
|
|
|
test("minting fails closed with no secret material at all", () => {
|
|
withSecretEnv({}, () => {
|
|
assert.throws(() => encryptAssistantProviderToken("token"), (error) =>
|
|
error.message.includes("encryption secret is unavailable")
|
|
);
|
|
});
|
|
});
|
|
|
|
test("enc-v2 round-trip with the dedicated secret", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
const encrypted = encryptAssistantProviderToken(" sk-groq-test-key-123 ");
|
|
const parts = encrypted.split(":");
|
|
assert.strictEqual(parts[0], "enc-v2");
|
|
assert.strictEqual(parts.length, 5);
|
|
assert.strictEqual(Buffer.from(parts[1], "base64").length, 16, "per-value salt must be 16 bytes");
|
|
assert.strictEqual(decryptAssistantProviderToken(encrypted), "sk-groq-test-key-123");
|
|
});
|
|
});
|
|
|
|
test("encrypting mints a fresh salt and ciphertext every time", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
const first = encryptAssistantProviderToken("same-token");
|
|
const second = encryptAssistantProviderToken("same-token");
|
|
assert.notStrictEqual(first, second);
|
|
assert.notStrictEqual(first.split(":")[1], second.split(":")[1], "salt must be random per value");
|
|
assert.strictEqual(decryptAssistantProviderToken(first), "same-token");
|
|
assert.strictEqual(decryptAssistantProviderToken(second), "same-token");
|
|
});
|
|
});
|
|
|
|
test("SECRET_KEY alone can never mint a new enc-v2 value", () => {
|
|
withSecretEnv({ SECRET_KEY: "recaptcha-site-secret" }, () => {
|
|
assert.throws(() => encryptAssistantProviderToken("token"), (error) =>
|
|
error.message.includes("DASHBOARD_ASSISTANT_ENCRYPTION_SECRET")
|
|
);
|
|
});
|
|
});
|
|
|
|
test("legacy enc-v1 value decrypts under every legacy chain secret", () => {
|
|
withSecretEnv({ SESSION_SECRET: "old-session-secret" }, () => {
|
|
assert.strictEqual(decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "old-session-secret")), "legacy-groq-key");
|
|
});
|
|
|
|
withSecretEnv({ SECRET_KEY: "recaptcha-site-secret" }, () => {
|
|
assert.strictEqual(decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "recaptcha-site-secret")), "legacy-groq-key");
|
|
});
|
|
});
|
|
|
|
test("legacy enc-v1 value stays decryptable after the dedicated secret is added", () => {
|
|
const legacyValue = legacyEncryptV1("legacy-groq-key", "old-session-secret");
|
|
|
|
// The dedicated secret is tried first; the loop must fall through to the
|
|
// secret the value was actually minted under.
|
|
withSecretEnv(
|
|
{ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "new-dedicated-secret", SESSION_SECRET: "old-session-secret" },
|
|
() => {
|
|
assert.strictEqual(decryptAssistantProviderToken(legacyValue), "legacy-groq-key");
|
|
}
|
|
);
|
|
});
|
|
|
|
test("enc-v1 value minted under a lost secret fails authentication", () => {
|
|
const legacyValue = legacyEncryptV1("legacy-groq-key", "lost-secret");
|
|
withSecretEnv({ SESSION_SECRET: "different-secret" }, () => {
|
|
assert.throws(() => decryptAssistantProviderToken(legacyValue));
|
|
});
|
|
});
|
|
|
|
test("enc-v2 value minted under SESSION_SECRET still decrypts (legacy-decrypt-only candidate)", () => {
|
|
const sessionMinted = encryptV2With("session-minted-groq-key", "old-session-secret");
|
|
|
|
// Both secrets present: the dedicated candidate fails authentication and
|
|
// the chain must fall through to the secret the value was minted under.
|
|
withSecretEnv(
|
|
{ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret", SESSION_SECRET: "old-session-secret" },
|
|
() => {
|
|
assert.strictEqual(decryptAssistantProviderToken(sessionMinted), "session-minted-groq-key");
|
|
}
|
|
);
|
|
|
|
// Only the legacy mint key present (e.g. dedicated provisioning failed):
|
|
// the stored value must stay readable — decryption compatibility for
|
|
// existing values is non-negotiable.
|
|
withSecretEnv({ SESSION_SECRET: "old-session-secret" }, () => {
|
|
assert.strictEqual(decryptAssistantProviderToken(sessionMinted), "session-minted-groq-key");
|
|
});
|
|
});
|
|
|
|
test("unknown envelope version throws the format error", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
assert.throws(() => decryptAssistantProviderToken("enc-v9:aa:bb:cc"), /Invalid assistant provider token format/);
|
|
assert.throws(() => decryptAssistantProviderToken("not-a-token"), /Invalid assistant provider token format/);
|
|
});
|
|
});
|
|
|
|
test("corrupted auth tag fails cleanly without poisoning the original", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
const encrypted = encryptAssistantProviderToken("some-provider-key");
|
|
const parts = encrypted.split(":");
|
|
const tag = Buffer.from(parts[3], "base64");
|
|
tag[0] ^= 0xff;
|
|
parts[3] = tag.toString("base64");
|
|
assert.throws(() => decryptAssistantProviderToken(parts.join(":")));
|
|
assert.strictEqual(decryptAssistantProviderToken(encrypted), "some-provider-key");
|
|
});
|
|
});
|
|
|
|
test("empty and blank payloads stay no-ops", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
assert.strictEqual(encryptAssistantProviderToken(""), "");
|
|
assert.strictEqual(decryptAssistantProviderToken(""), "");
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// enc-v1 → enc-v2 startup migration (migrateAssistantProviderSecretsV1ToV2).
|
|
//
|
|
// These tests MUST stay after the ones above and in this relative order: the
|
|
// retirement flag is module-wide, the migration tests flip it, and every test
|
|
// that still needs SECRET_KEY as an enc-v1 decryption candidate runs first.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const PROVIDER_ENCRYPTED_ENV_KEYS = [
|
|
"DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED",
|
|
"DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED",
|
|
// Quarantine slots: the migration's process.env mirror writes these when a
|
|
// run quarantines an undecryptable value, so they must be saved/restored
|
|
// like the live slots to keep mirrored state from leaking across tests.
|
|
"DASHBOARD_ASSISTANT_GROQ_API_KEY_ORPHANED_V1",
|
|
"DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ORPHANED_V1",
|
|
];
|
|
|
|
// Saves/restores the *_ENCRYPTED slots (and their ORPHANED_V1 quarantine
|
|
// counterparts) so the migration's process.env mirror never leaks mirrored
|
|
// values into other tests.
|
|
function withProviderEnv(overrides, fn) {
|
|
const saved = new Map(PROVIDER_ENCRYPTED_ENV_KEYS.map((key) => [key, process.env[key]]));
|
|
try {
|
|
for (const key of PROVIDER_ENCRYPTED_ENV_KEYS) delete process.env[key];
|
|
for (const [key, value] of Object.entries(overrides)) {
|
|
process.env[key] = value;
|
|
}
|
|
return fn();
|
|
} finally {
|
|
for (const key of PROVIDER_ENCRYPTED_ENV_KEYS) {
|
|
const previous = saved.get(key);
|
|
if (previous === undefined) delete process.env[key];
|
|
else process.env[key] = previous;
|
|
}
|
|
}
|
|
}
|
|
|
|
// In-memory stand-in for .env plus the readEnvFile/writeEnvFileBatch deps,
|
|
// recording every batch write the migration performs.
|
|
function createEnvDeps(initialEnv) {
|
|
const env = { ...initialEnv };
|
|
const writes = [];
|
|
return {
|
|
env,
|
|
writes,
|
|
deps: {
|
|
readEnvFile: () => ({ ...env }),
|
|
writeEnvFileBatch: (updates) => {
|
|
writes.push(updates);
|
|
Object.assign(env, updates);
|
|
return true;
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
// Captures console.warn AND console.log so tests can assert the migration is
|
|
// chatty about outcomes without ever leaking secret material.
|
|
function captureConsole(fn) {
|
|
const lines = [];
|
|
const originalWarn = console.warn;
|
|
const originalLog = console.log;
|
|
console.warn = (...args) => { lines.push(args.join(" ")); };
|
|
console.log = (...args) => { lines.push(args.join(" ")); };
|
|
try {
|
|
return { result: fn(), lines };
|
|
} finally {
|
|
console.warn = originalWarn;
|
|
console.log = originalLog;
|
|
}
|
|
}
|
|
|
|
// A readEnvFile that resolves to {} is ambiguous: the real one swallows read
|
|
// errors into {}, indistinguishable from a genuinely empty .env. An
|
|
// empty-looking env must therefore NOT confirm retirement — the full legacy
|
|
// chain (SECRET_KEY included) stays for this boot and a later boot that reads
|
|
// real .env content re-confirms it.
|
|
test("an empty-looking .env (e.g. a swallowed read error) keeps SECRET_KEY in the enc-v1 chain", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
// readEnvFile returning {} is exactly what the real dependency does
|
|
// when the .env read fails, so the migration cannot treat it as proof
|
|
// that no enc-v1 value exists.
|
|
const { writes, deps } = createEnvDeps({});
|
|
|
|
const outcome = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps)).result;
|
|
|
|
assert.deepStrictEqual(outcome, { retired: false, migrated: 0 });
|
|
assert.strictEqual(writes.length, 0, "an untrusted empty read must not touch .env");
|
|
|
|
// Retirement was NOT confirmed: a value keyed ONLY under SECRET_KEY
|
|
// still decrypts, so a transient read failure cannot strand enc-v1
|
|
// values for the rest of the process.
|
|
withSecretEnv({ SECRET_KEY: "recaptcha-site-secret" }, () => {
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "recaptcha-site-secret")),
|
|
"legacy-groq-key"
|
|
);
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
test("migration leaves an undecryptable enc-v1 value untouched and does not retire", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const lostValue = legacyEncryptV1("lost-groq-key", "lost-secret");
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: lostValue,
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: legacyEncryptV1("legacy-google-key", "dedicated-secret"),
|
|
});
|
|
|
|
const outcome = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps)).result;
|
|
|
|
// The undecryptable entry keeps its old value and blocks retirement...
|
|
assert.deepStrictEqual(outcome, { retired: false, migrated: 1 });
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED, lostValue);
|
|
// ...while the decryptable entry is still re-wrapped in the same run
|
|
// (batch contains only the changed entries).
|
|
assert.strictEqual(writes.length, 1);
|
|
assert.deepStrictEqual(Object.keys(writes[0]), ["DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED"]);
|
|
assert.strictEqual(decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED), "legacy-google-key");
|
|
|
|
// Retirement was NOT confirmed: the SECRET_KEY last resort still works.
|
|
withSecretEnv({ SECRET_KEY: "recaptcha-site-secret" }, () => {
|
|
assert.strictEqual(decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "recaptcha-site-secret")), "legacy-groq-key");
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
test("migration re-encrypts enc-v1 provider keys into a single enc-v2 batch", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: legacyEncryptV1("legacy-groq-key", "dedicated-secret"),
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: legacyEncryptV1("legacy-google-key", "dedicated-secret"),
|
|
});
|
|
|
|
const { result: outcome, lines } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
|
|
assert.deepStrictEqual(outcome, { retired: true, migrated: 2 });
|
|
assert.strictEqual(writes.length, 1, "both providers must migrate in a single batch write");
|
|
assert.deepStrictEqual(
|
|
Object.keys(writes[0]).sort(),
|
|
["DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED", "DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED"]
|
|
);
|
|
for (const [envKey, value] of Object.entries(writes[0])) {
|
|
const parts = value.split(":");
|
|
assert.strictEqual(parts[0], "enc-v2", `${envKey} must be re-wrapped as enc-v2`);
|
|
assert.strictEqual(parts.length, 5);
|
|
// saveProviderToken pattern: the fresh envelope is mirrored into
|
|
// process.env right after the batch write lands.
|
|
assert.strictEqual(process.env[envKey], value);
|
|
}
|
|
assert.strictEqual(decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED), "legacy-groq-key");
|
|
assert.strictEqual(decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED), "legacy-google-key");
|
|
|
|
assert.ok(
|
|
lines.some((line) => line.includes("re-encrypted 2 provider API key(s) as enc-v2 under DASHBOARD_ASSISTANT_ENCRYPTION_SECRET")),
|
|
"migration must log one concise outcome line"
|
|
);
|
|
assert.ok(
|
|
lines.every((line) => !line.includes("legacy-groq-key") && !line.includes("legacy-google-key")),
|
|
"migration logs must never contain plaintext key material"
|
|
);
|
|
})
|
|
);
|
|
});
|
|
|
|
test("confirmed retirement drops SECRET_KEY from the enc-v1 decryption chain", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
// Confirm retirement from a .env that holds no enc-v1 values: no write
|
|
// may happen at all (the mtime is a cross-worker invalidation signal).
|
|
const { writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: encryptAssistantProviderToken("already-enc-v2"),
|
|
});
|
|
const outcome = migrateAssistantProviderSecretsV1ToV2(deps);
|
|
assert.deepStrictEqual(outcome, { retired: true, migrated: 0 });
|
|
assert.strictEqual(writes.length, 0, "retirement confirmation must not touch .env");
|
|
|
|
// A value keyed ONLY under the reCAPTCHA secret no longer decrypts...
|
|
withSecretEnv({ SECRET_KEY: "recaptcha-site-secret" }, () => {
|
|
assert.throws(() => decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "recaptcha-site-secret")));
|
|
});
|
|
// ...while the secrets enc-v1 legitimately used keep working.
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "dedicated-secret")),
|
|
"legacy-groq-key"
|
|
);
|
|
});
|
|
withSecretEnv({ SESSION_SECRET: "old-session-secret" }, () => {
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(legacyEncryptV1("legacy-groq-key", "old-session-secret")),
|
|
"legacy-groq-key"
|
|
);
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
test("a second migration run performs no .env write", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: legacyEncryptV1("legacy-groq-key", "dedicated-secret"),
|
|
});
|
|
|
|
// captureConsole keeps the success log line out of the TAP output;
|
|
// assertions are unchanged.
|
|
const { result: first } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
assert.deepStrictEqual(first, { retired: true, migrated: 1 });
|
|
assert.strictEqual(writes.length, 1);
|
|
const migratedValue = env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED;
|
|
|
|
const { result: second } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
assert.deepStrictEqual(second, { retired: true, migrated: 0 });
|
|
assert.strictEqual(writes.length, 1, "the second run must not write .env again");
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED, migratedValue);
|
|
})
|
|
);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Verified batch write (lost-update guard).
|
|
//
|
|
// index.js wires a writeEnvFileBatchVerified dep for the migration: inside
|
|
// the .env lock it re-reads .env and refuses the WHOLE batch unless every
|
|
// pre-read original is still current, so the migration's read → decrypt →
|
|
// re-encrypt → write cycle cannot silently revert a key an admin saved on
|
|
// another worker in between. These tests run after the ones above and keep
|
|
// the file's ordering discipline (retirement-positive or retirement-neutral
|
|
// outcomes only).
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Like createEnvDeps, but the fake deps also expose writeEnvFileBatchVerified.
|
|
// Unless verifiedResult === false (simulating a concurrent modification the
|
|
// writer refuses), it applies the batch to the in-memory env like the plain
|
|
// writer would, and it records every call — the updates plus the
|
|
// expectedOriginals it was handed — for the assertions below. `writes` keeps
|
|
// recording ONLY plain writeEnvFileBatch calls, so tests can assert the
|
|
// migration never falls back to it when the verified writer exists.
|
|
function createVerifiedEnvDeps(initialEnv, verifiedResult) {
|
|
const base = createEnvDeps(initialEnv);
|
|
const verifiedCalls = [];
|
|
base.verifiedCalls = verifiedCalls;
|
|
base.deps.writeEnvFileBatchVerified = (updates, expectedOriginals) => {
|
|
verifiedCalls.push({ updates, expectedOriginals });
|
|
if (verifiedResult === false) return false;
|
|
Object.assign(base.env, updates);
|
|
return true;
|
|
};
|
|
return base;
|
|
}
|
|
|
|
test("migration writes through the verified batch writer with the exact pre-read originals", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const groqV1 = legacyEncryptV1("legacy-groq-key", "dedicated-secret");
|
|
const googleV1 = legacyEncryptV1("legacy-google-key", "dedicated-secret");
|
|
const { env, writes, verifiedCalls, deps } = createVerifiedEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: groqV1,
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: googleV1,
|
|
});
|
|
|
|
// captureConsole keeps the success log line out of the TAP output;
|
|
// assertions are unchanged.
|
|
const { result: outcome } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
|
|
assert.deepStrictEqual(outcome, { retired: true, migrated: 2 });
|
|
assert.strictEqual(verifiedCalls.length, 1, "the migration must prefer the verified writer");
|
|
// expectedOriginals must carry the EXACT encrypted values the fake
|
|
// readEnvFile returned: they are what the verified writer re-checks
|
|
// under the .env lock before applying the batch.
|
|
assert.deepStrictEqual(verifiedCalls[0].expectedOriginals, {
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: groqV1,
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: googleV1,
|
|
});
|
|
assert.deepStrictEqual(
|
|
Object.keys(verifiedCalls[0].updates).sort(),
|
|
["DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED", "DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED"]
|
|
);
|
|
assert.strictEqual(writes.length, 0, "the plain writeEnvFileBatch must not be called when the verified writer exists");
|
|
// The verified writer applied the batch: both values decrypt back to
|
|
// their original tokens under the dedicated secret.
|
|
assert.strictEqual(decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED), "legacy-groq-key");
|
|
assert.strictEqual(decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED), "legacy-google-key");
|
|
})
|
|
);
|
|
});
|
|
|
|
test("a refused verified write aborts the migration without mirroring or retiring", () => {
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const groqV1 = legacyEncryptV1("legacy-groq-key", "dedicated-secret");
|
|
const { env, writes, verifiedCalls, deps } = createVerifiedEnvDeps(
|
|
{ DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: groqV1 },
|
|
false // simulated concurrent modification: the verified writer refuses
|
|
);
|
|
|
|
const { result: outcome, lines } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
|
|
// The refusal takes the exact same abort path as a failed plain write.
|
|
assert.deepStrictEqual(outcome, { retired: false, migrated: 0 });
|
|
assert.strictEqual(verifiedCalls.length, 1);
|
|
assert.strictEqual(writes.length, 0, "a refused verified write must not fall back to the plain writer");
|
|
// The abort path mirrors nothing into process.env.
|
|
assert.strictEqual(process.env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED, undefined);
|
|
// The old enc-v1 value is left untouched in .env ...
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED, groqV1);
|
|
// ... the existing abort warning is logged ...
|
|
assert.ok(
|
|
lines.some((line) => line.includes("enc-v1 migration aborted: .env update failed")),
|
|
"the refusal must log the existing abort warning"
|
|
);
|
|
// ... and retirement stays unconfirmed: the untouched value still
|
|
// decrypts through the legacy chain.
|
|
assert.strictEqual(decryptAssistantProviderToken(groqV1), "legacy-groq-key");
|
|
})
|
|
);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Widened migration scope: re-wrapping enc-v2 values that were minted under
|
|
// the deprecated SESSION_SECRET fallback (dedicated secret unset at the
|
|
// time) into fresh enc-v2 under the dedicated secret. These tests run after
|
|
// the retirement flag has been flipped by the tests above; every outcome
|
|
// asserted here is retirement-positive or retirement-neutral, so that
|
|
// ordering stays safe.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test("migration re-wraps a SESSION_SECRET-minted enc-v2 value under the dedicated secret", () => {
|
|
withSecretEnv(
|
|
{ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret", SESSION_SECRET: "old-session-secret" },
|
|
() =>
|
|
withProviderEnv({}, () => {
|
|
const sessionMinted = encryptV2With("session-minted-groq-key", "old-session-secret");
|
|
const dedicatedMinted = encryptAssistantProviderToken("already-dedicated-google-key");
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: sessionMinted,
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: dedicatedMinted,
|
|
});
|
|
|
|
// captureConsole keeps the success log line out of the TAP output;
|
|
// assertions are unchanged.
|
|
const { result: outcome } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
|
|
// Only the legacy-minted value is rewritten; the value already keyed
|
|
// under the dedicated secret stays byte-for-byte alone (no salt
|
|
// churn, no needless .env mtime bump).
|
|
assert.deepStrictEqual(outcome, { retired: true, migrated: 1 });
|
|
assert.strictEqual(writes.length, 1);
|
|
assert.deepStrictEqual(Object.keys(writes[0]), ["DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED"]);
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED, dedicatedMinted);
|
|
|
|
const rewrapped = env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED;
|
|
assert.notStrictEqual(rewrapped, sessionMinted, "the re-wrap must mint a fresh envelope");
|
|
assert.strictEqual(rewrapped.split(":")[0], "enc-v2");
|
|
assert.notStrictEqual(
|
|
rewrapped.split(":")[1],
|
|
sessionMinted.split(":")[1],
|
|
"the re-wrap must derive a fresh random salt"
|
|
);
|
|
// Keyed ONLY under the dedicated secret now: it must decrypt with the
|
|
// dedicated secret alone ...
|
|
withSecretEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, () => {
|
|
assert.strictEqual(decryptAssistantProviderToken(rewrapped), "session-minted-groq-key");
|
|
});
|
|
// ... and no longer under the SESSION_SECRET it was minted with.
|
|
withSecretEnv({ SESSION_SECRET: "old-session-secret" }, () => {
|
|
assert.throws(() => decryptAssistantProviderToken(rewrapped));
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
test("migration leaves an undecryptable enc-v2 value untouched without blocking retirement", () => {
|
|
withSecretEnv(
|
|
{ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret", SESSION_SECRET: "old-session-secret" },
|
|
() =>
|
|
withProviderEnv({}, () => {
|
|
const orphaned = encryptV2With("lost-google-key", "lost-secret");
|
|
const sessionMinted = encryptV2With("session-minted-groq-key", "old-session-secret");
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: sessionMinted,
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: orphaned,
|
|
});
|
|
|
|
// captureConsole keeps the success log line out of the TAP output;
|
|
// assertions are unchanged.
|
|
const { result: outcome } = captureConsole(() => migrateAssistantProviderSecretsV1ToV2(deps));
|
|
|
|
// The orphan keeps its old value and does NOT gate the flip: it is an
|
|
// enc-v2 value, so SECRET_KEY was never a decryption candidate for it.
|
|
assert.deepStrictEqual(outcome, { retired: true, migrated: 1 });
|
|
assert.strictEqual(writes.length, 1);
|
|
assert.deepStrictEqual(Object.keys(writes[0]), ["DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED"]);
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED, orphaned);
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED),
|
|
"session-minted-groq-key"
|
|
);
|
|
})
|
|
);
|
|
});
|
|
|
|
test("migration without the dedicated secret leaves enc-v2 values untouched", () => {
|
|
withSecretEnv({ SESSION_SECRET: "old-session-secret" }, () =>
|
|
withProviderEnv({}, () => {
|
|
const sessionMinted = encryptV2With("session-minted-groq-key", "old-session-secret");
|
|
const { env, writes, deps } = createEnvDeps({
|
|
DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED: sessionMinted,
|
|
});
|
|
|
|
const outcome = migrateAssistantProviderSecretsV1ToV2(deps);
|
|
|
|
// Nothing can be re-wrapped without a dedicated target secret, and a
|
|
// run that changes nothing must not touch .env — the next boot (with
|
|
// the secret auto-provisioned by index.js) retries the re-wrap.
|
|
assert.strictEqual(outcome.migrated, 0);
|
|
assert.strictEqual(writes.length, 0);
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED, sessionMinted);
|
|
// The value is still readable through the legacy decrypt candidate.
|
|
assert.strictEqual(decryptAssistantProviderToken(sessionMinted), "session-minted-groq-key");
|
|
})
|
|
);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// saveProviderToken legacy-plaintext purge (at-rest hygiene).
|
|
//
|
|
// A save that mints a fresh enc-v2 envelope must purge the provider's
|
|
// assistant-owned legacy .env keys (null = "delete the line" per
|
|
// writeEnvFileBatch) in the SAME batch — but never the keys co-owned by the
|
|
// /api/ai/keys provider-settings feature (GROQ_API_KEY, GOOGLE_AI_KEY).
|
|
// These tests MUST stay after the migration ones: constructing a service
|
|
// schedules the enc-v1 migration via setImmediate, which flips the
|
|
// module-wide retirement flag.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const SAVE_PROVIDER_ENV_KEYS = [
|
|
"DASHBOARD_ASSISTANT_PROVIDER",
|
|
"DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED",
|
|
"DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED",
|
|
"GROQ_API_KEY",
|
|
"GOOGLE_AI_STUDIO_API_KEY",
|
|
"GOOGLE_AI_KEY",
|
|
];
|
|
|
|
// Async-aware env guard: saveProviderToken is async and the assertions
|
|
// decrypt a captured envelope, so the overrides (including the encryption
|
|
// secret) must hold until fn settles — unlike the sync helpers above.
|
|
async function withSaveProviderEnv(overrides, fn) {
|
|
const keys = [...SECRET_ENV_KEYS, ...PROVIDER_ENCRYPTED_ENV_KEYS, ...SAVE_PROVIDER_ENV_KEYS];
|
|
const saved = new Map(keys.map((key) => [key, process.env[key]]));
|
|
try {
|
|
for (const key of keys) delete process.env[key];
|
|
for (const [key, value] of Object.entries(overrides)) {
|
|
process.env[key] = value;
|
|
}
|
|
return await fn();
|
|
} finally {
|
|
for (const key of keys) {
|
|
const previous = saved.get(key);
|
|
if (previous === undefined) delete process.env[key];
|
|
else process.env[key] = previous;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fresh service per test (its provider-secret cache is per-instance) plus an
|
|
// in-memory .env stand-in whose writeEnvFileBatch applies the real null =
|
|
// delete-line semantics and records every batch.
|
|
function createSaveProviderDeps(initialEnv) {
|
|
const env = { ...initialEnv };
|
|
const writes = [];
|
|
return {
|
|
env,
|
|
writes,
|
|
service: createDashboardAssistantService({
|
|
readEnvFile: () => ({ ...env }),
|
|
writeEnvFileBatch: (updates) => {
|
|
writes.push(updates);
|
|
for (const [key, value] of Object.entries(updates)) {
|
|
if (value === null) delete env[key];
|
|
else env[key] = value;
|
|
}
|
|
return true;
|
|
},
|
|
}),
|
|
};
|
|
}
|
|
|
|
test("saving a fresh Google key purges only the assistant-owned legacy key, in the same batch", async () => {
|
|
await withSaveProviderEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, async () => {
|
|
const { env, writes, service } = createSaveProviderDeps({
|
|
GROQ_API_KEY: "legacy-groq-plaintext",
|
|
GOOGLE_AI_STUDIO_API_KEY: "legacy-google-plaintext",
|
|
GOOGLE_AI_KEY: "shared-google-plaintext",
|
|
});
|
|
|
|
const token = "AIza-google-test-key-0123456789abcdef";
|
|
const outcome = await service.saveProviderToken({ provider: "google", token });
|
|
|
|
assert.strictEqual(writes.length, 1, "the purge must ride in the same single batch as the encrypted write");
|
|
const batch = writes[0];
|
|
assert.strictEqual(batch.DASHBOARD_ASSISTANT_PROVIDER, "google");
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(batch.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED),
|
|
token
|
|
);
|
|
assert.strictEqual(
|
|
batch.GOOGLE_AI_STUDIO_API_KEY,
|
|
null,
|
|
"the assistant-owned legacy key must be purged via a null (delete) entry"
|
|
);
|
|
assert.ok(!("GROQ_API_KEY" in batch), "co-owned GROQ_API_KEY must never appear (let alone null) in the batch");
|
|
assert.ok(!("GOOGLE_AI_KEY" in batch), "co-owned GOOGLE_AI_KEY must never appear (let alone null) in the batch");
|
|
|
|
// Simulated .env after the batch: the assistant-owned line is gone while
|
|
// both co-owned plaintext keys survive for the /api/ai/keys feature.
|
|
assert.strictEqual(env.GOOGLE_AI_STUDIO_API_KEY, undefined);
|
|
assert.strictEqual(env.GROQ_API_KEY, "legacy-groq-plaintext");
|
|
assert.strictEqual(env.GOOGLE_AI_KEY, "shared-google-plaintext");
|
|
|
|
assert.strictEqual(outcome.provider, "google");
|
|
assert.strictEqual(outcome.configured, true);
|
|
});
|
|
});
|
|
|
|
test("saving a fresh Groq key purges nothing (GROQ_API_KEY is co-owned by /api/ai/keys)", async () => {
|
|
await withSaveProviderEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, async () => {
|
|
const { env, writes, service } = createSaveProviderDeps({
|
|
GROQ_API_KEY: "legacy-groq-plaintext",
|
|
});
|
|
|
|
await service.saveProviderToken({ provider: "groq", token: "gsk-groq-test-key-0123456789abcdef" });
|
|
|
|
assert.strictEqual(writes.length, 1);
|
|
assert.deepStrictEqual(
|
|
Object.keys(writes[0]).sort(),
|
|
["DASHBOARD_ASSISTANT_GROQ_API_KEY_ENCRYPTED", "DASHBOARD_ASSISTANT_PROVIDER"],
|
|
"groq has an empty legacyPurgeable list: no null entries may ride in the batch"
|
|
);
|
|
assert.strictEqual(env.GROQ_API_KEY, "legacy-groq-plaintext", "the co-owned key must stay in .env");
|
|
});
|
|
});
|
|
|
|
test("an empty-token save keeps the stored key and purges nothing", async () => {
|
|
await withSaveProviderEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, async () => {
|
|
const storedEncrypted = encryptAssistantProviderToken("stored-google-key");
|
|
const { env, writes, service } = createSaveProviderDeps({
|
|
DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED: storedEncrypted,
|
|
GOOGLE_AI_STUDIO_API_KEY: "legacy-google-plaintext",
|
|
GOOGLE_AI_KEY: "shared-google-plaintext",
|
|
});
|
|
|
|
const outcome = await service.saveProviderToken({ provider: "google", token: "" });
|
|
|
|
// "Keep stored key" mints no fresh envelope, so the batch must contain
|
|
// only the provider preference — no purge, no encrypted rewrite.
|
|
assert.strictEqual(writes.length, 1);
|
|
assert.deepStrictEqual(writes[0], { DASHBOARD_ASSISTANT_PROVIDER: "google" });
|
|
assert.strictEqual(env.GOOGLE_AI_STUDIO_API_KEY, "legacy-google-plaintext");
|
|
assert.strictEqual(env.GOOGLE_AI_KEY, "shared-google-plaintext");
|
|
assert.strictEqual(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED, storedEncrypted);
|
|
assert.strictEqual(outcome.configured, true);
|
|
});
|
|
});
|
|
|
|
test("a failing round-trip verification skips the purge but still saves the encrypted key", async () => {
|
|
await withSaveProviderEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, async () => {
|
|
const { env, writes, service } = createSaveProviderDeps({
|
|
GOOGLE_AI_STUDIO_API_KEY: "legacy-google-plaintext",
|
|
});
|
|
|
|
const token = "AIza-google-test-key-0123456789abcdef";
|
|
// Force the round-trip verification to fail for real: enc-v2 decryption
|
|
// goes through crypto.createDecipheriv, so a throwing stub breaks the
|
|
// verify step while encryption (createCipheriv) keeps working.
|
|
const realCreateDecipheriv = crypto.createDecipheriv;
|
|
let outcome;
|
|
try {
|
|
crypto.createDecipheriv = () => {
|
|
throw new Error("simulated decipher failure");
|
|
};
|
|
outcome = await service.saveProviderToken({ provider: "google", token });
|
|
} finally {
|
|
crypto.createDecipheriv = realCreateDecipheriv;
|
|
}
|
|
|
|
assert.strictEqual(writes.length, 1, "the save itself must complete exactly as it did before the purge feature");
|
|
const batch = writes[0];
|
|
assert.strictEqual(batch.DASHBOARD_ASSISTANT_PROVIDER, "google");
|
|
assert.strictEqual(
|
|
typeof batch.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED,
|
|
"string",
|
|
"the encrypted write must still land"
|
|
);
|
|
assert.ok(
|
|
!("GOOGLE_AI_STUDIO_API_KEY" in batch),
|
|
"a failed verification must skip the purge silently (no null entry in the batch)"
|
|
);
|
|
assert.strictEqual(env.GOOGLE_AI_STUDIO_API_KEY, "legacy-google-plaintext");
|
|
|
|
// The saved envelope is still valid once decipher works again.
|
|
assert.strictEqual(decryptAssistantProviderToken(batch.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED), token);
|
|
assert.strictEqual(outcome.configured, true);
|
|
});
|
|
});
|
|
|
|
test("an empty-token save over a plaintext-only key re-wraps it and purges the legacy line", async () => {
|
|
await withSaveProviderEnv({ DASHBOARD_ASSISTANT_ENCRYPTION_SECRET: "dedicated-secret" }, async () => {
|
|
const storedPlaintext = "legacy-google-plaintext";
|
|
const { env, writes, service } = createSaveProviderDeps({
|
|
GOOGLE_AI_STUDIO_API_KEY: storedPlaintext,
|
|
});
|
|
|
|
const outcome = await service.saveProviderToken({ provider: "google", token: "" });
|
|
|
|
// No encrypted value exists yet, so the empty-token save mints a fresh
|
|
// envelope from the stored plaintext (and still purges the legacy line).
|
|
assert.strictEqual(writes.length, 1, "the purge must ride in the same single batch as the encrypted write");
|
|
const batch = writes[0];
|
|
assert.strictEqual(batch.DASHBOARD_ASSISTANT_PROVIDER, "google");
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(batch.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED),
|
|
storedPlaintext,
|
|
"the minted envelope must decrypt back to the stored plaintext (restart-recoverability)"
|
|
);
|
|
assert.strictEqual(
|
|
batch.GOOGLE_AI_STUDIO_API_KEY,
|
|
null,
|
|
"the assistant-owned legacy key must be purged via a null (delete) entry"
|
|
);
|
|
assert.ok(!("GROQ_API_KEY" in batch), "co-owned GROQ_API_KEY must never appear (let alone null) in the batch");
|
|
assert.ok(!("GOOGLE_AI_KEY" in batch), "co-owned GOOGLE_AI_KEY must never appear (let alone null) in the batch");
|
|
|
|
// Simulated .env after the batch: the plaintext line is gone, replaced by
|
|
// the envelope.
|
|
assert.strictEqual(env.GOOGLE_AI_STUDIO_API_KEY, undefined);
|
|
assert.strictEqual(
|
|
decryptAssistantProviderToken(env.DASHBOARD_ASSISTANT_GOOGLE_AI_API_KEY_ENCRYPTED),
|
|
storedPlaintext
|
|
);
|
|
assert.strictEqual(outcome.provider, "google");
|
|
assert.strictEqual(outcome.configured, true);
|
|
});
|
|
});
|