Fix authinfo test

This commit is contained in:
wltsmrz
2014-05-30 13:45:14 -07:00
parent 453ff91065
commit 644ca2b472
2 changed files with 44 additions and 29 deletions

View File

@@ -1,10 +1,19 @@
var request = require('superagent');
var RippleTxt = require('./rippletxt').RippleTxt;
var async = require('async');
var superagent = require('superagent');
var RippleTxt = require('./rippletxt').RippleTxt;
function AuthInfo() {
this.rippleTxt = new RippleTxt();
};
AuthInfo.prototype._getRippleTxt = function(domain, callback) {
this.rippleTxt.get(domain, callback);
};
AuthInfo.prototype._getUser = function(url, callback) {
superagent.get(url, callback);
};
/**
* Get auth info for a given username
*
@@ -13,34 +22,38 @@ function AuthInfo() {
* @param {function} fn - Callback function
*/
AuthInfo.prototype.get = function(domain, username, fn) {
AuthInfo.prototype.get = function(domain, username, callback) {
var self = this;
self.rippleTxt.get(domain, function(err, txt) {
if (err) {
fn(err);
} else {
processTxt(txt)
}
});
function getRippleTxt(callback) {
self._getRippleTxt(domain, function(err, txt) {
if (err) {
return callback(err);
}
function processTxt(txt) {
if (!txt.authinfo_url) {
return fn(new Error('Authentication is not supported on ' + domain));
}
if (!txt.authinfo_url) {
return callback(new Error('Authentication is not supported on ' + domain));
}
var url = Array.isArray(txt.authinfo_url) ? txt.authinfo_url[0] : txt.authinfo_url;
var url = Array.isArray(txt.authinfo_url) ? txt.authinfo_url[0] : txt.authinfo_url;
url += '?domain=' + domain + '&username='+username;
url += '?domain=' + domain + '&username=' + username;
request.get(url, function(err, resp) {
if (err || resp.error) {
fn(new Error('Authentication info server unreachable'));
callback(null, url);
});
};
function getUser(url, callback) {
self._getUser(url, function(err, res) {
if (err || res.error) {
callback(new Error('Authentication info server unreachable'));
} else {
fn(null, resp.body);
callback(null, res.body);
}
});
};
async.waterfall([ getRippleTxt, getUser ], callback);
};
exports.AuthInfo = AuthInfo;

View File

@@ -39,11 +39,6 @@ var rippleTxtRes = {
var authInfoRes = {
body: {
version: 3,
exists: true,
username: 'exampleUser',
address: 'raVUps4RghLYkVBcpMaRbVKRTTzhesPXd',
emailVerified: true,
reserved: false,
blobvault: 'https://id.staging.ripple.com',
pakdf: {
modulus: 'c7f1bc1dfb1be82d244aef01228c1409c1988943ca9e21431f1669b4aa3864c9f37f3d51b2b4ba1ab9e80f59d267fda1521e88b05117993175e004543c6e3611242f24432ce8efa3b81f0ff660b4f91c5d52f2511a6f38181a7bf9abeef72db056508bbb4eeb5f65f161dd2d5b439655d2ae7081fcc62fdcb281520911d96700c85cdaf12e7d1f15b55ade867240722425198d4ce39019550c4c8a921fc231d3e94297688c2d77cd68ee8fdeda38b7f9a274701fef23b4eaa6c1a9c15b2d77f37634930386fc20ec291be95aed9956801e1c76601b09c413ad915ff03bfdc0b6b233686ae59e8caf11750b509ab4e57ee09202239baee3d6e392d1640185e1cd',
@@ -51,7 +46,12 @@ var authInfoRes = {
url: 'https://auth1.ripple.com/api/sign',
exponent: '010001',
host: 'auth1.ripple.com'
}
},
exists: true,
username: 'exampleUser',
address: 'raVUps4RghLYkVBcpMaRbVKRTTzhesPXd',
emailVerified: true,
reserved: false
},
};
@@ -98,7 +98,9 @@ describe('AuthInfo', function() {
auth.get(exampleData.domain, exampleData.username, function(err, resp) {
assert.ifError(err);
assert.deepEqual(resp, authInfoRes.body);
Object.keys(authInfoRes.body).forEach(function(prop) {
assert(resp.hasOwnProperty(prop));
});
done();
});
});