Check valid email address earlier in pgp.parseUserIds

This commit is contained in:
Tankred Hase 2016-06-10 18:43:09 +02:00
parent f1bf3caa20
commit 12b65e0ce2
2 changed files with 8 additions and 7 deletions

View File

@ -123,15 +123,15 @@ class PGP {
oneValid = true; oneValid = true;
} }
} }
if (oneValid) { if (oneValid && user.userId && user.userId.userid) {
result = result.concat(addressparser(user.userId.userid)); let uid = addressparser(user.userId.userid)[0];
if (util.isEmail(uid.address)) {
result.push(uid);
}
} }
} }
// map to local user id object format // map to local user id object format
return result.map(uid => { return result.map(uid => {
if (!util.isEmail(uid.address)) {
util.throw(400, 'Invalid PGP key: invalid email address');
}
return { return {
name: uid.name, name: uid.name,
email: uid.address.toLowerCase(), email: uid.address.toLowerCase(),

View File

@ -182,8 +182,9 @@ describe('PGP Unit Tests', () => {
it('should throw for a invalid email address', () => { it('should throw for a invalid email address', () => {
let verifyStub = sinon.stub(key.users[0], 'isValidSelfCertificate').returns(true); let verifyStub = sinon.stub(key.users[0], 'isValidSelfCertificate').returns(true);
key.users[0].userId.userid = 'safewithme.testusergmail.com'; key.users[0].userId.userid = 'safewithme testuser <safewithme.testusergmail.com>';
expect(pgp.parseUserIds.bind(pgp, key.users, key.primaryKey)).to.throw(/invalid email address/); let parsed = pgp.parseUserIds(key.users, key.primaryKey);
expect(parsed.length).to.equal(0);
verifyStub.restore(); verifyStub.restore();
}); });
}); });