mirror of
https://github.com/etesync/android
synced 2024-11-16 04:49:06 +00:00
Tests: Move constants to a shared file.
This commit is contained in:
parent
9ba0f39660
commit
d41b7827ee
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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==";
|
||||
}
|
Loading…
Reference in New Issue
Block a user