mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-27 13:28:00 +01:00
Add JUnit tests for user-id addition/deletion
This commit is contained in:
parent
6159428c9a
commit
cb3190a0fc
2 changed files with 58 additions and 3 deletions
|
@ -18,17 +18,21 @@ package org.pgpainless.key.modification;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.collection.PGPKeyRing;
|
||||
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
||||
public class AddUserIdTest {
|
||||
|
@ -52,8 +56,33 @@ public class AddUserIdTest {
|
|||
assertEquals("cheshirecat@wonderland.lit", userIds.next());
|
||||
assertFalse(userIds.hasNext());
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
// System.out.println(KeyPrinter.toAsciiArmoredString(secretKeys));
|
||||
// CHECKSTYLE:ON
|
||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||
.deleteUserId("cheshirecat@wonderland.lit", protector)
|
||||
.done();
|
||||
|
||||
userIds = secretKeys.getPublicKey().getUserIDs();
|
||||
assertEquals("alice@wonderland.lit", userIds.next());
|
||||
assertFalse(userIds.hasNext());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
public void addUserId_NoSuchElementExceptionForMissingKey() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
|
||||
PGPainless.modifyKeyRing(secretKeys)
|
||||
.addUserId(0L, TestKeys.CRYPTIE_UID, new UnprotectedKeysProtector());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
public void deleteUserId_noSuchElementExceptionForMissingUserId() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
|
||||
PGPainless.modifyKeyRing(secretKeys)
|
||||
.deleteUserId("invalid@user.id", new UnprotectedKeysProtector());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
public void deleteUserId_noSuchElementExceptionForMissingKey() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
|
||||
PGPainless.modifyKeyRing(secretKeys)
|
||||
.deleteUserId(0L, TestKeys.CRYPTIE_UID, new UnprotectedKeysProtector());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2020 Paul Schaub.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pgpainless.key.modification;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyRingEditorTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testConstructorThrowsNpeForNull() {
|
||||
new KeyRingEditor(null);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue