mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-16 01:12:05 +01:00
Increase test coverage
This commit is contained in:
parent
dff47d17d1
commit
9637ef5d35
4 changed files with 57 additions and 0 deletions
|
@ -16,7 +16,9 @@
|
||||||
package org.pgpainless.key.protection;
|
package org.pgpainless.key.protection;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
@ -68,4 +70,20 @@ public class PassphraseTest {
|
||||||
assertNull(trimmedEmpty.getChars());
|
assertNull(trimmedEmpty.getChars());
|
||||||
assertTrue(trimmedEmpty.isEmpty());
|
assertTrue(trimmedEmpty.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsTest() {
|
||||||
|
assertNotEquals(Passphrase.fromPassword("passphrase"), Passphrase.fromPassword("Password"));
|
||||||
|
assertNotEquals(Passphrase.fromPassword("password"), null);
|
||||||
|
assertNotEquals(Passphrase.fromPassword("password"), "password");
|
||||||
|
Passphrase passphrase = Passphrase.fromPassword("passphrase");
|
||||||
|
assertEquals(passphrase, passphrase);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hashCodeTest() {
|
||||||
|
assertNotEquals(0, Passphrase.fromPassword("passphrase").hashCode());
|
||||||
|
assertNotEquals(Passphrase.fromPassword("passphrase").hashCode(), Passphrase.fromPassword("password").hashCode());
|
||||||
|
assertEquals(0, Passphrase.emptyPassphrase().hashCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.pgpainless.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -26,8 +27,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
|
import org.pgpainless.key.TestKeys;
|
||||||
|
|
||||||
public class ArmorUtilsTest {
|
public class ArmorUtilsTest {
|
||||||
|
|
||||||
|
@ -89,4 +93,31 @@ public class ArmorUtilsTest {
|
||||||
assertThrows(IllegalArgumentException.class, () -> ArmorUtils.addMessageIdHeader(armor, "contains spaces 7890123456789012"));
|
assertThrows(IllegalArgumentException.class, () -> ArmorUtils.addMessageIdHeader(armor, "contains spaces 7890123456789012"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> ArmorUtils.addMessageIdHeader(armor, "contains\nnewlines\n12345678901234"));
|
assertThrows(IllegalArgumentException.class, () -> ArmorUtils.addMessageIdHeader(armor, "contains\nnewlines\n12345678901234"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddCommentAndHashHeaders() throws PGPException, IOException {
|
||||||
|
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ArmoredOutputStream armor = new ArmoredOutputStream(out);
|
||||||
|
ArmorUtils.addCommentHeader(armor, "This is a comment.");
|
||||||
|
ArmorUtils.addHashAlgorithmHeader(armor, HashAlgorithm.SHA224);
|
||||||
|
|
||||||
|
secretKeys.encode(armor);
|
||||||
|
armor.close();
|
||||||
|
|
||||||
|
String armored = out.toString();
|
||||||
|
assertTrue(armored.contains("Hash: SHA224"));
|
||||||
|
assertTrue(armored.contains("Comment: This is a comment."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toAsciiArmoredString() throws PGPException, IOException {
|
||||||
|
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
|
||||||
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
|
secretKeys.encode(bytes);
|
||||||
|
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(bytes.toByteArray());
|
||||||
|
String ascii = ArmorUtils.toAsciiArmoredString(in);
|
||||||
|
assertTrue(ascii.startsWith("-----BEGIN PGP PRIVATE KEY BLOCK-----\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,5 +128,6 @@ public class MultiMapTest {
|
||||||
assertEquals(fromMap.get("key"), Collections.singleton("value"));
|
assertEquals(fromMap.get("key"), Collections.singleton("value"));
|
||||||
|
|
||||||
assertNotEquals(fromMap, map);
|
assertNotEquals(fromMap, map);
|
||||||
|
assertNotEquals(fromMap, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package org.pgpainless.util;
|
package org.pgpainless.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -37,4 +38,10 @@ public class NotationRegistryTest {
|
||||||
assertFalse(registry.isKnownNotation("proof@metacode.biz"), "Notation is no longer known after registry is cleared.");
|
assertFalse(registry.isKnownNotation("proof@metacode.biz"), "Notation is no longer known after registry is cleared.");
|
||||||
assertFalse(registry.isKnownNotation("unknown@notation.data"));
|
assertFalse(registry.isKnownNotation("unknown@notation.data"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addKnownNotation_nullThrows() {
|
||||||
|
NotationRegistry registry = new NotationRegistry();
|
||||||
|
assertThrows(NullPointerException.class, () -> registry.addKnownNotation(null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue