mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2024-11-29 19:02:09 +01:00
Increase coverage of PGPCertificateDirectory
This commit is contained in:
parent
f34c6d7735
commit
4ce9f46846
2 changed files with 39 additions and 1 deletions
|
@ -21,6 +21,10 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the {@link PGPCertificateDirectory.Backend} which stores key material in-memory.
|
||||||
|
* It uses object locking with {@link #wait()} and {@link #notify()} to synchronize write-access.
|
||||||
|
*/
|
||||||
public class InMemoryCertificateDirectoryBackend implements PGPCertificateDirectory.Backend {
|
public class InMemoryCertificateDirectoryBackend implements PGPCertificateDirectory.Backend {
|
||||||
|
|
||||||
protected static class ObjectLockingMechanism implements PGPCertificateDirectory.LockingMechanism {
|
protected static class ObjectLockingMechanism implements PGPCertificateDirectory.LockingMechanism {
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class PGPCertificateDirectoryTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideTestSubjects")
|
@MethodSource("provideTestSubjects")
|
||||||
public void lockDirectoryAndInsertWillFail(PGPCertificateDirectory directory)
|
public void lockDirectoryAndTryInsertWillFail(PGPCertificateDirectory directory)
|
||||||
throws IOException, InterruptedException, BadDataException {
|
throws IOException, InterruptedException, BadDataException {
|
||||||
// Manually lock the dir
|
// Manually lock the dir
|
||||||
assertFalse(directory.backend.getLock().isLocked());
|
assertFalse(directory.backend.getLock().isLocked());
|
||||||
|
@ -86,6 +86,40 @@ public class PGPCertificateDirectoryTest {
|
||||||
assertNotNull(inserted);
|
assertNotNull(inserted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideTestSubjects")
|
||||||
|
public void lockDirectoryAndTryInsertTrustRootWillFail(PGPCertificateDirectory directory)
|
||||||
|
throws IOException, InterruptedException, BadDataException {
|
||||||
|
// Manually lock the dir
|
||||||
|
assertFalse(directory.backend.getLock().isLocked());
|
||||||
|
directory.backend.getLock().lockDirectory();
|
||||||
|
assertTrue(directory.backend.getLock().isLocked());
|
||||||
|
|
||||||
|
KeyMaterial inserted = directory.tryInsertTrustRoot(TestKeys.getHarryKey(), merger);
|
||||||
|
assertNull(inserted);
|
||||||
|
|
||||||
|
directory.backend.getLock().releaseDirectory();
|
||||||
|
inserted = directory.tryInsertTrustRoot(TestKeys.getHarryKey(), merger);
|
||||||
|
assertNotNull(inserted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideTestSubjects")
|
||||||
|
public void lockDirectoryAndTryInsertWithSpecialNameWillFail(PGPCertificateDirectory directory)
|
||||||
|
throws IOException, InterruptedException, BadDataException, BadNameException {
|
||||||
|
// Manually lock the dir
|
||||||
|
assertFalse(directory.backend.getLock().isLocked());
|
||||||
|
directory.backend.getLock().lockDirectory();
|
||||||
|
assertTrue(directory.backend.getLock().isLocked());
|
||||||
|
|
||||||
|
Certificate inserted = directory.tryInsertWithSpecialName(SpecialNames.TRUST_ROOT, TestKeys.getHarryKey(), merger);
|
||||||
|
assertNull(inserted);
|
||||||
|
|
||||||
|
directory.backend.getLock().releaseDirectory();
|
||||||
|
inserted = directory.tryInsertWithSpecialName(SpecialNames.TRUST_ROOT, TestKeys.getHarryKey(), merger);
|
||||||
|
assertNotNull(inserted);
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideTestSubjects")
|
@MethodSource("provideTestSubjects")
|
||||||
public void getByInvalidNameFails(PGPCertificateDirectory directory) {
|
public void getByInvalidNameFails(PGPCertificateDirectory directory) {
|
||||||
|
|
Loading…
Reference in a new issue