From 12b65e0ce2d071fb150473ba3f98313af1419586 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 10 Jun 2016 18:43:09 +0200 Subject: [PATCH] Check valid email address earlier in pgp.parseUserIds --- src/service/pgp.js | 10 +++++----- test/unit/pgp-test.js | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/service/pgp.js b/src/service/pgp.js index ff89dd9..d182b13 100644 --- a/src/service/pgp.js +++ b/src/service/pgp.js @@ -123,15 +123,15 @@ class PGP { oneValid = true; } } - if (oneValid) { - result = result.concat(addressparser(user.userId.userid)); + if (oneValid && user.userId && 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 return result.map(uid => { - if (!util.isEmail(uid.address)) { - util.throw(400, 'Invalid PGP key: invalid email address'); - } return { name: uid.name, email: uid.address.toLowerCase(), diff --git a/test/unit/pgp-test.js b/test/unit/pgp-test.js index 4607237..d4b31c1 100644 --- a/test/unit/pgp-test.js +++ b/test/unit/pgp-test.js @@ -182,8 +182,9 @@ describe('PGP Unit Tests', () => { it('should throw for a invalid email address', () => { let verifyStub = sinon.stub(key.users[0], 'isValidSelfCertificate').returns(true); - key.users[0].userId.userid = 'safewithme.testusergmail.com'; - expect(pgp.parseUserIds.bind(pgp, key.users, key.primaryKey)).to.throw(/invalid email address/); + key.users[0].userId.userid = 'safewithme testuser '; + let parsed = pgp.parseUserIds(key.users, key.primaryKey); + expect(parsed.length).to.equal(0); verifyStub.restore(); }); });