1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 02:09:38 +02:00

Fix tests

This commit is contained in:
Paul Schaub 2025-07-30 14:01:54 +02:00
parent 801766ce04
commit 289cf6ddee
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 9 additions and 8 deletions

View file

@ -40,7 +40,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
.addUserId(UserId.onlyEmail("primary@user.id")) .addUserId(UserId.onlyEmail("primary@user.id"))
.addUserId(UserId.onlyEmail("additional@user.id")) .addUserId(UserId.onlyEmail("additional@user.id"))
.addUserId(UserId.onlyEmail("additional2@user.id")) .addUserId(UserId.onlyEmail("additional2@user.id"))
.addUserId("\ttrimThis@user.id ") .addUserId("\tdoNotTrim@user.id ")
.setExpirationDate(expiration) .setExpirationDate(expiration)
.build() .build()
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
@ -52,7 +52,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
assertEquals("<primary@user.id>", userIds.next()); assertEquals("<primary@user.id>", userIds.next());
assertEquals("<additional@user.id>", userIds.next()); assertEquals("<additional@user.id>", userIds.next());
assertEquals("<additional2@user.id>", userIds.next()); assertEquals("<additional2@user.id>", userIds.next());
assertEquals("trimThis@user.id", userIds.next()); assertEquals("\tdoNotTrim@user.id ", userIds.next());
assertFalse(userIds.hasNext()); assertFalse(userIds.hasNext());
} }
} }

View file

@ -34,19 +34,19 @@ public class PassphraseTest {
@Test @Test
public void testTrimming() { public void testTrimming() {
Passphrase leadingSpace = Passphrase.fromPassword(" space"); Passphrase leadingSpace = Passphrase.fromPassword(" space").withTrimmedWhitespace();
assertArrayEquals("space".toCharArray(), leadingSpace.getChars()); assertArrayEquals("space".toCharArray(), leadingSpace.getChars());
assertFalse(leadingSpace.isEmpty()); assertFalse(leadingSpace.isEmpty());
Passphrase trailingSpace = Passphrase.fromPassword("space "); Passphrase trailingSpace = Passphrase.fromPassword("space ").withTrimmedWhitespace();
assertArrayEquals("space".toCharArray(), trailingSpace.getChars()); assertArrayEquals("space".toCharArray(), trailingSpace.getChars());
assertFalse(trailingSpace.isEmpty()); assertFalse(trailingSpace.isEmpty());
Passphrase leadingTrailingWhitespace = new Passphrase("\t Such whitespace, much wow\n ".toCharArray()); Passphrase leadingTrailingWhitespace = new Passphrase("\t Such whitespace, much wow\n ".toCharArray()).withTrimmedWhitespace();
assertArrayEquals("Such whitespace, much wow".toCharArray(), leadingTrailingWhitespace.getChars()); assertArrayEquals("Such whitespace, much wow".toCharArray(), leadingTrailingWhitespace.getChars());
assertFalse(leadingTrailingWhitespace.isEmpty()); assertFalse(leadingTrailingWhitespace.isEmpty());
Passphrase fromEmptyChars = new Passphrase(" ".toCharArray()); Passphrase fromEmptyChars = new Passphrase(" ".toCharArray()).withTrimmedWhitespace();
assertNull(fromEmptyChars.getChars()); assertNull(fromEmptyChars.getChars());
assertTrue(fromEmptyChars.isEmpty()); assertTrue(fromEmptyChars.isEmpty());
} }
@ -54,7 +54,7 @@ public class PassphraseTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"", " ", " ", "\t", "\t\t"}) @ValueSource(strings = {"", " ", " ", "\t", "\t\t"})
public void testEmptyPassphrases(String empty) { public void testEmptyPassphrases(String empty) {
Passphrase passphrase = Passphrase.fromPassword(empty); Passphrase passphrase = Passphrase.fromPassword(empty).withTrimmedWhitespace();
assertTrue(passphrase.isEmpty()); assertTrue(passphrase.isEmpty());
assertEquals(Passphrase.emptyPassphrase(), passphrase); assertEquals(Passphrase.emptyPassphrase(), passphrase);

View file

@ -152,7 +152,8 @@ class EncryptImpl(private val api: PGPainless) : Encrypt {
} }
override fun withPassword(password: String): Encrypt = apply { override fun withPassword(password: String): Encrypt = apply {
encryptionOptions.addMessagePassphrase(Passphrase.fromPassword(password).withTrimmedWhitespace()) encryptionOptions.addMessagePassphrase(
Passphrase.fromPassword(password).withTrimmedWhitespace())
} }
private fun modeToStreamEncoding(mode: EncryptAs): StreamEncoding { private fun modeToStreamEncoding(mode: EncryptAs): StreamEncoding {