@@ -660,6 +660,75 @@ describe('a request whose auth context adapter is not the observed view is refus
660660 } ) ;
661661} ) ;
662662
663+ describe ( 'the discovery scope follows the composition: a kernel that does not mount SSO answers the vendor\'s 404 and logs nothing' , ( ) => {
664+ afterEach ( ( ) => {
665+ vi . unstubAllEnvs ( ) ;
666+ } ) ;
667+
668+ interface Kernel {
669+ manager : AuthManager ;
670+ logger : { warn : ReturnType < typeof vi . fn > ; error : ReturnType < typeof vi . fn > ; info : ReturnType < typeof vi . fn > } ;
671+ }
672+
673+ function kernel ( plugins : Record < string , unknown > ) : Kernel {
674+ const logger = { warn : vi . fn ( ) , error : vi . fn ( ) , info : vi . fn ( ) } ;
675+ const manager = new AuthManager ( {
676+ secret : SECRET ,
677+ baseUrl : BASE ,
678+ dataEngine : createMemoryEngine ( ) ,
679+ trustedOrigins : [ BASE ] ,
680+ plugins,
681+ logger,
682+ } as unknown as ConstructorParameters < typeof AuthManager > [ 0 ] ) ;
683+ return { manager, logger } ;
684+ }
685+
686+ const doors : ReadonlyArray < readonly [ path : string , request : ( ) => Request ] > = [
687+ [ 'POST /sso/register' , ( ) => new Request ( `${ AUTH } /sso/register` , {
688+ method : 'POST' ,
689+ headers : { 'content-type' : 'application/json' , origin : BASE } ,
690+ body : JSON . stringify ( registration ( 'unmounted-register' , 'https://idp.acme.example' ) ) ,
691+ } ) ] ,
692+ [ 'POST /sign-in/sso' , ( ) => new Request ( `${ AUTH } /sign-in/sso` , {
693+ method : 'POST' ,
694+ headers : { 'content-type' : 'application/json' , origin : BASE } ,
695+ body : JSON . stringify ( { providerId : 'unmounted-oidc' , callbackURL : `${ BASE } /after` } ) ,
696+ } ) ] ,
697+ [ 'GET /sso/callback/:providerId' , ( ) => new Request ( `${ AUTH } /sso/callback/unmounted-oidc?code=idp-code&state=any-state` ) ] ,
698+ ] ;
699+
700+ const compositions : ReadonlyArray < readonly [ name : string , plugins : Record < string , unknown > ] > = [
701+ [ 'plugins.sso false' , { sso : false } ] ,
702+ [ 'plugins.sso unset and OS_SSO_ENABLED unset (the default)' , { } ] ,
703+ ] ;
704+
705+ describe . each ( compositions ) ( '%s' , ( _name , plugins ) => {
706+ it . each ( doors ) ( '%s answers 404, and nothing is logged at error level' , async ( _door , request ) => {
707+ vi . stubEnv ( 'OS_SSO_ENABLED' , undefined ) ;
708+ const { manager, logger } = kernel ( plugins ) ;
709+ const res = await manager . handleRequest ( request ( ) ) ;
710+ expect ( res . status , await res . clone ( ) . text ( ) ) . toBe ( 404 ) ;
711+ expect ( logger . error ) . not . toHaveBeenCalled ( ) ;
712+ const lines = [ ...logger . warn . mock . calls , ...logger . info . mock . calls ] . map ( ( call ) => String ( call [ 0 ] ) ) ;
713+ expect ( lines . filter ( ( line ) => line . includes ( 'SSO request refused' ) ) ) . toEqual ( [ ] ) ;
714+ } ) ;
715+ } ) ;
716+
717+ it ( 'CONTROL: a kernel that mounted SSO keeps the scope when OS_SSO_ENABLED is unset after the build: an unobserved context adapter is still answered 503' , async ( ) => {
718+ vi . stubEnv ( 'OS_SSO_ENABLED' , 'true' ) ;
719+ const { manager, logger } = kernel ( { } ) ;
720+ const ctx = await ( ( await manager . getAuthInstance ( ) ) as any ) . $context ;
721+ // The configuration re-read at request time now says "no SSO"; the
722+ // composition that answers the request still mounts it.
723+ vi . stubEnv ( 'OS_SSO_ENABLED' , undefined ) ;
724+ ctx . adapter = { ...ctx . adapter } ;
725+ const res = await manager . handleRequest ( doors [ 0 ] ! [ 1 ] ( ) ) ;
726+ expect ( res . status , await res . clone ( ) . text ( ) ) . toBe ( 503 ) ;
727+ expect ( await res . json ( ) ) . toMatchObject ( { success : false , error : { code : 'SERVICE_UNAVAILABLE' } } ) ;
728+ expect ( logger . error ) . toHaveBeenCalledTimes ( 1 ) ;
729+ } ) ;
730+ } ) ;
731+
663732describe ( 'the SSO discovery scope judges only the reads it names' , ( ) => {
664733 /** A guard that answers every read itself, recording it. */
665734 function recordingGuard ( ) : { guard : EgressGuard ; sent : string [ ] } {
0 commit comments