Begin work on offline vault client tests

This commit is contained in:
wltsmrz
2014-05-29 14:33:53 -07:00
parent 61bc01ae12
commit 9a349a3d55
2 changed files with 157 additions and 105 deletions

View File

@@ -1,54 +1,112 @@
var assert = require('assert'),
RippleTxt = require('../src/js/ripple/rippletxt').RippleTxt,
AuthInfo = require('../src/js/ripple/authinfo').AuthInfo,
VaultClient = require('../src/js/ripple/vaultclient').VaultClient,
Blob = require('../src/js/ripple/blob').Blob,
UInt256 = require('../src/js/ripple/uint256').UInt256;
var assert = require('assert');
var RippleTxt = require('../src/js/ripple/rippletxt').RippleTxt;
var AuthInfo = require('../src/js/ripple/authinfo').AuthInfo;
var VaultClient = require('../src/js/ripple/vaultclient').VaultClient;
var Blob = require('../src/js/ripple/blob').Blob;
var UInt256 = require('../src/js/ripple/uint256').UInt256;
var exampleData = {
id : "ef203d3e76552c0592384f909e6f61f1d1f02f61f07643ce015d8b0c9710dd2f",
crypt : "f0cc91a7c1091682c245cd8e13c246cc150b2cf98b17dd6ef092019c99dc9d82",
unlock : "3e15fe3218a9c664835a6f585582e14480112110ddbe50e5028d05fc5bd9b5f4",
blobURL : "https://id.staging.ripple.com",
username : "exampleUser",
password : "pass word",
domain : "staging.ripple.com",
encrypted_secret : "APYqtqvjJk/J324rx2BGGzUiQ3mtmMMhMsbrUmgxb00W2aFVQzCC2mqd58Z17gzeUUcjtjAm"
id: 'ef203d3e76552c0592384f909e6f61f1d1f02f61f07643ce015d8b0c9710dd2f',
crypt: 'f0cc91a7c1091682c245cd8e13c246cc150b2cf98b17dd6ef092019c99dc9d82',
unlock: '3e15fe3218a9c664835a6f585582e14480112110ddbe50e5028d05fc5bd9b5f4',
blobURL: 'https://id.staging.ripple.com',
username: 'exampleUser',
password: 'pass word',
domain: 'staging.ripple.com',
encrypted_secret: 'APYqtqvjJk/J324rx2BGGzUiQ3mtmMMhMsbrUmgxb00W2aFVQzCC2mqd58Z17gzeUUcjtjAm'
};
var rippleTxtRes = {
address: [ 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV' ],
validation_public_key: [ 'n9KPnVLn7ewVzHvn218DcEYsnWLzKerTDwhpofhk4Ym1RUq4TeGw' ],
domain: [ 'ripple.com' ],
ips: [
'23.21.167.100 51235',
'23.23.201.55 51235',
'107.21.116.214 51235'
],
validators: [
'n9KPnVLn7ewVzHvn218DcEYsnWLzKerTDwhpofhk4Ym1RUq4TeGw',
'n9LFzWuhKNvXStHAuemfRKFVECLApowncMAM5chSCL9R5ECHGN4V',
'n94rSdgTyBNGvYg8pZXGuNt59Y5bGAZGxbxyvjDaqD9ceRAgD85P',
'redstem.com'
],
authinfo_url: [
'https://id.staging.ripple.com/v1/authinfo'
]
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; //must be set for self signed certs
var authInfoRes = {
body: {
version: 3,
exists: true,
username: 'exampleUser',
address: 'raVUps4RghLYkVBcpMaRbVKRTTzhesPXd',
emailVerified: true,
reserved: false,
blobvault: 'https://id.staging.ripple.com',
pakdf: {
modulus: 'c7f1bc1dfb1be82d244aef01228c1409c1988943ca9e21431f1669b4aa3864c9f37f3d51b2b4ba1ab9e80f59d267fda1521e88b05117993175e004543c6e3611242f24432ce8efa3b81f0ff660b4f91c5d52f2511a6f38181a7bf9abeef72db056508bbb4eeb5f65f161dd2d5b439655d2ae7081fcc62fdcb281520911d96700c85cdaf12e7d1f15b55ade867240722425198d4ce39019550c4c8a921fc231d3e94297688c2d77cd68ee8fdeda38b7f9a274701fef23b4eaa6c1a9c15b2d77f37634930386fc20ec291be95aed9956801e1c76601b09c413ad915ff03bfdc0b6b233686ae59e8caf11750b509ab4e57ee09202239baee3d6e392d1640185e1cd',
alpha: '7283d19e784f48a96062271a5fa6e2c3addf14e6ezf78a4bb61364856d580f13552008d7b9e3b60ebd9555e9f6c7778ec69f976757d206134e54d61ba9d588a7e37a77cf48060522478352d76db000366ef669a1b1ca93c5e3e05bc344afa1e8ccb15d3343da94180dccf590c2c32408c3f3f176c8885e95d988f1565ee9b80c12f72503ab49917792f907bbb9037487b0afed967fefc9ab090164597fcd391c43fab33029b38e66ff4af96cbf6d90a01b891f856ddd3d94e9c9b307fe01e1353a8c30edd5a94a0ebba5fe7161569000ad3b0d3568872d52b6fbdfce987a687e4b346ea702e8986b03b6b1b85536c813e46052a31ed64ec490d3ba38029544aa',
url: 'https://auth1.ripple.com/api/sign',
exponent: '010001',
host: 'auth1.ripple.com'
}
},
};
//must be set for self signed certs
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
describe('Ripple Txt', function() {
it('should get the context of a ripple.txt file from a given domain', function(done){
this.timeout(10000);
it('should get the content of a ripple.txt file from a given domain', function(done) {
var rt = new RippleTxt();
rt.get(exampleData.domain, function(err, resp){
assert.ifError(err);
assert.equal(typeof resp, 'object');
var requestedUrls = [ ];
var testUrls = RippleTxt.urlTemplates.map(function(template) {
return template.replace('{{domain}}', 'localhost');
});
rt.request = function(url, callback) {
requestedUrls.push(url);
callback(new Error());
};
rt.get('localhost', function(err, resp) {
assert(err instanceof Error);
assert.strictEqual(resp, void(0));
assert.deepEqual(requestedUrls, testUrls);
done();
});
});
});
describe('AuthInfo', function() {
var auth = new AuthInfo();
it ('should', function(done){
this.timeout(10000);
auth.get(exampleData.domain, exampleData.user, function(err, resp){
it('should get auth info', function(done) {
var auth = new AuthInfo();
auth._getRippleTxt = function(domain, callback) {
assert.strictEqual(domain, 'staging.ripple.com');
callback(null, rippleTxtRes);
};
auth._getUser = function(url, callback) {
assert.strictEqual(url, 'https://id.staging.ripple.com/v1/authinfo?domain=staging.ripple.com&username=exampleUser');
callback(null, authInfoRes);
};
auth.get(exampleData.domain, exampleData.username, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'object');
assert.deepEqual(resp, authInfoRes.body);
done();
});
});
});
});
});
describe('VaultClient', function() {
var client = new VaultClient(exampleData.domain);
describe('initialization', function() {
it('should be initialized with a domain', function() {
var client = new VaultClient({ domain: exampleData.domain });
@@ -60,24 +118,21 @@ describe('VaultClient', function() {
assert.strictEqual(client.domain, 'ripple.com');
});
});
describe('#exists', function() {
it('should determine if a username exists on the domain', function(done) {
this.timeout(10000);
client.exists(exampleData.username, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'boolean');
assert.strictEqual(typeof resp, 'boolean');
done();
});
});
});
describe('#login', function() {
it('with username and password should retrive the blob, crypt key, and id', function(done) {
this.timeout(10000);
client.login(exampleData.username, exampleData.password, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'object');
assert(resp.blob instanceof Blob);
@@ -91,13 +146,12 @@ describe('VaultClient', function() {
});
});
});
describe('#relogin', function() {
it('should retrieve the decrypted blob with blob vault url, id, and crypt key', function(done) {
this.timeout(10000);
client.relogin(exampleData.blobURL, exampleData.id, exampleData.crypt, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'object');
assert(resp.blob instanceof Blob);
@@ -110,7 +164,6 @@ describe('VaultClient', function() {
it('should access the wallet secret using encryption secret, username and password', function(done) {
this.timeout(10000);
client.unlock(exampleData.username, exampleData.password, exampleData.encrypted_secret, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'object');
assert.equal(typeof resp.keys, 'object');
@@ -125,7 +178,6 @@ describe('VaultClient', function() {
it('should get the decrypted blob and decrypted secret given name and password', function(done) {
this.timeout(10000);
client.loginAndUnlock(exampleData.username, exampleData.password, function(err, resp) {
assert.ifError(err);
assert.equal(typeof resp, 'object');
assert(resp.blob instanceof Blob);
@@ -147,60 +199,17 @@ describe('VaultClient', function() {
describe('Blob', function() {
var vaultClient;
vaultClient = new VaultClient({ domain: exampleData.domain });
vaultClient.login(exampleData.username, exampleData.password, function(err,resp){
vaultClient.login(exampleData.username, exampleData.password, function(err,resp) {
assert.ifError(err);
var blob = resp.blob;
describe('#set', function() {
it('should set a new property in the blob', function(done) {
this.timeout(10000)
blob.extend("/testObject", {
foo : [],
}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#extend', function() {
it('should extend an object in the blob', function(done) {
this.timeout(10000)
blob.extend("/testObject", {
foobar : "baz",
}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#unset', function() {
it('should remove a property from the blob', function(done) {
this.timeout(10000)
blob.unset("/testObject", function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#unshift', function() {
it('should prepend an item to an array in the blob', function(done) {
this.timeout(10000)
blob.unshift("/testArray", {
name : "bob",
address : "1234"
blob.extend('/testObject', {
foo: [],
}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
@@ -208,35 +217,70 @@ describe('Blob', function() {
});
});
});
describe('#filter', function() {
it('should find a specific entity in an array and apply subcommands to it', function(done) {
describe('#extend', function() {
it('should extend an object in the blob', function(done) {
this.timeout(10000)
blob.filter('/testArray', 'name', 'bob', 'extend', '', {description:"Alice"}, function(err, resp){
blob.extend('/testObject', {
foobar: 'baz',
}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
});
describe('#unset', function() {
it('should remove a property from the blob', function(done) {
this.timeout(10000)
blob.unset('/testObject', function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#unshift', function() {
it('should prepend an item to an array in the blob', function(done) {
this.timeout(10000)
blob.unshift('/testArray', {
name: 'bob',
address: '1234'
}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#filter', function() {
it('should find a specific entity in an array and apply subcommands to it', function(done) {
this.timeout(10000)
blob.filter('/testArray', 'name', 'bob', 'extend', '', {description:'Alice'}, function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
describe('#consolidate', function() {
it('should consolidate and save changes to the blob', function(done) {
this.timeout(10000)
blob.unset('/testArray', function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
blob.consolidate(function(err, resp){
assert.ifError(err);
assert.equal(resp.result, 'success');
done();
});
});
});
});
});
});
});
});
});
});