Skip to content

Commit

Permalink
fix issues with regional endpoints and add integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Dec 4, 2019
1 parent 66a5e5b commit 0b86f9d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Endpoint-d580bc63.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Endpoint",
"description": "fix bug in regional endpoints and add more tests"
}
8 changes: 8 additions & 0 deletions features/s3/buckets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Feature: Working with Buckets
When I delete the bucket
Then the bucket should not exist

@us-east-1-regional-endpoint
Scenario: Support us-east-1 regional endpoint
Given I am using the S3 us-east-1 regional endpoint
When I create a bucket
Then the bucket should exist
When I delete the bucket
Then the bucket should not exist

@cors
Scenario: Bucket CORS
When I create a bucket
Expand Down
5 changes: 5 additions & 0 deletions features/s3/step_definitions/buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module.exports = function() {
callback();
});

this.Given(/^I am using the S3 us-east-1 regional endpoint$/, function(callback) {
this.s3 = new this.AWS.S3({region: 'us-east-1', s3UsEast1RegionalEndpoint: 'regional'});
callback();
});

this.When(/^I create a bucket with the location constraint "([^"]*)"$/, function(location, callback) {
var bucket = this.bucket = this.uniqueName('aws-sdk-js-integration');
var params = {
Expand Down
10 changes: 10 additions & 0 deletions features/sts/step_definitions/sts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ module.exports = function() {
this.request(null, 'getSessionToken', {DurationSeconds: parseInt(duration)}, callback, false);
});

this.Before('@sts-regional-endpoints', function(callback) {
this.service = new this.AWS.STS({region: 'us-east-1', stsRegionalEndpoints: 'regional'});
callback()
});

this.After('@sts-regional-endpoints', function(callback) {
this.service = new this.AWS.STS();
callback();
})

this.Then(/^the result should contain an access key ID and secret access key$/, function(callback) {
this.assert.compare(this.data.Credentials.AccessKeyId.length, '>', 0);
this.assert.compare(this.data.Credentials.SecretAccessKey.length, '>', 0);
Expand Down
5 changes: 5 additions & 0 deletions features/sts/sts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ Feature: AWS Security Token Service
Scenario: Error handling
Given I get an STS session token with a duration of 60 seconds
Then the error code should be "ValidationError"

@sts-regional-endpoints
Scenario: Get a session token from regional endpoint
Given I get an STS session token with a duration of 900 seconds
Then the result should contain an access key ID and secret access key
12 changes: 12 additions & 0 deletions lib/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ export abstract class ConfigurationOptions {
* Whether to force path style URLs for S3 objects.
*/
s3ForcePathStyle?: boolean
/**
* when region is set to 'us-east-1', whether to send s3 request to global endpoints
* or 'us-east-1' regional endpoints. This config is only applicable to S3 client;
* Defaults to 'legacy'
*/
s3UsEast1RegionalEndpoint?: "regional"|"legacy"
/**
* whether to override the request region with the region inferred
* from requested resource's ARN. Only available for S3 buckets
* Defaults to `true`
*/
s3UseArnRegion?: boolean
/**
* Whether the signature to sign requests with (overriding the API configuration) is cached.
*/
Expand Down
4 changes: 1 addition & 3 deletions lib/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ AWS.util.update(AWS.S3.prototype, {
var insertPoint = config.endpoint.indexOf('.amazonaws.com');
regionalEndpoint = config.endpoint.substring(0, insertPoint) +
'.us-east-1' + config.endpoint.substring(insertPoint);
var endpoint = req.httpRequest.endpoint;
endpoint.hostname = regionalEndpoint;
endpoint.host = regionalEndpoint;
req.httpRequest.updateEndpoint(regionalEndpoint);
}
},

Expand Down
7 changes: 3 additions & 4 deletions lib/services/sts.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ AWS.util.update(AWS.STS.prototype, {
{code: 'ConfigError', message: 'Missing region in config'});
}
var insertPoint = config.endpoint.indexOf('.amazonaws.com');

regionalEndpoint = config.endpoint.substring(0, insertPoint) +
'.' + config.region + config.endpoint.substring(insertPoint);
var endpoint = req.httpRequest.endpoint;
endpoint.hostname = regionalEndpoint;
endpoint.host = regionalEndpoint;
'.' + config.region + config.endpoint.substring(insertPoint);
req.httpRequest.updateEndpoint(regionalEndpoint);
req.httpRequest.region = config.region;
}
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/region-checker/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ var whitelist = {
370,
376,
748,
750,
869,
746,
867,
880,
881,
882,
887
878,
879,
885
]
};

Expand Down
10 changes: 5 additions & 5 deletions test/services/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3319,18 +3319,18 @@ describe('AWS.S3', function() {
it('according to config settings', function() {
var s3 = new AWS.S3({region: 'us-west-2'});
var request = s3.listBuckets().build(function() {});
expect(request.httpRequest.endpoint.hostname).to.contain('s3.us-west-2.amazonaws.com');
expect(request.httpRequest.endpoint.hostname).to.equal('s3.us-west-2.amazonaws.com');
s3 = new AWS.S3({region: 'us-east-1'});
var request = s3.listBuckets().build(function() {});
expect(request.httpRequest.endpoint.hostname).to.contain('s3.amazonaws.com');
expect(request.httpRequest.endpoint.hostname).to.equal('s3.amazonaws.com');
s3 = new AWS.S3({region: 'us-east-1', s3UsEast1RegionalEndpoint: 'regional'});
request = s3.listBuckets().build(function() {});
expect(request.httpRequest.endpoint.hostname).to.contain('s3.us-east-1.amazonaws.com');
expect(request.httpRequest.endpoint.hostname).to.equal('s3.us-east-1.amazonaws.com');
});
it('should use global endpoints for when config is set to legacy', function() {
s3 = new AWS.S3({region: 'us-east-1', s3UsEast1RegionalEndpoint: 'legacy'});
request = s3.listBuckets().build(function() {});
expect(request.httpRequest.endpoint.hostname).to.contain('s3.amazonaws.com');
expect(request.httpRequest.endpoint.hostname).to.equal('s3.amazonaws.com');
});
it('should not update endpoint if supplied a custom endpoint', function() {
s3 = new AWS.S3({
Expand All @@ -3339,7 +3339,7 @@ describe('AWS.S3', function() {
endpoint: 's3.amazonaws.com'
});
request = s3.listBuckets().build(function() {});
expect(request.httpRequest.endpoint.hostname).to.contain('s3.amazonaws.com');
expect(request.httpRequest.endpoint.hostname).to.equal('s3.amazonaws.com');
});
});
}
Expand Down
12 changes: 6 additions & 6 deletions test/services/sts.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b86f9d

Please sign in to comment.