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