Use static passphrases in tests

This commit is contained in:
Christian Hagau 2018-07-22 00:00:00 +00:00
parent 5d28cef81a
commit 2e50e117ed
6 changed files with 23 additions and 23 deletions

View file

@ -79,11 +79,9 @@ import static org.mockito.Mockito.when;
@RunWith(KeychainTestRunner.class) @RunWith(KeychainTestRunner.class)
public class BackupOperationTest { public class BackupOperationTest {
static Passphrase mPassphrase = TestingUtils.genPassphrase(true); static Passphrase mPassphrase = TestingUtils.testPassphrase0;
static UncachedKeyRing mStaticRing1, mStaticRing2; static UncachedKeyRing mStaticRing1, mStaticRing2;
static Passphrase mKeyPhrase1 = TestingUtils.genPassphrase(true);
static Passphrase mKeyPhrase2 = TestingUtils.genPassphrase(true);
static PrintStream oldShadowStream; static PrintStream oldShadowStream;
@ -104,7 +102,7 @@ public class BackupOperationTest {
builder.addSubkeyAdd(SubkeyAdd.createSubkeyAdd( builder.addSubkeyAdd(SubkeyAdd.createSubkeyAdd(
Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L)); Algorithm.ECDH, 0, SaveKeyringParcel.Curve.NIST_P256, KeyFlags.ENCRYPT_COMMS, 0L));
builder.addUserId("snips"); builder.addUserId("snips");
builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(mKeyPhrase1)); builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(mPassphrase));
PgpEditKeyResult result = op.createSecretKeyRing(builder.build()); PgpEditKeyResult result = op.createSecretKeyRing(builder.build());
assertTrue("initial test key creation must succeed", result.success()); assertTrue("initial test key creation must succeed", result.success());

View file

@ -57,8 +57,8 @@ import org.sufficientlysecure.keychain.util.TestingUtils;
public class CertifyOperationTest { public class CertifyOperationTest {
static UncachedKeyRing mStaticRing1, mStaticRing2; static UncachedKeyRing mStaticRing1, mStaticRing2;
static Passphrase mKeyPhrase1 = TestingUtils.genPassphrase(true); static Passphrase mKeyPhrase1 = TestingUtils.testPassphrase1;
static Passphrase mKeyPhrase2 = TestingUtils.genPassphrase(true); static Passphrase mKeyPhrase2 = TestingUtils.testPassphrase2;
static PrintStream oldShadowStream; static PrintStream oldShadowStream;

View file

@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.util.TestingUtils;
public class PromoteKeyOperationTest { public class PromoteKeyOperationTest {
static UncachedKeyRing mStaticRing; static UncachedKeyRing mStaticRing;
static Passphrase mKeyPhrase1 = TestingUtils.genPassphrase(true); static Passphrase mKeyPhrase1 = TestingUtils.testPassphrase1;
static PrintStream oldShadowStream; static PrintStream oldShadowStream;

View file

@ -73,7 +73,7 @@ import static org.hamcrest.core.Is.is;
@RunWith(KeychainTestRunner.class) @RunWith(KeychainTestRunner.class)
public class PgpEncryptDecryptTest { public class PgpEncryptDecryptTest {
static Passphrase mSymmetricPassphrase = TestingUtils.genPassphrase(true); static Passphrase mSymmetricPassphrase = TestingUtils.testPassphrase0;
static UncachedKeyRing mStaticRing1, mStaticRing2, mStaticRingInsecure; static UncachedKeyRing mStaticRing1, mStaticRing2, mStaticRingInsecure;
static Passphrase mKeyPhrase1, mKeyPhrase2; static Passphrase mKeyPhrase1, mKeyPhrase2;
@ -165,7 +165,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testSymmetricEncryptDecrypt() { public void testSymmetricEncryptDecrypt() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with a given passphrase { // encrypt data with a given passphrase
@ -291,7 +291,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testAsymmetricSignLiteral() { public void testAsymmetricSignLiteral() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with key { // encrypt data with key
@ -346,7 +346,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testAsymmetricSignCleartext() { public void testAsymmetricSignCleartext() {
String plaintext = "dies ist ein\r\nplaintext\n ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein\r\nplaintext\n ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with key { // encrypt data with key
@ -407,7 +407,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testAsymmetricSignDetached() { public void testAsymmetricSignDetached() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] detachedSignature; byte[] detachedSignature;
{ // encrypt data with key { // encrypt data with key
@ -464,7 +464,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testAsymmetricEncryptDecrypt() { public void testAsymmetricEncryptDecrypt() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with key { // encrypt data with key
@ -563,7 +563,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testMultiSubkeyEncryptSkipStripOrBadFlag() throws Exception { public void testMultiSubkeyEncryptSkipStripOrBadFlag() throws Exception {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
long encKeyId1; long encKeyId1;
@ -670,7 +670,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testMultiSubkeyEncryptSkipRevoked() throws Exception { public void testMultiSubkeyEncryptSkipRevoked() throws Exception {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
{ // revoke first encryption subkey of keyring in database { // revoke first encryption subkey of keyring in database
SaveKeyringParcel.Builder builder = SaveKeyringParcel.buildChangeKeyringParcel( SaveKeyringParcel.Builder builder = SaveKeyringParcel.buildChangeKeyringParcel(
@ -727,7 +727,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testMultiAsymmetricEncryptDecrypt() { public void testMultiAsymmetricEncryptDecrypt() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with a given passphrase { // encrypt data with a given passphrase
@ -855,7 +855,7 @@ public class PgpEncryptDecryptTest {
@Test @Test
public void testMultiAsymmetricSignEncryptDecryptVerify() { public void testMultiAsymmetricSignEncryptDecryptVerify() {
String plaintext = "dies ist ein plaintext ☭" + TestingUtils.genPassphrase(true); String plaintext = "dies ist ein plaintext ☭";
byte[] ciphertext; byte[] ciphertext;
{ // encrypt data with a given passphrase { // encrypt data with a given passphrase

View file

@ -88,7 +88,7 @@ import static org.sufficientlysecure.keychain.service.SaveKeyringParcel.buildCha
public class PgpKeyOperationTest { public class PgpKeyOperationTest {
static UncachedKeyRing staticRing; static UncachedKeyRing staticRing;
final static Passphrase passphrase = new Passphrase("passphrase"); final static Passphrase passphrase = TestingUtils.testPassphrase0;
UncachedKeyRing ring; UncachedKeyRing ring;
PgpKeyOperation op; PgpKeyOperation op;
@ -321,9 +321,6 @@ public class PgpKeyOperationTest {
{ {
Passphrase badphrase = new Passphrase(); Passphrase badphrase = new Passphrase();
if (badphrase.equals(passphrase)) {
badphrase = new Passphrase("a");
}
builder.addUserId("allure"); builder.addUserId("allure");
assertModifyFailure("keyring modification with bad passphrase should fail", assertModifyFailure("keyring modification with bad passphrase should fail",
@ -1152,7 +1149,7 @@ public class PgpKeyOperationTest {
PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag); PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag);
// modify keyring, change to non-empty passphrase // modify keyring, change to non-empty passphrase
Passphrase otherPassphrase = TestingUtils.genPassphrase(true); Passphrase otherPassphrase = TestingUtils.testPassphrase1;
CryptoInputParcel otherCryptoInput = CryptoInputParcel.createCryptoInputParcel(otherPassphrase); CryptoInputParcel otherCryptoInput = CryptoInputParcel.createCryptoInputParcel(otherPassphrase);
builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(otherPassphrase)); builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(otherPassphrase));
modified = applyModificationWithChecks(builder.build(), modified, onlyA, onlyB, modified = applyModificationWithChecks(builder.build(), modified, onlyA, onlyB,
@ -1179,7 +1176,7 @@ public class PgpKeyOperationTest {
Assert.assertEquals("extracted packet should be a secret subkey", Assert.assertEquals("extracted packet should be a secret subkey",
PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag); PacketTags.SECRET_SUBKEY, sKeyNoPassphrase.tag);
Passphrase otherPassphrase2 = TestingUtils.genPassphrase(true); Passphrase otherPassphrase2 = TestingUtils.testPassphrase2;
builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(otherPassphrase2)); builder.setNewUnlock(ChangeUnlockParcel.createUnLockParcelForNewKey(otherPassphrase2));
{ {
// if we replace a secret key with one without passphrase // if we replace a secret key with one without passphrase

View file

@ -23,6 +23,11 @@ import junit.framework.Assert;
public class TestingUtils { public class TestingUtils {
public static Passphrase testPassphrase0 = new Passphrase("This is a passphrase ☢☣☠☤☮☭⚗⚛⚿∰ℹ℻ ∇∙B=0 ||=ℵ₀");
public static Passphrase testPassphrase1 = new Passphrase("This is a different passphrase ☢☣☠☤☮☭⚗⚛⚿∰ℹ℻ ||=ℵ₀");
public static Passphrase testPassphrase2 = new Passphrase("This is a yet another passphrase ☢☣☠☤☮☭⚗⚛⚿∰ℹ℻");
public static Passphrase genPassphrase(boolean noEmpty) { public static Passphrase genPassphrase(boolean noEmpty) {
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()-_="; String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()-_=";
Random r = new Random(); Random r = new Random();