Skip to content

Commit

Permalink
fix issues when SDK populates wrong path if access point arn contains…
Browse files Browse the repository at this point in the history
… forward slash (#2989)
  • Loading branch information
AllanZhengYP authored Dec 4, 2019
1 parent b030cf8 commit ed9a30e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-S3-cb2d4f76.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "S3",
"description": "fix issues when SDK populates wrong path if access point arn contains forward slash"
}
2 changes: 1 addition & 1 deletion lib/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ AWS.util.update(AWS.S3.prototype, {
dnsSuffix
].join('.');
endpoint.host = endpoint.hostname;
var encodedArn = AWS.util.uriEscapePath(req.params.Bucket);
var encodedArn = AWS.util.uriEscape(req.params.Bucket);
var path = req.httpRequest.path;
//remove the Bucket value from path
req.httpRequest.path = path.replace(new RegExp('/' + encodedArn), '');
Expand Down
48 changes: 32 additions & 16 deletions test/services/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,7 @@ describe('AWS.S3', function() {

it('supports access point ARN', function(done) {
s3.getSignedUrl('getObject', {
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint',
Key: 'key'
}, function(err, data) {
expect(data).to.equal(
Expand Down Expand Up @@ -3354,6 +3354,22 @@ describe('AWS.S3', function() {
});

it('should correctly generate access point endpoint', function(done) {
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
expect(err).to.not.exist;
expect(request.httpRequest.endpoint.hostname).to.equal(
'myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com'
);
expect(request.httpRequest.path).to.equal('/key');
done();
});
});

it('should correctly generate access point endpoint containing \':\'', function(done) {
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint',
Expand All @@ -3372,7 +3388,7 @@ describe('AWS.S3', function() {
it('should correctly generate access point endpoint for us-gov partition', function(done) {
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws-us-gov:s3:us-gov-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws-us-gov:s3:us-gov-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3389,7 +3405,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'cn-north-1'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws-cn:s3:cn-north-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3404,7 +3420,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-east-1'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:s3-external-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:s3-external-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
var built = request.build(function() {});
Expand All @@ -3415,7 +3431,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-east-1-fips'});
helpers.mockHttpResponse(200, {}, '');
request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
var error;
Expand All @@ -3430,7 +3446,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3445,7 +3461,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2', s3UseArnRegion: false});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3460,7 +3476,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2', endpoint: 'https://bucket.s3.us-west-2.amazonaws.com'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3475,7 +3491,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({s3ForcePathStyle: true});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3502,7 +3518,7 @@ describe('AWS.S3', function() {
it('should throw if cross region enabled but region from different partition', function(done) {
s3 = new AWS.S3({region: 'us-west-2'});
var request = s3.getObject({
Bucket: 'arn:aws-cn:s3:cn-north-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws-cn:s3:cn-north-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3519,7 +3535,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3535,7 +3551,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3553,7 +3569,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3571,7 +3587,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2'});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-east-1:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3587,7 +3603,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2', useAccelerateEndpoint: true});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand All @@ -3602,7 +3618,7 @@ describe('AWS.S3', function() {
s3 = new AWS.S3({region: 'us-west-2', useDualstack: true});
helpers.mockHttpResponse(200, {}, '');
var request = s3.getObject({
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint',
Bucket: 'arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint',
Key: 'key'
});
request.send(function(err, data) {
Expand Down

0 comments on commit ed9a30e

Please sign in to comment.