mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-13 20:29:39 +02:00
Trim passphrases
This commit is contained in:
parent
a72cff28d8
commit
7e2c89b1b3
2 changed files with 73 additions and 1 deletions
|
@ -17,6 +17,7 @@ package org.pgpainless.key.protection;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
@ -37,4 +38,34 @@ public class PassphraseTest {
|
|||
assertFalse(passphrase.isValid());
|
||||
assertThrows(IllegalStateException.class, passphrase::getChars);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrimming() {
|
||||
Passphrase leadingSpace = Passphrase.fromPassword(" space");
|
||||
assertArrayEquals("space".toCharArray(), leadingSpace.getChars());
|
||||
assertFalse(leadingSpace.isEmpty());
|
||||
|
||||
Passphrase trailingSpace = Passphrase.fromPassword("space ");
|
||||
assertArrayEquals("space".toCharArray(), trailingSpace.getChars());
|
||||
assertFalse(trailingSpace.isEmpty());
|
||||
|
||||
Passphrase leadingTrailingWhitespace = new Passphrase("\t Such whitespace, much wow\n ".toCharArray());
|
||||
assertArrayEquals("Such whitespace, much wow".toCharArray(), leadingTrailingWhitespace.getChars());
|
||||
assertFalse(leadingTrailingWhitespace.isEmpty());
|
||||
|
||||
Passphrase fromEmptyChars = new Passphrase(" ".toCharArray());
|
||||
assertNull(fromEmptyChars.getChars());
|
||||
assertTrue(fromEmptyChars.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyPassphrase() {
|
||||
Passphrase empty = Passphrase.emptyPassphrase();
|
||||
assertNull(empty.getChars());
|
||||
assertTrue(empty.isEmpty());
|
||||
|
||||
Passphrase trimmedEmpty = Passphrase.fromPassword(" ");
|
||||
assertNull(trimmedEmpty.getChars());
|
||||
assertTrue(trimmedEmpty.isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue