mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
test: get rid of some SaveKeyringParcel boilerplate
This commit is contained in:
parent
26f6d58284
commit
bb92fe2804
@ -43,6 +43,7 @@ public class PgpKeyOperationTest {
|
||||
static UncachedKeyRing staticRing;
|
||||
UncachedKeyRing ring;
|
||||
PgpKeyOperation op;
|
||||
SaveKeyringParcel parcel;
|
||||
ArrayList<RawPacket> onlyA = new ArrayList<RawPacket>();
|
||||
ArrayList<RawPacket> onlyB = new ArrayList<RawPacket>();
|
||||
|
||||
@ -72,6 +73,11 @@ public class PgpKeyOperationTest {
|
||||
// setting up some parameters just to reduce code duplication
|
||||
op = new PgpKeyOperation(null);
|
||||
|
||||
// set this up, gonna need it more than once
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,10 +101,6 @@ public class PgpKeyOperationTest {
|
||||
@Test
|
||||
public void testCreatedKey() throws Exception {
|
||||
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
|
||||
// an empty modification should change nothing. this also ensures the keyring
|
||||
// is constant through canonicalization.
|
||||
// applyModificationWithChecks(parcel, ring, onlyA, onlyB);
|
||||
@ -141,9 +143,6 @@ public class PgpKeyOperationTest {
|
||||
@Test
|
||||
public void testSubkeyAdd() throws Exception {
|
||||
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
|
||||
|
||||
applyModificationWithChecks(parcel, ring, onlyA, onlyB);
|
||||
@ -169,9 +168,6 @@ public class PgpKeyOperationTest {
|
||||
@Test
|
||||
public void testSubkeyRevoke() throws Exception {
|
||||
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
{
|
||||
Iterator<UncachedPublicKey> it = ring.getPublicKeys();
|
||||
it.next();
|
||||
@ -203,9 +199,6 @@ public class PgpKeyOperationTest {
|
||||
|
||||
{ // revoke second user id
|
||||
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
parcel.revokeUserIds.add(uid);
|
||||
|
||||
modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB);
|
||||
@ -226,9 +219,8 @@ public class PgpKeyOperationTest {
|
||||
}
|
||||
|
||||
{ // re-add second user id
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
// new parcel
|
||||
parcel.reset();
|
||||
parcel.addUserIds.add(uid);
|
||||
|
||||
applyModificationWithChecks(parcel, modified, onlyA, onlyB, true, false);
|
||||
@ -265,9 +257,6 @@ public class PgpKeyOperationTest {
|
||||
@Test
|
||||
public void testUserIdAdd() throws Exception {
|
||||
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
parcel.addUserIds.add("rainbow");
|
||||
|
||||
UncachedKeyRing modified = applyModificationWithChecks(parcel, ring, onlyA, onlyB);
|
||||
@ -304,9 +293,6 @@ public class PgpKeyOperationTest {
|
||||
String uid = ring.getPublicKey().getUnorderedUserIds().get(1);
|
||||
|
||||
{ // first part, add new user id which is also primary
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = modified.getMasterKeyId();
|
||||
parcel.mFingerprint = modified.getFingerprint();
|
||||
parcel.addUserIds.add("jack");
|
||||
parcel.changePrimaryUserId = "jack";
|
||||
|
||||
@ -317,9 +303,7 @@ public class PgpKeyOperationTest {
|
||||
}
|
||||
|
||||
{ // second part, change primary to a different one
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
parcel.reset();
|
||||
parcel.changePrimaryUserId = uid;
|
||||
|
||||
modified = applyModificationWithChecks(parcel, modified, onlyA, onlyB);
|
||||
@ -332,9 +316,7 @@ public class PgpKeyOperationTest {
|
||||
}
|
||||
|
||||
{ // third part, change primary to a non-existent one
|
||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||
parcel.mMasterKeyId = ring.getMasterKeyId();
|
||||
parcel.mFingerprint = ring.getFingerprint();
|
||||
parcel.reset();
|
||||
//noinspection SpellCheckingInspection
|
||||
parcel.changePrimaryUserId = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
|
||||
|
@ -39,11 +39,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public ArrayList<Long> revokeSubKeys;
|
||||
|
||||
public SaveKeyringParcel() {
|
||||
addUserIds = new ArrayList<String>();
|
||||
addSubKeys = new ArrayList<SubkeyAdd>();
|
||||
changeSubKeys = new ArrayList<SubkeyChange>();
|
||||
revokeUserIds = new ArrayList<String>();
|
||||
revokeSubKeys = new ArrayList<Long>();
|
||||
reset();
|
||||
}
|
||||
|
||||
public SaveKeyringParcel(long masterKeyId, byte[] fingerprint) {
|
||||
@ -52,6 +48,16 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
mFingerprint = fingerprint;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
newPassphrase = null;
|
||||
addUserIds = new ArrayList<String>();
|
||||
addSubKeys = new ArrayList<SubkeyAdd>();
|
||||
changePrimaryUserId = null;
|
||||
changeSubKeys = new ArrayList<SubkeyChange>();
|
||||
revokeUserIds = new ArrayList<String>();
|
||||
revokeSubKeys = new ArrayList<Long>();
|
||||
}
|
||||
|
||||
// performance gain for using Parcelable here would probably be negligible,
|
||||
// use Serializable instead.
|
||||
public static class SubkeyAdd implements Serializable {
|
||||
|
Loading…
Reference in New Issue
Block a user