SEA User.auth test cases done & bug fixed

This commit is contained in:
Mika Helander 2017-08-29 23:55:24 +03:00
parent b74a0268d0
commit 68f5725899
2 changed files with 8375 additions and 8313 deletions

6
sea.js
View File

@ -140,7 +140,7 @@
root.get(key).get(function(at, ev){ root.get(key).get(function(at, ev){
key = key.slice(4); key = key.slice(4);
ev.off(); ev.off();
if(!at.put){ return reject({err: 'Public key does not exist!'}) } if(!at.put){return}
// attempt to PBKDF2 extend the password with the salt. (Verifying the signature gives us the plain text salt.) // attempt to PBKDF2 extend the password with the salt. (Verifying the signature gives us the plain text salt.)
SEA.read(at.put.salt, key).then(function(salt){ SEA.read(at.put.salt, key).then(function(salt){
return SEA.proof(pass, salt); return SEA.proof(pass, salt);
@ -198,10 +198,14 @@
return; return;
} }
// Or else we failed to log in... // Or else we failed to log in...
}).catch(function(e){
Gun.log('Failed to sign in!'); Gun.log('Failed to sign in!');
reject({err: 'Attempt failed'}); reject({err: 'Attempt failed'});
}); });
}); });
// if (!found) {
// reject({err: 'Public key does not exist!'})
// }
}); });
}); });
}; };

View File

@ -8038,6 +8038,7 @@ describe('Gun', function(){
var alias = 'dude'; var alias = 'dude';
var pass = 'my secret password'; var pass = 'my secret password';
var user = Gun().user(); var user = Gun().user();
Gun.log.off = true; // Supress all console logging
['callback', 'Promise'].forEach(function(type){ ['callback', 'Promise'].forEach(function(type){
describe(type, function(){ describe(type, function(){
@ -8057,8 +8058,7 @@ describe('Gun', function(){
} }
}); });
it('conflict', function(done){ it('conflict', function(done){
var gunLog = Gun.log; // Temporarily removing logging Gun.log.off = true; // Supress all console logging
Gun.log = function(){};
var check = function(ack){ var check = function(ack){
expect(ack).to.not.be(undefined); expect(ack).to.not.be(undefined);
expect(ack).to.not.be(''); expect(ack).to.not.be('');
@ -8075,7 +8075,6 @@ describe('Gun', function(){
done('Failed to decline creating existing user!'); done('Failed to decline creating existing user!');
}).catch(check); }).catch(check);
} }
Gun.log = gunLog;
}); });
}); });
@ -8087,28 +8086,86 @@ describe('Gun', function(){
expect(ack).to.not.have.key('err'); expect(ack).to.not.have.key('err');
done(); done();
}; };
var props = {alias: alias+'-'+type, pass: pass}; var props = {alias: alias+type, pass: pass};
user.create(props.alias, props.pass).catch(function(){}) // Gun.user.auth - authenticates existing user
.then(function(){
// Gun.user.create - creates new user
if(type === 'callback'){ if(type === 'callback'){
user.auth(props, check); user.auth(props, check);
} else { } else {
user.auth(props).then(check).catch(done); user.auth(props).then(check).catch(done);
} }
}); });
it('wrong password', function(done){
var check = function(ack){
expect(ack).to.not.be(undefined);
expect(ack).to.not.be('');
expect(ack).to.have.key('err');
expect(ack.err).to.not.be(undefined);
expect(ack.err).to.not.be('');
done();
};
var props = {alias: alias+type, pass: pass+'not'};
if(type === 'callback'){
user.auth(props, check);
} else {
user.auth(props).then(function(ack){
done('Unexpected login success!');
}).catch(check);
}
}); });
it.skip('failed login', function(done){ it('unknown alias', function(done){
var check = function(ack){
expect(ack).to.not.be(undefined);
expect(ack).to.not.be('');
expect(ack).to.have.key('err');
expect(ack.err).to.not.be(undefined);
expect(ack.err).to.not.be('');
done(); done();
};
var props = {alias: alias+type+'not', pass: pass};
if(type === 'callback'){
user.auth(props, check);
} else {
user.auth(props).then(function(ack){
done('Unexpected login success!');
}).catch(check);
}
}); });
it.skip('new password', function(done){ it('new password', function(done){
var check = function(ack){
expect(ack).to.not.be(undefined);
expect(ack).to.not.be('');
expect(ack).to.not.have.key('err');
done(); done();
};
var props = {alias: alias+type, pass: pass, newpass: pass+' new'};
// Gun.user.auth - with newpass props sets new password
if(type === 'callback'){
user.auth(props, check);
} else {
user.auth(props).then(check).catch(done);
}
}); });
it.skip('failed new password', function(done){ it('failed new password', function(done){
var check = function(ack){
expect(ack).to.not.be(undefined);
expect(ack).to.not.be('');
expect(ack).to.have.key('err');
expect(ack.err).to.not.be(undefined);
expect(ack.err).to.not.be('');
done(); done();
};
var props = {alias: alias+type, pass: pass+'not', newpass: pass+' new'};
if(type === 'callback'){
user.auth(props, check);
} else {
user.auth(props).then(function(ack){
done('Unexpected password change success!');
}).catch(check);
}
}); });
}); });
@ -8119,6 +8176,7 @@ describe('Gun', function(){
}); });
}); });
}); });
Gun.log.off = false;
}); });
describe('Streams', function(){ describe('Streams', function(){