@@ -43,7 +43,8 @@ describe('Identity Provider', () => {
4343 assert . strictEqual ( res . status , 200 ) ;
4444
4545 const config = await res . json ( ) ;
46- assert . strictEqual ( config . issuer , BASE_URL ) ;
46+ // Issuer has trailing slash for CTH compatibility
47+ assert . strictEqual ( config . issuer , BASE_URL + '/' ) ;
4748 assert . ok ( config . authorization_endpoint ) ;
4849 assert . ok ( config . token_endpoint ) ;
4950 assert . ok ( config . jwks_uri ) ;
@@ -259,25 +260,24 @@ describe('Identity Provider - Accounts', () => {
259260
260261describe ( 'Identity Provider - Credentials Endpoint' , ( ) => {
261262 let server ;
262- const CREDS_DATA_DIR = './test-data-idp-creds' ;
263+ // Use same data dir as other tests (DATA_ROOT is cached at module load)
264+ const CREDS_DATA_DIR = './data' ;
263265 const CREDS_PORT = 3101 ;
264266 const CREDS_URL = `http://${ TEST_HOST } :${ CREDS_PORT } ` ;
265267
266268 before ( async ( ) => {
267- await fs . remove ( CREDS_DATA_DIR ) ;
268- await fs . ensureDir ( CREDS_DATA_DIR ) ;
269+ await fs . emptyDir ( CREDS_DATA_DIR ) ;
269270
270271 server = createServer ( {
271272 logger : false ,
272- root : CREDS_DATA_DIR ,
273273 idp : true ,
274274 idpIssuer : CREDS_URL ,
275275 } ) ;
276276
277277 await server . listen ( { port : CREDS_PORT , host : TEST_HOST } ) ;
278278
279279 // Create a test user
280- await fetch ( `${ CREDS_URL } /.pods` , {
280+ const res = await fetch ( `${ CREDS_URL } /.pods` , {
281281 method : 'POST' ,
282282 headers : { 'Content-Type' : 'application/json' } ,
283283 body : JSON . stringify ( {
@@ -286,11 +286,14 @@ describe('Identity Provider - Credentials Endpoint', () => {
286286 password : 'testpassword123' ,
287287 } ) ,
288288 } ) ;
289+ if ( ! res . ok ) {
290+ throw new Error ( `Failed to create test user: ${ res . status } ${ await res . text ( ) } ` ) ;
291+ }
289292 } ) ;
290293
291294 after ( async ( ) => {
292295 await server . close ( ) ;
293- await fs . remove ( CREDS_DATA_DIR ) ;
296+ await fs . emptyDir ( CREDS_DATA_DIR ) ;
294297 } ) ;
295298
296299 describe ( 'GET /idp/credentials' , ( ) => {
@@ -366,7 +369,7 @@ describe('Identity Provider - Credentials Endpoint', () => {
366369 assert . ok ( body . webid . includes ( 'credtest' ) , 'should have webid' ) ;
367370 } ) ;
368371
369- it ( 'should return simple token with webid for Bearer auth ' , async ( ) => {
372+ it ( 'should return JWT token with webid claim ' , async ( ) => {
370373 const res = await fetch ( `${ CREDS_URL } /idp/credentials` , {
371374 method : 'POST' ,
372375 headers : { 'Content-Type' : 'application/json' } ,
@@ -378,15 +381,15 @@ describe('Identity Provider - Credentials Endpoint', () => {
378381
379382 const body = await res . json ( ) ;
380383
381- // Simple tokens have format: base64payload .signature
384+ // JWT tokens have format: header.payload .signature
382385 const parts = body . access_token . split ( '.' ) ;
383- assert . strictEqual ( parts . length , 2 , 'simple token has 2 parts' ) ;
386+ assert . strictEqual ( parts . length , 3 , 'JWT token has 3 parts' ) ;
384387
385- // Decode the payload
386- const payload = JSON . parse ( Buffer . from ( parts [ 0 ] , 'base64url' ) . toString ( ) ) ;
388+ // Decode the payload (second part)
389+ const payload = JSON . parse ( Buffer . from ( parts [ 1 ] , 'base64url' ) . toString ( ) ) ;
387390
388- assert . ok ( payload . webId , 'token should have webId ' ) ;
389- assert . ok ( payload . webId . includes ( 'credtest' ) , 'webId should reference user' ) ;
391+ assert . ok ( payload . webid , 'token should have webid claim ' ) ;
392+ assert . ok ( payload . webid . includes ( 'credtest' ) , 'webid should reference user' ) ;
390393 assert . ok ( payload . exp > payload . iat , 'should have valid expiry' ) ;
391394 } ) ;
392395
0 commit comments