@@ -92,20 +92,17 @@ describe("ClientAuthentication", () => {
9292 logoutHandler : mockLogoutHandler ( defaultMockStorage ) ,
9393 sessionInfoManager : mockSessionInfoManager ( defaultMockStorage ) ,
9494 issuerConfigFetcher : mockDefaultIssuerConfigFetcher ( ) ,
95- storage : defaultMockStorage ,
9695 } ;
9796
9897 function getClientAuthentication (
9998 mocks : Partial < typeof defaultMocks > = defaultMocks ,
10099 ) : ClientAuthentication {
101- const storage = mocks . storage ?? defaultMocks . storage ;
102100 return new ClientAuthentication (
103101 mocks . loginHandler ?? defaultMocks . loginHandler ,
104102 mocks . redirectHandler ?? defaultMocks . redirectHandler ,
105103 mocks . logoutHandler ?? defaultMocks . logoutHandler ,
106104 mocks . sessionInfoManager ?? defaultMocks . sessionInfoManager ,
107105 mocks . issuerConfigFetcher ?? defaultMocks . issuerConfigFetcher ,
108- storage ,
109106 ) ;
110107 }
111108
@@ -605,128 +602,36 @@ describe("ClientAuthentication", () => {
605602 } ) ;
606603 } ) ;
607604
608- describe ( "isClientExpired" , ( ) => {
609- it ( "returns true when a confidential client has an expired timestamp" , async ( ) => {
610- const sessionId = "mySession" ;
611- const expiredTimestamp = Math . floor ( Date . now ( ) / 1000 ) - 1000 ; // 1000 seconds ago
612- const mockedStorage = new StorageUtility (
613- mockStorage ( {
614- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
615- isLoggedIn : "true" ,
616- } ,
617- } ) ,
618- mockStorage ( {
619- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
620- clientId : "some-client-id" ,
621- clientSecret : "some-secret" ,
622- expiresAt : String ( expiredTimestamp ) ,
623- } ,
624- } ) ,
625- ) ;
626- const clientAuthn = getClientAuthentication ( {
627- sessionInfoManager : mockSessionInfoManager ( mockedStorage ) ,
628- storage : mockedStorage ,
629- } ) ;
630-
631- await expect ( clientAuthn . isClientExpired ( sessionId ) ) . resolves . toBe ( true ) ;
632- } ) ;
633-
634- it ( "returns false when a confidential client has a valid timestamp" , async ( ) => {
635- const sessionId = "mySession" ;
636- const futureTimestamp = Math . floor ( Date . now ( ) / 1000 ) + 10000 ; // 10000 seconds in future
637- const mockedStorage = new StorageUtility (
638- mockStorage ( {
639- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
640- isLoggedIn : "true" ,
641- } ,
642- } ) ,
643- mockStorage ( {
644- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
645- clientId : "some-client-id" ,
646- clientSecret : "some-secret" ,
647- expiresAt : String ( futureTimestamp ) ,
648- } ,
649- } ) ,
650- ) ;
651- const clientAuthn = getClientAuthentication ( {
652- sessionInfoManager : mockSessionInfoManager ( mockedStorage ) ,
653- storage : mockedStorage ,
654- } ) ;
655-
656- await expect ( clientAuthn . isClientExpired ( sessionId ) ) . resolves . toBe ( false ) ;
657- } ) ;
658-
659- it ( "returns false when a confidential client never expires (expiresAt = 0)" , async ( ) => {
605+ describe ( "validateCurrentSession" , ( ) => {
606+ it ( "returns clientExpiresAt when expiresAt is in storage" , async ( ) => {
660607 const sessionId = "mySession" ;
608+ const expiresAt = Math . floor ( Date . now ( ) / 1000 ) + 10000 ;
661609 const mockedStorage = new StorageUtility (
662610 mockStorage ( {
663611 [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
664612 isLoggedIn : "true" ,
613+ webId : "https://my.pod/profile#me" ,
665614 } ,
666615 } ) ,
667616 mockStorage ( {
668617 [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
669- clientId : "some-client-id " ,
618+ clientId : "https:// some.app/registration " ,
670619 clientSecret : "some-secret" ,
671- expiresAt : "0" ,
672- } ,
673- } ) ,
674- ) ;
675- const clientAuthn = getClientAuthentication ( {
676- sessionInfoManager : mockSessionInfoManager ( mockedStorage ) ,
677- storage : mockedStorage ,
678- } ) ;
679-
680- await expect ( clientAuthn . isClientExpired ( sessionId ) ) . resolves . toBe ( false ) ;
681- } ) ;
682-
683- it ( "returns false for public clients (no secret) regardless of expiration" , async ( ) => {
684- const sessionId = "mySession" ;
685- const expiredTimestamp = Math . floor ( Date . now ( ) / 1000 ) - 1000 ;
686- const mockedStorage = new StorageUtility (
687- mockStorage ( {
688- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
689- isLoggedIn : "true" ,
690- } ,
691- } ) ,
692- mockStorage ( {
693- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
694- clientId : "some-client-id" ,
695- // No clientSecret - public client
696- expiresAt : String ( expiredTimestamp ) ,
620+ issuer : "https://some.issuer" ,
621+ expiresAt : String ( expiresAt ) ,
697622 } ,
698623 } ) ,
699624 ) ;
700625 const clientAuthn = getClientAuthentication ( {
701626 sessionInfoManager : mockSessionInfoManager ( mockedStorage ) ,
702- storage : mockedStorage ,
703627 } ) ;
704628
705- await expect ( clientAuthn . isClientExpired ( sessionId ) ) . resolves . toBe ( false ) ;
706- } ) ;
707-
708- it ( "returns true for legacy clients with missing expiresAt (confidential)" , async ( ) => {
709- const sessionId = "mySession" ;
710- const mockedStorage = new StorageUtility (
711- mockStorage ( {
712- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
713- isLoggedIn : "true" ,
714- } ,
715- } ) ,
716- mockStorage ( {
717- [ `${ USER_SESSION_PREFIX } :${ sessionId } ` ] : {
718- clientId : "some-client-id" ,
719- clientSecret : "some-secret" ,
720- // No expiresAt - legacy case
721- } ,
629+ const result = await clientAuthn . validateCurrentSession ( sessionId ) ;
630+ expect ( result ) . toStrictEqual (
631+ expect . objectContaining ( {
632+ clientExpiresAt : expiresAt ,
722633 } ) ,
723634 ) ;
724- const clientAuthn = getClientAuthentication ( {
725- sessionInfoManager : mockSessionInfoManager ( mockedStorage ) ,
726- storage : mockedStorage ,
727- } ) ;
728-
729- await expect ( clientAuthn . isClientExpired ( sessionId ) ) . resolves . toBe ( true ) ;
730635 } ) ;
731636 } ) ;
732637} ) ;
0 commit comments