aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-07-12 01:28:27 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-07-12 01:28:27 +0200
commitd4c1b781db6198fc8a99b29173d872d418032a67 (patch)
treeb2a02e06432a15b95d5b661d81077e64f0d9bbed
parent54bc874ce558866e70e54c0076cbee1f51823be7 (diff)
downloadopen-keychain-d4c1b781db6198fc8a99b29173d872d418032a67.tar.gz
open-keychain-d4c1b781db6198fc8a99b29173d872d418032a67.tar.bz2
open-keychain-d4c1b781db6198fc8a99b29173d872d418032a67.zip
test: add algorithm choice tests
-rw-r--r--.travis.yml4
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java74
-rw-r--r--settings.gradle2
3 files changed, 77 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml
index 673dd3876..fd6e55ea7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,6 +15,6 @@ before_install:
- ./install-custom-gradle-test-plugin.sh
install: echo "Installation done"
script:
- - gradle -PwithTesting=true assemble -S -q
- - gradle -PwithTesting=true --info OpenKeychain-Test:testDebug
+ - gradle assemble -S -q
+ - gradle --info OpenKeychain-Test:testDebug
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java
index 0cf16843a..e866e77c0 100644
--- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java
@@ -68,6 +68,8 @@ public class PgpKeyOperationTest {
OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
staticRing = op.createSecretKeyRing(parcel, log, 0);
+ Assert.assertNotNull("initial test key creation must succeed", staticRing);
+
// we sleep here for a second, to make sure all new certificates have different timestamps
Thread.sleep(1000);
}
@@ -88,6 +90,78 @@ public class PgpKeyOperationTest {
}
@Test
+ public void testAlgorithmChoice() {
+
+ OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
+
+ {
+ parcel.reset();
+ parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ Constants.choice.algorithm.rsa, new Random().nextInt(256)+255, KeyFlags.CERTIFY_OTHER, null));
+ parcel.mAddUserIds.add("shy");
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+
+ Assert.assertNull("creating ring with < 512 bytes keysize should fail", ring);
+ }
+
+ {
+ parcel.reset();
+ parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ Constants.choice.algorithm.elgamal, 1024, KeyFlags.CERTIFY_OTHER, null));
+ parcel.mAddUserIds.add("shy");
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+
+ Assert.assertNull("creating ring with ElGamal master key should fail", ring);
+ }
+
+ {
+ parcel.reset();
+ parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ 12345, 1024, KeyFlags.CERTIFY_OTHER, null));
+ parcel.mAddUserIds.add("shy");
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+ Assert.assertNull("creating ring with bad algorithm choice should fail", ring);
+ }
+
+ {
+ parcel.reset();
+ parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ Constants.choice.algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
+ parcel.mAddUserIds.add("shy");
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+ Assert.assertNull("creating ring with non-certifying master key should fail", ring);
+ }
+
+ {
+ parcel.reset();
+ parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ Constants.choice.algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+ Assert.assertNull("creating ring without user ids should fail", ring);
+ }
+
+ {
+ parcel.reset();
+ parcel.mAddUserIds.add("shy");
+ parcel.mNewPassphrase = "swag";
+
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+ Assert.assertNull("creating ring without subkeys should fail", ring);
+ }
+
+ }
+
+ @Test
// this is a special case since the flags are in user id certificates rather than
// subkey binding certificates
public void testMasterFlags() throws Exception {
diff --git a/settings.gradle b/settings.gradle
index 47385ed14..86088e04a 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,5 +1,5 @@
include ':OpenKeychain'
-if (hasProperty('withTesting') && withTesting) include ':OpenKeychain-Test'
+include ':OpenKeychain-Test'
include ':extern:openpgp-api-lib'
include ':extern:openkeychain-api-lib'
include ':extern:html-textview'