Skip to content

Commit

Permalink
DRYed out the tests a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnachlinger committed Feb 18, 2013
1 parent 565b2b6 commit 81637d0
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions tests/tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ var test = require('tap').test;
var common = require('./common.js'); var common = require('./common.js');
var cf = require('..'); var cf = require('..');


var privateKey;
test('Setup', function (t) {
common.loadPrivateKey(function (err, key) {
t.notOk(err, "Loads test private key without error");
t.ok(key, "Test private key is not empty");
privateKey = key;
t.end();
});
});

/* /*
Using example data and output from: Using example data and output from:
http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/RestrictingAccessPrivateContent.html#CannedPolicy http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/RestrictingAccessPrivateContent.html#CannedPolicy
Expand All @@ -10,7 +20,7 @@ test('Canned policy works', function (t) {
var urlToSign = 'http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes'; var urlToSign = 'http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes';


var config = { var config = {
privateKey: '', privateKey: privateKey,
keyPairId: 'PK12345EXAMPLE', keyPairId: 'PK12345EXAMPLE',
dateLessThan: new Date(Date.parse('Sun, 1 Jan 2012 00:00:00 GMT')) dateLessThan: new Date(Date.parse('Sun, 1 Jan 2012 00:00:00 GMT'))
}; };
Expand All @@ -21,15 +31,11 @@ test('Canned policy works', function (t) {
'Key-Pair-Id': 'PK12345EXAMPLE' 'Key-Pair-Id': 'PK12345EXAMPLE'
}; };


common.loadPrivateKey(function (err, key) {
t.notOk(err, "Loads test private key");
config.privateKey = key;


cf.signUrl(urlToSign, config, function signUrlCb(err, signedUrl) { cf.signUrl(urlToSign, config, function signUrlCb(err, signedUrl) {
t.notOk(err, "Signs the URL"); t.notOk(err, "Signs the URL");
t.ok(common.queryStringHasKeysValues(signedUrl, expectedQueryString),"URL is signed as expected"); t.ok(common.queryStringHasKeysValues(signedUrl, expectedQueryString), "URL is signed as expected");
t.end(); t.end();
});
}); });
}); });


Expand All @@ -41,7 +47,7 @@ test('Custom policy works', function (t) {
var urlToSign = 'http://d604721fxaaqy9.cloudfront.net/training/orientation.avi'; var urlToSign = 'http://d604721fxaaqy9.cloudfront.net/training/orientation.avi';


var config = { var config = {
privateKey: '', privateKey: privateKey,
keyPairId: 'PK12345EXAMPLE', keyPairId: 'PK12345EXAMPLE',
dateLessThan: new Date(Date.parse('Sun, 1 Jan 2012 00:00:00 GMT')), dateLessThan: new Date(Date.parse('Sun, 1 Jan 2012 00:00:00 GMT')),
ipAddress: '145.168.143.0/24' ipAddress: '145.168.143.0/24'
Expand All @@ -53,14 +59,9 @@ test('Custom policy works', function (t) {
'Key-Pair-Id': 'PK12345EXAMPLE' 'Key-Pair-Id': 'PK12345EXAMPLE'
}; };


common.loadPrivateKey(function (err, key) { cf.signUrl(urlToSign, config, function signUrlCb(err, signedUrl) {
t.notOk(err, "Loads test private key"); t.notOk(err, "Signs the URL");
config.privateKey = key; t.ok(common.queryStringHasKeysValues(signedUrl, expectedQueryString), "URL is signed as expected");

t.end();
cf.signUrl(urlToSign, config, function signUrlCb(err, signedUrl) {
t.notOk(err, "Signs the URL");
t.ok(common.queryStringHasKeysValues(signedUrl, expectedQueryString),"URL is signed as expected");
t.end();
});
}); });
}); });

0 comments on commit 81637d0

Please sign in to comment.