From 0f9540a645ef66f3cf67294f75ba2c5d9d80078e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 27 May 2024 20:59:20 +0530 Subject: feat(pgpainless): add detection for passphrase-less messages (#3069) * WIP: feat(pgpainless): add detection for passphrase-less messages * refactor: test keys instead of the message This makes more logical sense --- .../crypto/PGPainlessCryptoHandlerTest.kt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crypto/pgpainless/src/test') diff --git a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt index 5de2bf4f..600cc39d 100644 --- a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt +++ b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt @@ -155,6 +155,26 @@ class PGPainlessCryptoHandlerTest { assertIs(res.error, message = "${res.error.cause}") } + @Test + fun detectsKeysWithPassphrase() { + assertTrue(cryptoHandler.isPassphraseProtected(listOf(PGPKey(TestUtils.getArmoredSecretKey())))) + assertTrue( + cryptoHandler.isPassphraseProtected( + listOf(PGPKey(TestUtils.getArmoredSecretKeyWithMultipleIdentities())) + ) + ) + } + + @Test + fun detectsKeysWithoutPassphrase() { + // Uses the internal method instead of the public API because GnuPG seems to have made it + // impossible to generate a key without a passphrase and I can't care to find a magical + // incantation to convince it I am smarter than whatever they are protecting against. + assertFalse( + cryptoHandler.keyringHasPassphrase(PGPainless.generateKeyRing().modernKeyRing("John Doe")) + ) + } + @Test fun canHandleFiltersFormats() { assertFalse { cryptoHandler.canHandle("example.com") } -- cgit v1.2.3