Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapiest-cloudfront-url

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapiest-cloudfront-url - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

15

lib/cloudfrontUrlService.js

@@ -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

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc