Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues when SDK populates wrong path if access point arn contains forward slash #2989

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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