Skip to content

Commit 0526e18

Browse files
authored
Handle the case where an incomplete set of AWS credentials were provided.
1 parent 870a463 commit 0526e18

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

rush-plugins/rush-amazon-s3-build-cache-plugin/src/AmazonS3Credentials.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ export const fromAmazonEnv = (): IAmazonS3Credentials | undefined => {
3232
secretAccessKey,
3333
sessionToken
3434
};
35+
} else if (accessKeyId) {
36+
throw new Error(
37+
`The "${AWS_ACCESS_KEY_ID}" env variable is set, but the "${AWS_SECRET_ACCESS_KEY}" `+
38+
`env variable is not set. Both or neither must be provided.`
39+
);
40+
} else if (secretAccessKey) {
41+
throw new Error(
42+
`The "${AWS_SECRET_ACCESS_KEY}" env variable is set, but the "${AWS_ACCESS_KEY_ID}" `+
43+
`env variable is not set. Both or neither must be provided.`
44+
);
45+
} else {
46+
return undefined;
3547
}
36-
37-
return undefined;
3848
};
3949

4050
/**

rush-plugins/rush-amazon-s3-build-cache-plugin/src/test/AmazonS3Credentials.test.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ describe('Amazon S3 Credentials', () => {
2020
oldEnvAwsAccessKeyId = process.env[AWS_ACCESS_KEY_ID];
2121
oldEnvAwsSecretAccessKey = process.env[AWS_SECRET_ACCESS_KEY];
2222
oldEnvAwsSessionToken = process.env[AWS_SESSION_TOKEN];
23+
24+
delete process.env[AWS_ACCESS_KEY_ID];
25+
delete process.env[AWS_SECRET_ACCESS_KEY];
26+
delete process.env[AWS_SESSION_TOKEN];
2327
});
2428

2529
afterEach(() => {
@@ -55,10 +59,11 @@ describe('Amazon S3 Credentials', () => {
5559

5660
it('returns undefined if access key and secret are not both present', () => {
5761
process.env[AWS_ACCESS_KEY_ID] = AWS_ACCESS_KEY_ID;
62+
expect(() => fromAmazonEnv()).toThrowErrorMatchingSnapshot();
5863

59-
const credentials = fromAmazonEnv();
60-
61-
expect(credentials).toBeUndefined();
64+
delete process.env[AWS_ACCESS_KEY_ID];
65+
process.env[AWS_SECRET_ACCESS_KEY] = AWS_SECRET_ACCESS_KEY;
66+
expect(() => fromAmazonEnv()).toThrowErrorMatchingSnapshot();
6267
});
6368
});
6469

0 commit comments

Comments
 (0)