Skip to content

Commit

Permalink
Rename isDnsCompatible to dnsCompatibleBucketName (#3364)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 22, 2020
1 parent bc41e65 commit e345c65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ AWS.util.update(AWS.S3.prototype, {
}
var accessPoint = parsedArn.resource.split(delimiter)[1];
var accessPointPrefix = accessPoint + '-' + parsedArn.accountId;
if (!req.service.isDnsCompatible(accessPointPrefix) || accessPointPrefix.match(/\./)) {
if (!req.service.dnsCompatibleBucketName(accessPointPrefix) || accessPointPrefix.match(/\./)) {
throw AWS.util.error(new Error(), {
code: 'InvalidAccessPointARN',
message: 'Access point ARN is not DNS compatible. Got ' + accessPoint
Expand Down Expand Up @@ -621,7 +621,7 @@ AWS.util.update(AWS.S3.prototype, {
if (this.config.s3ForcePathStyle) return true;
if (this.config.s3BucketEndpoint) return false;

if (this.isDnsCompatible(bucketName)) {
if (this.dnsCompatibleBucketName(bucketName)) {
return (this.config.sslEnabled && bucketName.match(/\./)) ? true : false;
} else {
return true; // not dns compatible names must always use path style
Expand All @@ -634,7 +634,7 @@ AWS.util.update(AWS.S3.prototype, {
*
* @api private
*/
isDnsCompatible: function isDnsCompatible(bucketName) {
dnsCompatibleBucketName: function dnsCompatibleBucketName(bucketName) {
var b = bucketName;
var domain = new RegExp(/^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/);
var ipAddress = new RegExp(/(\d+\.){3}\d+/);
Expand Down Expand Up @@ -890,7 +890,7 @@ AWS.util.update(AWS.S3.prototype, {
if (cachedRegion && cachedRegion !== request.httpRequest.region) {
service.updateReqBucketRegion(request, cachedRegion);
done();
} else if (!service.isDnsCompatible(bucket)) {
} else if (!service.dnsCompatibleBucketName(bucket)) {
service.updateReqBucketRegion(request, 'us-east-1');
if (bucketRegionCache[bucket] !== 'us-east-1') {
bucketRegionCache[bucket] = 'us-east-1';
Expand Down
30 changes: 15 additions & 15 deletions test/services/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@ describe('AWS.S3', function() {
return done();
});

describe('isDnsCompatible', function() {
describe('dnsCompatibleBucketName', function() {
it('must be at least 3 characters', function() {
expect(s3.isDnsCompatible('aa')).to.equal(false);
expect(s3.dnsCompatibleBucketName('aa')).to.equal(false);
});

it('must not be longer than 63 characters', function() {
var b;
b = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
expect(s3.isDnsCompatible(b)).to.equal(false);
expect(s3.dnsCompatibleBucketName(b)).to.equal(false);
});

it('must start with a lower-cased letter or number', function() {
expect(s3.isDnsCompatible('Abc')).to.equal(false);
expect(s3.isDnsCompatible('-bc')).to.equal(false);
expect(s3.isDnsCompatible('abc')).to.equal(true);
expect(s3.dnsCompatibleBucketName('Abc')).to.equal(false);
expect(s3.dnsCompatibleBucketName('-bc')).to.equal(false);
expect(s3.dnsCompatibleBucketName('abc')).to.equal(true);
});

it('must end with a lower-cased letter or number', function() {
expect(s3.isDnsCompatible('abC')).to.equal(false);
expect(s3.isDnsCompatible('ab-')).to.equal(false);
expect(s3.isDnsCompatible('abc')).to.equal(true);
expect(s3.dnsCompatibleBucketName('abC')).to.equal(false);
expect(s3.dnsCompatibleBucketName('ab-')).to.equal(false);
expect(s3.dnsCompatibleBucketName('abc')).to.equal(true);
});

it('may not contain multiple contiguous dots', function() {
expect(s3.isDnsCompatible('abc.123')).to.equal(true);
expect(s3.isDnsCompatible('abc..123')).to.equal(false);
expect(s3.dnsCompatibleBucketName('abc.123')).to.equal(true);
expect(s3.dnsCompatibleBucketName('abc..123')).to.equal(false);
});

it('may only contain letters numbers and dots', function() {
expect(s3.isDnsCompatible('abc123')).to.equal(true);
expect(s3.isDnsCompatible('abc_123')).to.equal(false);
expect(s3.dnsCompatibleBucketName('abc123')).to.equal(true);
expect(s3.dnsCompatibleBucketName('abc_123')).to.equal(false);
});

it('must not look like an ip address', function() {
expect(s3.isDnsCompatible('1.2.3.4')).to.equal(false);
expect(s3.isDnsCompatible('a.b.c.d')).to.equal(true);
expect(s3.dnsCompatibleBucketName('1.2.3.4')).to.equal(false);
expect(s3.dnsCompatibleBucketName('a.b.c.d')).to.equal(true);
});
});

Expand Down

0 comments on commit e345c65

Please sign in to comment.