mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Fix tests
This commit is contained in:
parent
801766ce04
commit
289cf6ddee
3 changed files with 9 additions and 8 deletions
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue