mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-01 16:12:02 +00:00
fix: treat an empty PLUGIN_SIGNING_KEY_FILE as unset #996
This commit is contained in:
@@ -64,6 +64,18 @@ describe('plugin signing key storage', () => {
|
||||
await expect(getPublicKeyBase64()).resolves.toBe(expected.subarray(-32).toString('base64'));
|
||||
});
|
||||
|
||||
it('treats an empty PLUGIN_SIGNING_KEY_FILE as unset', async () => {
|
||||
const configDir = path.join(dir, 'config');
|
||||
const pem = privateKeyPem();
|
||||
await mkdir(configDir);
|
||||
await writeFile(path.join(configDir, 'plugin-signing.key'), pem);
|
||||
vi.stubEnv('PLUGIN_SIGNING_KEY_FILE', '');
|
||||
vi.stubEnv('ADMIN_CONFIG_DIR', configDir);
|
||||
|
||||
const expected = createPublicKey(pem).export({ type: 'spki', format: 'der' }) as Buffer;
|
||||
await expect(getPublicKeyBase64()).resolves.toBe(expected.subarray(-32).toString('base64'));
|
||||
});
|
||||
|
||||
it('keeps generating plugin-signing.key when external path is unset', async () => {
|
||||
const configDir = path.join(dir, 'config');
|
||||
vi.stubEnv('ADMIN_CONFIG_DIR', configDir);
|
||||
|
||||
@@ -47,8 +47,11 @@ async function loadExternal(path: string): Promise<{ privateKey: KeyObject; publ
|
||||
}
|
||||
|
||||
async function loadOrCreate(): Promise<{ privateKey: KeyObject; publicKey: KeyObject }> {
|
||||
const externalPath = process.env.PLUGIN_SIGNING_KEY_FILE;
|
||||
if (externalPath !== undefined) return loadExternal(externalPath);
|
||||
// An empty value (`PLUGIN_SIGNING_KEY_FILE=` in an env file) means unset,
|
||||
// like the other *_FILE variables. Reading '' fails, and a failed load
|
||||
// makes every bundle ship unsigned with only a console warning.
|
||||
const externalPath = process.env.PLUGIN_SIGNING_KEY_FILE?.trim();
|
||||
if (externalPath) return loadExternal(externalPath);
|
||||
|
||||
await ensureConfigDir();
|
||||
const path = getConfigPath(KEY_FILENAME);
|
||||
|
||||
Reference in New Issue
Block a user