Skip to content

Commit 4165af1

Browse files
committed
test(plugin-auth): store the Google client secret through a confidential adapter
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXhZcHuALPAjkDCiiT
1 parent 850f14e commit 4165af1

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎packages/plugins/plugin-auth/src/sign-in-method-floor.test.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import type { PluginContext } from '@objectstack/core';
3030
import type { IHttpRequest, IHttpResponse, IHttpServer, RouteHandler } from '@objectstack/spec/contracts';
3131
import { assertEngineFindOnePredicate, type EngineFindOneQueryInput } from '@objectstack/objectql';
3232
import {
33-
InMemoryCryptoProvider,
3433
SettingsService,
3534
SettingsValidationError,
3635
builtinSettingsManifests,
3736
registerSettingsRoutes,
37+
type CryptoAdapter,
3838
} from '@objectstack/service-settings';
3939
import { AuthPlugin } from './auth-plugin.js';
4040
import type { AuthManager } from './auth-manager.js';
@@ -43,6 +43,20 @@ import { SIGN_IN_FLOOR_COPY } from './sign-in-method-floor.js';
4343

4444
const SECRET = 'test-secret-at-least-32-chars-long';
4545

46+
/** Declares confidentiality, so the settings service stores the Google client secret. */
47+
class ConfidentialTestAdapter implements CryptoAdapter {
48+
readonly confidential = true;
49+
async encrypt(plaintext: string): Promise<string> {
50+
return 'kms:' + Buffer.from(plaintext, 'utf8').toString('base64');
51+
}
52+
async decrypt(ciphertext: string): Promise<string> {
53+
return Buffer.from(ciphertext.replace(/^kms:/, ''), 'base64').toString('utf8');
54+
}
55+
digest(): string {
56+
return 'fnv32:deadbeef';
57+
}
58+
}
59+
4660
const ENV_KEYS = [
4761
'OS_AUTH_EMAIL_PASSWORD_ENABLED',
4862
'OS_AUTH_GOOGLE_ENABLED',
@@ -98,8 +112,7 @@ describe('the auth settings save keeps a way to sign in', () => {
98112
});
99113

100114
const makeSettings = (env: Record<string, string | undefined> = {}) => {
101-
// A crypto provider, so the Google client secret can be stored.
102-
const settings = new SettingsService({ env, cryptoProvider: new InMemoryCryptoProvider() });
115+
const settings = new SettingsService({ env, crypto: new ConfidentialTestAdapter() });
103116
for (const manifest of builtinSettingsManifests) {
104117
if (manifest.namespace === 'auth') settings.registerManifest(manifest);
105118
}
@@ -298,6 +311,8 @@ describe('the auth settings save keeps a way to sign in', () => {
298311
await vi.waitFor(() => expect(passwordOn(alone.manager)).toBe(false));
299312
process.env.GOOGLE_CLIENT_SECRET = 'google-env-client-secret';
300313
await alone.settings.setMany('auth', { google_client_secret: null });
314+
expect(await alone.settings.get('auth', 'google_client_secret')).toMatchObject({ source: 'default' });
315+
await new Promise((resolve) => setTimeout(resolve, 10)); // the pass re-runs on the change
301316
expect(googleOn(alone.manager)).toBe(true);
302317
});
303318

0 commit comments

Comments
 (0)