@@ -9,7 +9,7 @@ import * as nock from 'nock';
99import {
1010 createGithubAppAuth ,
1111 createOctokitClient ,
12- getStoredAppId ,
12+ getAppId ,
1313 getStoredInstallationId ,
1414 onRateLimit ,
1515 onSecondaryRateLimit ,
@@ -34,6 +34,7 @@ const ENVIRONMENT = 'dev';
3434const GITHUB_APP_ID = '1' ;
3535const PARAMETER_GITHUB_APP_ID_NAME = `/actions-runner/${ ENVIRONMENT } /github_app_id` ;
3636const PARAMETER_GITHUB_APP_KEY_BASE64_NAME = `/actions-runner/${ ENVIRONMENT } /github_app_key_base64` ;
37+ const storageProviderType = 'aws_ssm' as const ;
3738
3839const mockedGetParameters = vi . mocked ( getParameters ) ;
3940
@@ -90,7 +91,7 @@ describe('Test createGithubAppAuth', () => {
9091 it ( 'Throws early when PARAMETER_GITHUB_APP_ID_NAME is not set' , async ( ) => {
9192 delete process . env . PARAMETER_GITHUB_APP_ID_NAME ;
9293
93- await expect ( createGithubAppAuth ( installationId ) ) . rejects . toThrow (
94+ await expect ( createGithubAppAuth ( storageProviderType , installationId ) ) . rejects . toThrow (
9495 'Environment variable PARAMETER_GITHUB_APP_ID_NAME is not set' ,
9596 ) ;
9697 expect ( mockedGetParameters ) . not . toHaveBeenCalled ( ) ;
@@ -99,7 +100,7 @@ describe('Test createGithubAppAuth', () => {
99100 it ( 'Throws early when PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set' , async ( ) => {
100101 delete process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME ;
101102
102- await expect ( createGithubAppAuth ( installationId ) ) . rejects . toThrow (
103+ await expect ( createGithubAppAuth ( storageProviderType , installationId ) ) . rejects . toThrow (
103104 'Environment variable PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set' ,
104105 ) ;
105106 expect ( mockedGetParameters ) . not . toHaveBeenCalled ( ) ;
@@ -120,7 +121,7 @@ describe('Test createGithubAppAuth', () => {
120121 mockedCreatAppAuth . mockReturnValue ( mockWithHook ) ;
121122
122123 // Act
123- await createGithubAppAuth ( installationId ) ;
124+ await createGithubAppAuth ( storageProviderType , installationId ) ;
124125
125126 // Assert
126127 expect ( mockedCreatAppAuth ) . toBeCalledTimes ( 1 ) ;
@@ -155,7 +156,7 @@ describe('Test createGithubAppAuth', () => {
155156 } ) ;
156157
157158 // Act
158- await createGithubAppAuth ( installationId ) ;
159+ await createGithubAppAuth ( storageProviderType , installationId ) ;
159160
160161 // Generate two JWTs and verify they are different (jti makes them unique)
161162 const jwt1 = await capturedCreateJwt ! ( 1 ) ;
@@ -192,7 +193,7 @@ describe('Test createGithubAppAuth', () => {
192193 mockedCreatAppAuth . mockReturnValue ( mockWithHook ) ;
193194
194195 // Act
195- const result = await createGithubAppAuth ( installationId ) ;
196+ const result = await createGithubAppAuth ( storageProviderType , installationId ) ;
196197
197198 // Assert
198199 expect ( getParameters ) . toBeCalledWith ( [ PARAMETER_GITHUB_APP_ID_NAME , PARAMETER_GITHUB_APP_KEY_BASE64_NAME ] ) ;
@@ -216,7 +217,7 @@ describe('Test createGithubAppAuth', () => {
216217 mockedCreatAppAuth . mockReturnValue ( mockWithHook ) ;
217218
218219 // Act
219- const result = await createGithubAppAuth ( installationId ) ;
220+ const result = await createGithubAppAuth ( storageProviderType , installationId ) ;
220221
221222 // Assert
222223 expect ( getParameters ) . toBeCalledWith ( [ PARAMETER_GITHUB_APP_ID_NAME , PARAMETER_GITHUB_APP_KEY_BASE64_NAME ] ) ;
@@ -253,7 +254,7 @@ describe('Test createGithubAppAuth', () => {
253254 } ) ;
254255
255256 // Act
256- const result = await createGithubAppAuth ( installationId , githubServerUrl ) ;
257+ const result = await createGithubAppAuth ( storageProviderType , installationId , githubServerUrl ) ;
257258
258259 // Assert
259260 expect ( getParameters ) . toBeCalledWith ( [ PARAMETER_GITHUB_APP_ID_NAME , PARAMETER_GITHUB_APP_KEY_BASE64_NAME ] ) ;
@@ -291,7 +292,7 @@ describe('Test createGithubAppAuth', () => {
291292 mockedCreatAppAuth . mockReturnValue ( mockWithHook ) ;
292293
293294 // Act
294- const result = await createGithubAppAuth ( installationId , githubServerUrl ) ;
295+ const result = await createGithubAppAuth ( storageProviderType , installationId , githubServerUrl ) ;
295296
296297 // Assert
297298 expect ( getParameters ) . toBeCalledWith ( [ PARAMETER_GITHUB_APP_ID_NAME , PARAMETER_GITHUB_APP_KEY_BASE64_NAME ] ) ;
@@ -353,7 +354,7 @@ describe('Test getStoredInstallationId', () => {
353354 ] ) ,
354355 ) ;
355356
356- const result = await getStoredInstallationId ( 0 ) ;
357+ const result = await getStoredInstallationId ( storageProviderType , 0 ) ;
357358 expect ( result ) . toBe ( 12345 ) ;
358359 } ) ;
359360
@@ -368,11 +369,24 @@ describe('Test getStoredInstallationId', () => {
368369 ] ) ,
369370 ) ;
370371
371- await expect ( getStoredAppId ( 0 ) ) . resolves . toBe ( GITHUB_APP_ID ) ;
372- await expect ( getStoredInstallationId ( 0 ) ) . resolves . toBe ( 12345 ) ;
372+ await expect ( getAppId ( storageProviderType , 0 ) ) . resolves . toBe ( GITHUB_APP_ID ) ;
373+ await expect ( getStoredInstallationId ( storageProviderType , 0 ) ) . resolves . toBe ( 12345 ) ;
373374 expect ( mockedGetParameters ) . toHaveBeenCalledTimes ( 1 ) ;
374375 } ) ;
375376
377+ it ( 'retries credential loading after a cached request rejects' , async ( ) => {
378+ mockedGetParameters . mockRejectedValueOnce ( new Error ( 'temporary storage failure' ) ) . mockResolvedValueOnce (
379+ new Map ( [
380+ [ PARAMETER_GITHUB_APP_ID_NAME , GITHUB_APP_ID ] ,
381+ [ PARAMETER_GITHUB_APP_KEY_BASE64_NAME , b64 ] ,
382+ ] ) ,
383+ ) ;
384+
385+ await expect ( getAppId ( storageProviderType ) ) . rejects . toThrow ( 'temporary storage failure' ) ;
386+ await expect ( getAppId ( storageProviderType ) ) . resolves . toBe ( GITHUB_APP_ID ) ;
387+ expect ( mockedGetParameters ) . toHaveBeenCalledTimes ( 2 ) ;
388+ } ) ;
389+
376390 it ( 'returns undefined when installation ID param is empty' , async ( ) => {
377391 process . env . PARAMETER_GITHUB_APP_INSTALLATION_ID_NAME = '' ;
378392 mockedGetParameters . mockResolvedValueOnce (
@@ -382,7 +396,7 @@ describe('Test getStoredInstallationId', () => {
382396 ] ) ,
383397 ) ;
384398
385- const result = await getStoredInstallationId ( 0 ) ;
399+ const result = await getStoredInstallationId ( storageProviderType , 0 ) ;
386400 expect ( result ) . toBeUndefined ( ) ;
387401 } ) ;
388402
@@ -395,7 +409,7 @@ describe('Test getStoredInstallationId', () => {
395409 ] ) ,
396410 ) ;
397411
398- const result = await getStoredInstallationId ( 0 ) ;
412+ const result = await getStoredInstallationId ( storageProviderType , 0 ) ;
399413 expect ( result ) . toBeUndefined ( ) ;
400414 } ) ;
401415
@@ -408,7 +422,7 @@ describe('Test getStoredInstallationId', () => {
408422 ] ) ,
409423 ) ;
410424
411- const result = await getStoredInstallationId ( 99 ) ;
425+ const result = await getStoredInstallationId ( storageProviderType , 99 ) ;
412426 expect ( result ) . toBeUndefined ( ) ;
413427 } ) ;
414428
@@ -434,11 +448,11 @@ describe('Test getStoredInstallationId', () => {
434448 ) ;
435449
436450 // Primary app (index 0) has no stored installation ID
437- const result0 = await getStoredInstallationId ( 0 ) ;
451+ const result0 = await getStoredInstallationId ( storageProviderType , 0 ) ;
438452 expect ( result0 ) . toBeUndefined ( ) ;
439453
440454 // Additional app (index 1) has stored installation ID
441- const result1 = await getStoredInstallationId ( 1 ) ;
455+ const result1 = await getStoredInstallationId ( storageProviderType , 1 ) ;
442456 expect ( result1 ) . toBe ( 67890 ) ;
443457 } ) ;
444458} ) ;
0 commit comments