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(); }); });