File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const USER_AGENT = 'configure-aws-credentials-for-github-actions';
1010const MAX_TAG_VALUE_LENGTH = 256 ;
1111const SANITIZATION_CHARACTER = '_' ;
1212const ROLE_SESSION_NAME = 'GitHubActions' ;
13+ const REGION_REGEX = / ^ [ a - z 0 - 9 - ] + $ / g;
1314
1415async function assumeRole ( params ) {
1516 // Assume a role to get short-lived credentials using longer-lived credentials.
@@ -151,6 +152,10 @@ async function run() {
151152 const roleDurationSeconds = core . getInput ( 'role-duration-seconds' , { required : false } ) || MAX_ACTION_RUNTIME ;
152153 const roleSessionName = core . getInput ( 'role-session-name' , { required : false } ) || ROLE_SESSION_NAME ;
153154
155+ if ( ! region . match ( REGION_REGEX ) ) {
156+ throw new Error ( `Region is not valid: ${ region } ` ) ;
157+ }
158+
154159 exportRegion ( region ) ;
155160
156161 // Always export the source credentials and account ID.
Original file line number Diff line number Diff line change @@ -154,6 +154,19 @@ describe('Configure AWS Credentials', () => {
154154 expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_ACCOUNT_ID ) ;
155155 } ) ;
156156
157+ test ( 'validates region name' , async ( ) => {
158+ process . env . SHOW_STACK_TRACE = 'false' ;
159+
160+ const mockInputs = { ...CREDS_INPUTS , 'aws-region' : '$AWS_REGION' } ;
161+ core . getInput = jest
162+ . fn ( )
163+ . mockImplementation ( mockGetInput ( mockInputs ) ) ;
164+
165+ await run ( ) ;
166+
167+ expect ( core . setFailed ) . toHaveBeenCalledWith ( 'Region is not valid: $AWS_REGION' ) ;
168+ } ) ;
169+
157170 test ( 'can opt out of masking account ID' , async ( ) => {
158171 const mockInputs = { ...CREDS_INPUTS , 'aws-region' : 'us-east-1' , 'mask-aws-account-id' : 'false' } ;
159172 core . getInput = jest
You can’t perform that action at this time.
0 commit comments