@@ -390,7 +390,7 @@ describe('DataGenerator', () => {
390390 ` ) ;
391391 } ) ;
392392
393- it ( 'renders OIDC auth mode' , async ( ) => {
393+ it ( 'renders OIDC auth mode with TTL converted from milliseconds to seconds ' , async ( ) => {
394394 const gen1App = await createGen1App ( {
395395 providers : { awscloudformation : { StackName : 'amplify-test-main-123456' , Region : 'us-east-1' } } ,
396396 api : {
@@ -412,8 +412,8 @@ describe('DataGenerator', () => {
412412 name : 'MyOIDC' ,
413413 issuerUrl : 'https://example.com' ,
414414 clientId : 'client123' ,
415- authTTL : 3600 ,
416- iatTTL : 7200 ,
415+ authTTL : 3600000 ,
416+ iatTTL : 7200000 ,
417417 } ,
418418 } ,
419419 ] ,
@@ -459,6 +459,93 @@ describe('DataGenerator', () => {
459459 ` ) ;
460460 } ) ;
461461
462+ it ( 'renders OIDC auth mode without clientId when absent and supplements from live API' , async ( ) => {
463+ const gen1App = await createGen1App ( {
464+ providers : { awscloudformation : { StackName : 'amplify-test-main-123456' , Region : 'us-east-1' } } ,
465+ api : {
466+ testApi : {
467+ service : 'AppSync' ,
468+ output : { GraphQLAPIIdOutput : 'api-123' } ,
469+ } ,
470+ } ,
471+ } ) ;
472+ mockSchema ( gen1App , 'type Todo @model { id: ID! }' , [ 'Todo' ] ) ;
473+ jest . spyOn ( gen1App , 'resourceMetaOutput' ) . mockImplementation ( ( _resource : DiscoveredResource , key : string ) => {
474+ if ( key === 'GraphQLAPIIdOutput' ) return 'api-123' ;
475+ if ( key === 'authConfig' )
476+ return {
477+ defaultAuthentication : {
478+ authenticationType : 'OPENID_CONNECT' ,
479+ openIDConnectConfig : {
480+ name : 'NoClientIdProvider' ,
481+ issuerUrl : 'https://idp.example.com' ,
482+ authTTL : 1800000 ,
483+ iatTTL : 3600000 ,
484+ } ,
485+ } ,
486+ } as any ;
487+ return undefined as any ;
488+ } ) ;
489+ jest . spyOn ( gen1App . aws , 'fetchGraphqlApi' ) . mockResolvedValue ( {
490+ apiId : 'api-123' ,
491+ name : 'testApi' ,
492+ openIDConnectConfig : { issuer : 'https://idp.example.com' , clientId : 'supplemented-client-id' } ,
493+ additionalAuthenticationProviders : [ ] ,
494+ } ) ;
495+
496+ const generator = new DataGenerator ( gen1App , backendGenerator , outputDir , dataResource , logger ) ;
497+ const ops = await generator . plan ( ) ;
498+ await ops [ 0 ] . execute ( ) ;
499+
500+ const output = writtenFile ( 'resource.ts' ) ;
501+ expect ( output ) . toContain ( "clientId: 'supplemented-client-id'" ) ;
502+ expect ( output ) . toContain ( 'tokenExpiryFromAuthInSeconds: 1800' ) ;
503+ expect ( output ) . toContain ( 'tokenExpireFromIssueInSeconds: 3600' ) ;
504+ } ) ;
505+
506+ it ( 'floors TTL values when not exact multiples of 1000' , async ( ) => {
507+ const gen1App = await createGen1App ( {
508+ providers : { awscloudformation : { StackName : 'amplify-test-main-123456' , Region : 'us-east-1' } } ,
509+ api : {
510+ testApi : {
511+ service : 'AppSync' ,
512+ output : { GraphQLAPIIdOutput : 'api-123' } ,
513+ } ,
514+ } ,
515+ } ) ;
516+ mockSchema ( gen1App , 'type Todo @model { id: ID! }' , [ 'Todo' ] ) ;
517+ jest . spyOn ( gen1App , 'resourceMetaOutput' ) . mockImplementation ( ( _resource : DiscoveredResource , key : string ) => {
518+ if ( key === 'GraphQLAPIIdOutput' ) return 'api-123' ;
519+ if ( key === 'authConfig' )
520+ return {
521+ defaultAuthentication : {
522+ authenticationType : 'OPENID_CONNECT' ,
523+ openIDConnectConfig : {
524+ name : 'Floored' ,
525+ issuerUrl : 'https://idp.example.com' ,
526+ clientId : 'abc' ,
527+ authTTL : 3599999 ,
528+ iatTTL : 7200500 ,
529+ } ,
530+ } ,
531+ } as any ;
532+ return undefined as any ;
533+ } ) ;
534+ jest . spyOn ( gen1App . aws , 'fetchGraphqlApi' ) . mockResolvedValue ( {
535+ apiId : 'api-123' ,
536+ name : 'testApi' ,
537+ additionalAuthenticationProviders : [ ] ,
538+ } ) ;
539+
540+ const generator = new DataGenerator ( gen1App , backendGenerator , outputDir , dataResource , logger ) ;
541+ const ops = await generator . plan ( ) ;
542+ await ops [ 0 ] . execute ( ) ;
543+
544+ const output = writtenFile ( 'resource.ts' ) ;
545+ expect ( output ) . toContain ( 'tokenExpiryFromAuthInSeconds: 3599' ) ;
546+ expect ( output ) . toContain ( 'tokenExpireFromIssueInSeconds: 7200' ) ;
547+ } ) ;
548+
462549 it ( 'renders Lambda auth mode' , async ( ) => {
463550 const gen1App = await createGen1App ( {
464551 providers : { awscloudformation : { StackName : 'amplify-test-main-123456' , Region : 'us-east-1' } } ,
0 commit comments