fix the jshint errors in assertion_service.js

fixes #146
This commit is contained in:
Shane Tomlinson 2013-12-12 11:18:39 +00:00
Родитель e7ba3aebc6
Коммит 28b42d44d1
1 изменённых файлов: 27 добавлений и 21 удалений

Просмотреть файл

@ -10,16 +10,18 @@ define([
'intern/order!static/js/gherkin.js',
'intern/order!static/javascripts/vendor/bidbundle.js',
'intern/order!static/javascripts/assertion_service.js'
], function (tdd, assert, Deferred, request) {
with (tdd) {
suite('assertion_service', function () {
],
function (tdd, assert, Deferred, request, gherkin, bidbundle, AssertionService) {
'use strict';
tdd.suite('assertion_service', function () {
var client;
var assertionService;
var serverUrl = 'http://127.0.0.1:9000';
//var serverUrl = 'https://api-accounts.dev.lcip.org';
// before the suite starts
before(function () {
tdd.before(function () {
var setupDfd = new Deferred();
var Client = gherkin.Client;
@ -41,15 +43,15 @@ define([
return setupDfd.promise;
});
beforeEach(function () {
tdd.beforeEach(function () {
assertionService = new AssertionService(client);
});
test('client session check', function () {
tdd.test('client session check', function () {
assert.ok(client.sessionToken, 'token', 'Session should have a sessionToken');
});
test('#getAssertion (async)', function () {
tdd.test('#getAssertion (async)', function () {
// test will time out after 9 seconds
var dfd = this.async(9000);
@ -61,7 +63,7 @@ define([
}));
});
test('#generateKeys (async)', function () {
tdd.test('#generateKeys (async)', function () {
var dfd = this.async(9000);
// dfd.callback resolves the promise as long as no errors are thrown from within the callback function
@ -77,7 +79,7 @@ define([
}));
});
test('#testVerify (async)', function () {
tdd.test('#testVerify (async)', function () {
var dfd = this.async(9000);
// dfd.callback resolves the promise as long as no errors are thrown from within the callback function
@ -89,7 +91,7 @@ define([
});
test('#checkAssertion (async)', function () {
tdd.test('#checkAssertion (async)', function () {
var dfd = this.async(9000);
var jwcrypto = require('./lib/jwcrypto');
@ -108,21 +110,27 @@ define([
function (data) {
assert.ok(data, 'Received .well-known data');
var rk;
try {
var rk = JSON.stringify(JSON.parse(data)['public-key']);
rk = JSON.stringify(JSON.parse(data)['public-key']);
} catch (e) {
console.log(e);
dfd.reject(new assert.AssertionError({ message: 'Could not parse public key out of .well-known' }));
}
// jwcrypto verification can go wrong
var fxaRootKey;
var fullAssertion;
var components;
var assertionPublicKey;
var checkDate;
try {
var fxaRootKey = jwcrypto.loadPublicKeyFromObject(JSON.parse(rk));
var fullAssertion = jwcrypto.cert.unbundle(assertion);
var components = jwcrypto.extractComponents(fullAssertion.certs[0]);
var assertionPublicKey = jwcrypto.loadPublicKey(JSON.stringify(components.payload['public-key']));
fxaRootKey = jwcrypto.loadPublicKeyFromObject(JSON.parse(rk));
fullAssertion = jwcrypto.cert.unbundle(assertion);
components = jwcrypto.extractComponents(fullAssertion.certs[0]);
assertionPublicKey = jwcrypto.loadPublicKey(JSON.stringify(components.payload['public-key']));
var checkDate = new Date(components.payload.exp - 1);
checkDate = new Date(components.payload.exp - 1);
} catch (e) {
dfd.reject(new assert.AssertionError({ message: e }));
}
@ -162,7 +170,7 @@ define([
}
)
.then(
function(objs) {
function (objs) {
var verifyDeferred = new Deferred();
jwcrypto.assertion.verify(
@ -186,8 +194,7 @@ define([
return verifyDeferred.promise;
}
)
.then(
function(objs){
.then(function (objs) {
var verifyBundleDeferred = new Deferred();
jwcrypto.cert.verifyBundle(
@ -221,5 +228,4 @@ define([
});
});
}
});
});