mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
feat(settings): set the Google Maps key through PLACES_API_KEY
The server already put PLACES_API_KEY ahead of the key saved in the admin panel, but nothing said so: the variable was in no template and the admin field kept showing a stored value that no search used. GET /me/settings now answers env_keys, the variable behind each key the environment sets (Google, Unsplash, Amap), and null for that key's value. The admin field turns read-only and names the variable, Test still probes the key a search resolves to, and a save leaves those names out so the stored fallback survives. The variable is documented in .env.example, docker-compose.yml, the Helm chart (as a secret) and the wiki. Addresses discussion #1881.
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
||||
readInstanceApiKey,
|
||||
writeInstanceApiKey,
|
||||
resolveApiKey,
|
||||
operatorKeyVariables,
|
||||
} from '../../../../src/nest/settings/instance-api-keys';
|
||||
|
||||
const db = new DatabaseService(testDb);
|
||||
@@ -137,3 +138,43 @@ describe('instance API keys', () => {
|
||||
expect(resolveApiKey(db, 'unsplash_api_key', user.id, undefined)).toEqual({ key: null, source: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('operatorKeyVariables (#1881)', () => {
|
||||
const VARS = ['PLACES_API_KEY', 'UNSPLASH_ACCESS_KEY', 'AMAP_API_KEY'] as const;
|
||||
const saved: Partial<Record<(typeof VARS)[number], string>> = {};
|
||||
beforeEach(() => {
|
||||
for (const v of VARS) {
|
||||
saved[v] = process.env[v];
|
||||
delete process.env[v];
|
||||
}
|
||||
});
|
||||
afterAll(() => {
|
||||
for (const v of VARS) {
|
||||
if (saved[v] === undefined) delete process.env[v];
|
||||
else process.env[v] = saved[v];
|
||||
}
|
||||
});
|
||||
|
||||
it('INSTKEY-010: names nothing while no variable is set', () => {
|
||||
expect(operatorKeyVariables()).toEqual({});
|
||||
});
|
||||
|
||||
it('INSTKEY-011: names the variable behind each key that has one, never its value', () => {
|
||||
process.env.PLACES_API_KEY = 'google-from-env';
|
||||
process.env.UNSPLASH_ACCESS_KEY = 'unsplash-from-env';
|
||||
process.env.AMAP_API_KEY = 'amap-from-env';
|
||||
const set = operatorKeyVariables();
|
||||
expect(set).toEqual({
|
||||
maps_api_key: 'PLACES_API_KEY',
|
||||
unsplash_api_key: 'UNSPLASH_ACCESS_KEY',
|
||||
amap_api_key: 'AMAP_API_KEY',
|
||||
});
|
||||
expect(JSON.stringify(set)).not.toContain('from-env');
|
||||
});
|
||||
|
||||
it('INSTKEY-012: a blank variable does not count as set', () => {
|
||||
process.env.PLACES_API_KEY = '';
|
||||
process.env.UNSPLASH_ACCESS_KEY = ' ';
|
||||
expect(operatorKeyVariables()).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user