From d41b7827ee98b99dfac483df50f3b8679535f051 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 6 Apr 2017 16:39:01 +0100 Subject: [PATCH] Tests: Move constants to a shared file. --- .../journalmanager/AuthenticatorTest.java | 8 ++------ .../journalmanager/EncryptionTest.java | 16 ++++++---------- .../syncadapter/journalmanager/Helpers.java | 7 +++++++ 3 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 app/src/test/java/com/etesync/syncadapter/journalmanager/Helpers.java diff --git a/app/src/test/java/com/etesync/syncadapter/journalmanager/AuthenticatorTest.java b/app/src/test/java/com/etesync/syncadapter/journalmanager/AuthenticatorTest.java index cd915942..a37e2751 100644 --- a/app/src/test/java/com/etesync/syncadapter/journalmanager/AuthenticatorTest.java +++ b/app/src/test/java/com/etesync/syncadapter/journalmanager/AuthenticatorTest.java @@ -25,10 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; public class AuthenticatorTest { - private static final String USER = "test@localhost"; - private static final String PASSWORD = "SomePassword"; - private static final String keyBase64 = "Gpn6j6WJ/9JJbVkWhmEfZjlqSps5rwEOzjUOO0rqufvb4vtT4UfRgx0uMivuGwjF7/8Y1z1glIASX7Oz/4l2jucgf+lAzg2oTZFodWkXRZCDmFa7c9a8/04xIs7koFmUH34Rl9XXW6V2/GDVigQhQU8uWnrGo795tupoNQMbtB8RgMX5GyuxR55FvcybHpYBbwrDIsKvXcBxWFEscdNU8zyeq3yjvDo/W/y24dApW3mnNo7vswoL2rpkZj3dqw=="; - private OkHttpClient httpClient; private HttpUrl remote; @@ -45,14 +41,14 @@ public class AuthenticatorTest { @Test public void testAuthToken() throws IOException, Exceptions.HttpException { JournalAuthenticator journalAuthenticator = new JournalAuthenticator(httpClient, remote); - String authToken = journalAuthenticator.getAuthToken(USER, PASSWORD); + String authToken = journalAuthenticator.getAuthToken(Helpers.USER, Helpers.PASSWORD); assertNotEquals(authToken.length(), 0); } @Test(expected=Exceptions.UnauthorizedException.class) public void testNoUser() throws Exceptions.IntegrityException, Exceptions.VersionTooNewException, IOException, Exceptions.HttpException { JournalAuthenticator journalAuthenticator = new JournalAuthenticator(httpClient, remote); - String authToken = journalAuthenticator.getAuthToken(USER, "BadPassword"); + String authToken = journalAuthenticator.getAuthToken(Helpers.USER, "BadPassword"); assertNotEquals(authToken.length(), 0); } } diff --git a/app/src/test/java/com/etesync/syncadapter/journalmanager/EncryptionTest.java b/app/src/test/java/com/etesync/syncadapter/journalmanager/EncryptionTest.java index 2bcf6cca..01883101 100644 --- a/app/src/test/java/com/etesync/syncadapter/journalmanager/EncryptionTest.java +++ b/app/src/test/java/com/etesync/syncadapter/journalmanager/EncryptionTest.java @@ -20,10 +20,6 @@ import java.io.IOException; import static org.junit.Assert.assertEquals; public class EncryptionTest { - private static final String USER = "test@localhost"; - private static final String PASSWORD = "SomePassword"; - private static final String keyBase64 = "Gpn6j6WJ/9JJbVkWhmEfZjlqSps5rwEOzjUOO0rqufvb4vtT4UfRgx0uMivuGwjF7/8Y1z1glIASX7Oz/4l2jucgf+lAzg2oTZFodWkXRZCDmFa7c9a8/04xIs7koFmUH34Rl9XXW6V2/GDVigQhQU8uWnrGo795tupoNQMbtB8RgMX5GyuxR55FvcybHpYBbwrDIsKvXcBxWFEscdNU8zyeq3yjvDo/W/y24dApW3mnNo7vswoL2rpkZj3dqw=="; - @Before public void setUp() throws IOException { } @@ -34,13 +30,13 @@ public class EncryptionTest { @Test public void testDerivePassword() { - String key = Crypto.deriveKey(USER, PASSWORD); - assertEquals(key, keyBase64); + String key = Crypto.deriveKey(Helpers.USER, Helpers.PASSWORD); + assertEquals(key, Helpers.keyBase64); } @Test public void testCryptoV1() throws Exceptions.IntegrityException, Exceptions.GenericCryptoException { - Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(1, keyBase64, "TestSaltShouldBeJournalId"); + Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(1, Helpers.keyBase64, "TestSaltShouldBeJournalId"); String clearText = "This Is Some Test Cleartext."; byte[] cipher = cryptoManager.encrypt(clearText.getBytes(Charsets.UTF_8)); @@ -52,7 +48,7 @@ public class EncryptionTest { @Test public void testCryptoV2() throws Exceptions.IntegrityException, Exceptions.GenericCryptoException { - Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(2, keyBase64, "TestSaltShouldBeJournalId"); + Crypto.CryptoManager cryptoManager = new Crypto.CryptoManager(2, Helpers.keyBase64, "TestSaltShouldBeJournalId"); String clearText = "This Is Some Test Cleartext."; byte[] cipher = cryptoManager.encrypt(clearText.getBytes(Charsets.UTF_8)); @@ -64,11 +60,11 @@ public class EncryptionTest { @Test(expected=Exceptions.VersionTooNewException.class) public void testCryptoVersionTooNew() throws Exceptions.IntegrityException, Exceptions.VersionTooNewException { - new Crypto.CryptoManager(120, keyBase64, "TestSaltShouldBeJournalId"); + new Crypto.CryptoManager(120, Helpers.keyBase64, "TestSaltShouldBeJournalId"); } @Test(expected=Exceptions.IntegrityException.class) public void testCryptoVersionOutOfRange() throws Exceptions.IntegrityException, Exceptions.VersionTooNewException { - new Crypto.CryptoManager(999, keyBase64, "TestSaltShouldBeJournalId"); + new Crypto.CryptoManager(999, Helpers.keyBase64, "TestSaltShouldBeJournalId"); } } diff --git a/app/src/test/java/com/etesync/syncadapter/journalmanager/Helpers.java b/app/src/test/java/com/etesync/syncadapter/journalmanager/Helpers.java new file mode 100644 index 00000000..79b96990 --- /dev/null +++ b/app/src/test/java/com/etesync/syncadapter/journalmanager/Helpers.java @@ -0,0 +1,7 @@ +package com.etesync.syncadapter.journalmanager; + +class Helpers { + static final String USER = "test@localhost"; + static final String PASSWORD = "SomePassword"; + static final String keyBase64 = "Gpn6j6WJ/9JJbVkWhmEfZjlqSps5rwEOzjUOO0rqufvb4vtT4UfRgx0uMivuGwjF7/8Y1z1glIASX7Oz/4l2jucgf+lAzg2oTZFodWkXRZCDmFa7c9a8/04xIs7koFmUH34Rl9XXW6V2/GDVigQhQU8uWnrGo795tupoNQMbtB8RgMX5GyuxR55FvcybHpYBbwrDIsKvXcBxWFEscdNU8zyeq3yjvDo/W/y24dApW3mnNo7vswoL2rpkZj3dqw=="; +}