hapiest-cloudfront-url
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -27,6 +27,8 @@ 'use strict'; | ||
/** | ||
* Returns true if the URL is from an origin in the Cloudfront distribution | ||
* | ||
* @param {String} url | ||
* @returns {boolean} | ||
*/ | ||
doesUrlMapToDistribution(url) { | ||
isOriginUrl(url) { | ||
for (var i=0; i < this._origins.length; i++) { | ||
@@ -65,2 +67,13 @@ if (this._doesUrlMatchOrigin(this._origins[i], url)) { | ||
/** | ||
* Returns true if the URL is from this Cloudfront distribution | ||
* | ||
* @param {String} url | ||
* @returns {boolean} | ||
*/ | ||
isDistributionUrl(url) { | ||
const urlInfo = Url.parse(url); | ||
return urlInfo.host === this._cloudfrontDomainName; | ||
} | ||
/** | ||
* @param {String} url - a URL you'd like to map to a Cloudfront URL | ||
@@ -67,0 +80,0 @@ * @param {Boolean} [forceConversion=false] - force a conversion even if we've disabled the service |
{ | ||
"name": "hapiest-cloudfront-url", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Maps origin URLs to an AWS Cloudfront distribution URL", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -80,2 +80,50 @@ 'use strict'; | ||
describe('isDistributionUrl', function() { | ||
it('Should return true when the url matches distribution and false when it does not', function() { | ||
const cfUrlService = CloudfrontUrlServiceFactory.create({ | ||
cloudfrontDomainName: 'dafjlsavc13asd.cloudfront.net', | ||
enabled: true, | ||
origins: [{host: 'localhost', port: 3000, path: 'localstorage/bucket/public'}] | ||
}); | ||
const urlToCheck_true = 'http://dafjlsavc13asd.cloudfront.net/images/folder/thumbnail.jpg'; | ||
const isDistributionUrl_true = cfUrlService.isDistributionUrl(urlToCheck_true); | ||
isDistributionUrl_true.should.be.True(); | ||
const urlToCheck_false = 'http://vizual.ai/images/folder/thumbnail.jpg'; | ||
const isDistributionUrl_false = cfUrlService.isDistributionUrl(urlToCheck_false); | ||
isDistributionUrl_false.should.be.False(); | ||
}); | ||
}); | ||
describe('matchesDistributionOrigins', function() { | ||
it('Should return true when the url matches an origin and false when it does not', function() { | ||
const cfUrlService = CloudfrontUrlServiceFactory.create({ | ||
cloudfrontDomainName: 'dafjlsavc13asd.cloudfront.net', | ||
enabled: true, | ||
origins: [ | ||
{host: 'localhost', port: 3000, path: '/localstorage/bucket/public'}, | ||
{host: 'static.digg.com', path: '/'}, | ||
] | ||
}); | ||
const localhost_url_true = 'http://localhost:3000/localstorage/bucket/public/images/somethumbnail.jpg'; | ||
const isOriginUrl_localhost_true = cfUrlService.isOriginUrl(localhost_url_true); | ||
isOriginUrl_localhost_true.should.be.True(); | ||
const digg_url_true = 'http://static.digg.com/somethumbnail.jpg'; | ||
const isOriginUrl_digg_true = cfUrlService.isOriginUrl(digg_url_true); | ||
isOriginUrl_digg_true.should.be.True(); | ||
const vizualai_url_false = 'http://vizual.ai/images/nomatch/thumbnail.jpg'; | ||
const isOriginUrl_vizualai_true = cfUrlService.isOriginUrl(vizualai_url_false); | ||
isOriginUrl_vizualai_true.should.be.False(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70563
358