File tree Expand file tree Collapse file tree 2 files changed +32
-7
lines changed
lambdas/functions/control-plane/src/github Expand file tree Collapse file tree 2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,24 @@ describe('Test createGithubAppAuth', () => {
7777 process . env . ENVIRONMENT = ENVIRONMENT ;
7878 } ) ;
7979
80+ it ( 'Throws early when PARAMETER_GITHUB_APP_ID_NAME is not set' , async ( ) => {
81+ delete process . env . PARAMETER_GITHUB_APP_ID_NAME ;
82+
83+ await expect ( createGithubAppAuth ( installationId ) ) . rejects . toThrow (
84+ 'Environment variable PARAMETER_GITHUB_APP_ID_NAME is not set' ,
85+ ) ;
86+ expect ( mockedGetParameters ) . not . toHaveBeenCalled ( ) ;
87+ } ) ;
88+
89+ it ( 'Throws early when PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set' , async ( ) => {
90+ delete process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME ;
91+
92+ await expect ( createGithubAppAuth ( installationId ) ) . rejects . toThrow (
93+ 'Environment variable PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set' ,
94+ ) ;
95+ expect ( mockedGetParameters ) . not . toHaveBeenCalled ( ) ;
96+ } ) ;
97+
8098 it ( 'Creates auth object with line breaks in SSH key.' , async ( ) => {
8199 // Arrange
82100 const authOptions = {
Original file line number Diff line number Diff line change @@ -70,18 +70,25 @@ export async function createGithubInstallationAuth(
7070}
7171
7272async function createAuth ( installationId : number | undefined , ghesApiUrl : string ) : Promise < AuthInterface > {
73+ const appIdParamName = process . env . PARAMETER_GITHUB_APP_ID_NAME ;
74+ const appKeyParamName = process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME ;
75+ if ( ! appIdParamName ) {
76+ throw new Error ( 'Environment variable PARAMETER_GITHUB_APP_ID_NAME is not set' ) ;
77+ }
78+ if ( ! appKeyParamName ) {
79+ throw new Error ( 'Environment variable PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set' ) ;
80+ }
81+
7382 // Batch fetch both App ID and Private Key in a single SSM API call
74- const paramNames = [ process . env . PARAMETER_GITHUB_APP_ID_NAME , process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME ] ;
83+ const paramNames = [ appIdParamName , appKeyParamName ] ;
7584 const params = await getParameters ( paramNames ) ;
76-
77- const appIdValue = params . get ( process . env . PARAMETER_GITHUB_APP_ID_NAME ) ;
78- const privateKeyBase64 = params . get ( process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME ) ;
79-
85+ const appIdValue = params . get ( appIdParamName ) ;
86+ const privateKeyBase64 = params . get ( appKeyParamName ) ;
8087 if ( ! appIdValue ) {
81- throw new Error ( `Parameter ${ process . env . PARAMETER_GITHUB_APP_ID_NAME } not found` ) ;
88+ throw new Error ( `Parameter ${ appIdParamName } not found` ) ;
8289 }
8390 if ( ! privateKeyBase64 ) {
84- throw new Error ( `Parameter ${ process . env . PARAMETER_GITHUB_APP_KEY_BASE64_NAME } not found` ) ;
91+ throw new Error ( `Parameter ${ appKeyParamName } not found` ) ;
8592 }
8693
8794 const appId = parseInt ( appIdValue ) ;
You can’t perform that action at this time.
0 commit comments