@@ -30,11 +30,11 @@ import type { PluginContext } from '@objectstack/core';
3030import type { IHttpRequest , IHttpResponse , IHttpServer , RouteHandler } from '@objectstack/spec/contracts' ;
3131import { assertEngineFindOnePredicate , type EngineFindOneQueryInput } from '@objectstack/objectql' ;
3232import {
33- InMemoryCryptoProvider ,
3433 SettingsService ,
3534 SettingsValidationError ,
3635 builtinSettingsManifests ,
3736 registerSettingsRoutes ,
37+ type CryptoAdapter ,
3838} from '@objectstack/service-settings' ;
3939import { AuthPlugin } from './auth-plugin.js' ;
4040import type { AuthManager } from './auth-manager.js' ;
@@ -43,6 +43,20 @@ import { SIGN_IN_FLOOR_COPY } from './sign-in-method-floor.js';
4343
4444const 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 ( / ^ k m s : / , '' ) , 'base64' ) . toString ( 'utf8' ) ;
54+ }
55+ digest ( ) : string {
56+ return 'fnv32:deadbeef' ;
57+ }
58+ }
59+
4660const 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