Skip to content

Commit 71f0358

Browse files
committed
Add unit test for hardcoded S3 credentials
1 parent 0bc10de commit 71f0358

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/unit/s3gateway_test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,31 @@ function testEscapeURIPathPreservesDoubleSlashes() {
298298
}
299299
}
300300

301+
function testReadCredentialsWithAccessAndSecretKeySet() {
302+
process.env['S3_ACCESS_KEY_ID'] = 'SOME_ACCESS_KEY';
303+
process.env['S3_SECRET_KEY'] = 'SOME_SECRET_KEY';
304+
305+
try {
306+
var credentials = s3gateway.readCredentials();
307+
if (credentials.accessKeyId !== process.env['S3_ACCESS_KEY_ID']) {
308+
throw 'static credentials do not match returned value [accessKeyId]';
309+
}
310+
if (credentials.secretAccessKey !== process.env['S3_SECRET_KEY']) {
311+
throw 'static credentials do not match returned value [secretAccessKey]';
312+
}
313+
if (credentials.sessionToken !== null) {
314+
throw 'static credentials do not match returned value [sessionToken]';
315+
}
316+
if (credentials.expiration !== null) {
317+
throw 'static credentials do not match returned value [expiration]';
318+
}
319+
320+
} finally {
321+
delete process.env.S3_ACCESS_KEY_ID;
322+
delete process.env.S3_SECRET_KEY;
323+
}
324+
}
325+
301326
function testReadCredentials() {
302327
var originalCredentialPath = process.env['S3_CREDENTIALS_TEMP_FILE'];
303328
var tempDir = (process.env['TMPDIR'] ? process.env['TMPDIR'] : '/tmp');
@@ -485,8 +510,9 @@ async function test() {
485510
testEditAmzHeaders();
486511
testEditAmzHeadersHeadDirectory();
487512
testEscapeURIPathPreservesDoubleSlashes();
488-
testReadCredentialsFromNonexistentPath();
513+
testReadCredentialsWithAccessAndSecretKeySet();
489514
testReadCredentials();
515+
testReadCredentialsFromNonexistentPath();
490516
await testEcsCredentialRetrieval();
491517
await testEc2CredentialRetrieval();
492518
}

0 commit comments

Comments
 (0)