From 2f28e501ab5743b53b6d1c5e3bf17def4c71e2e7 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Fri, 25 Mar 2022 23:17:13 +0100 Subject: [PATCH] Add tests for signature verification failure --- test/signatures.test.js | 58 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/test/signatures.test.js b/test/signatures.test.js index d37ae66..1ea3ee5 100644 --- a/test/signatures.test.js +++ b/test/signatures.test.js @@ -39,16 +39,72 @@ YCKJPotiqe50nBijHHbuABtBianiMZOm2BbaPnsmdHIX5ynWhOI8LHR1CVmTI/0o =2vuM -----END PGP SIGNATURE-----` +const invalidSigProfileMessage = `-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +A demo signature profile for testing. + +proof=dns:doip.sucks +-----BEGIN PGP SIGNATURE----- + +iQHEBAEBCgAuFiEENjcgJSPnwTCat56Z7y3FgntEX0sFAmI+LCEQHHRlc3RAZG9p +cC5yb2NrcwAKCRDvLcWCe0RfS2KIC/9wGOnntH4jBBO3unLWb0dQLUguo9XilHGp +Uh4Huue5/nlbmkCNMJFKkRiohYGaySIN4xBU8R4gWwzA8hbqTj9XII5en5VzHqkt +ZONRabicA6rdr4DNzV/UzB0Hz2vdxCLZAICLik6NyScjNE+EybITg/gHjrDrzyEe +hmNCSuUo/PA0oGY1ckduhy9hwFULdEWcyDvM4wIaAh5A53UJ+ndZVxlguCixqnQH +JBXuDQdDOFJRrT7Objdgd/8CI+NEm0iwIlcsaITwG6Twx0ki5NTWftmIg3DoiTEz +svBu6SMrlwbZ7nkRdSZhHp0zrEBOafT1AcFGquF63AlfPuC46rNWTAYvtyU6Cn3P +MeErGzZgOkW9vLbFS+GHaX0ODr01xMMCdvdjPc/o+3sBqkw3d2DctSTLKOx7strh +YCKJPotiqe50nBijHHbuABtBianiMZOm2BbaPnsmdHIX5ynWhOI8LHR1CVmTI/0o +/ilSykmWgvLSdPk5K+i3deQ1wESZeGU= +=2vuM +-----END PGP SIGNATURE-----` + +const invalidSigProfileHash = `-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +A demo signature profile for testing. + +proof=dns:doip.rocks +-----BEGIN PGP SIGNATURE----- + +xQHEBAEBCgAuFiEENjcgJSPnwTCat56Z7y3FgntEX0sFAmI+LCEQHHRlc3RAZG9p +cC5yb2NrcwAKCRDvLcWCe0RfS2KIC/9wGOnntH4jBBO3unLWb0dQLUguo9XilHGp +Uh4Huue5/nlbmkCNMJFKkRiohYGaySIN4xBU8R4gWwzA8hbqTj9XII5en5VzHqkt +ZONRabicA6rdr4DNzV/UzB0Hz2vdxCLZAICLik6NyScjNE+EybITg/gHjrDrzyEe +hmNCSuUo/PA0oGY1ckduhy9hwFULdEWcyDvM4wIaAh5A53UJ+ndZVxlguCixqnQH +JBXuDQdDOFJRrT7Objdgd/8CI+NEm0iwIlcsaITwG6Twx0ki5NTWftmIg3DoiTEz +svBu6SMrlwbZ7nkRdSZhHp0zrEBOafT1AcFGquF63AlfPuC46rNWTAYvtyU6Cn3P +MeErGzZgOkW9vLbFS+GHaX0ODr01xMMCdvdjPc/o+3sBqkw3d2DctSTLKOx7strh +YCKJPotiqe50nBijHHbuABtBianiMZOm2BbaPnsmdHIX5ynWhOI8LHR1CVmTI/0o +/ilSykmWgvLSdPk5K+i3deQ1wESZeGU= +=2vuM +-----END PGP SIGNATURE-----` + describe('signatures.process', () => { it('should be a function (2 arguments)', () => { expect(doipjs.signatures.process).to.be.a('function') expect(doipjs.signatures.process).to.have.length(1) }) - it('should verify the demonstration signature', async () => { + it('should verify a valid signature', async () => { const verification = await doipjs.signatures.process(sigProfile) expect(verification.fingerprint).to.be.equal( '3637202523e7c1309ab79e99ef2dc5827b445f4b' ) expect(verification.users[0].claims).to.be.length(1) }) + it('should reject an invalid signature', async () => { + return expect( + doipjs.signatures.process(invalidSigProfileMessage) + ).to.eventually.be.rejectedWith( + 'Signature could not be verified (Signed digest did not match)' + ) + }) + it('should reject an invalid signature', async () => { + return expect( + doipjs.signatures.process(invalidSigProfileHash) + ).to.eventually.be.rejectedWith( + 'Signature could not be read (Ascii armor integrity check failed)' + ) + }) })