aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-10-18 16:05:28 +0200
committerpedroGitt <pedro.contreiras@amdocs.com>2016-10-18 16:05:28 +0200
commit139402611aff5919844109f2c7f126bec5c31534 (patch)
tree375417c2112892b429412a02ad75b586d07be01a /java/android/OlmLibSdk/olm-sdk/src/androidTest
parent034fa6be40b1a354dad5394cdb43651f435f8adb (diff)
Add OlmUtility class
- add unit tests for OlmUtility - rename OlmGroupTest to OlmGroupSessionTest - update OlmException
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java37
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java (renamed from java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupTest.java)46
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java1
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java89
4 files changed, 109 insertions, 64 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
index 70db63e..45f6e63 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
@@ -173,41 +173,6 @@ public class OlmAccountTest {
String clearMsg = "String to be signed by olm";
String signedMsg = mOlmAccount.signMessage(clearMsg);
assertNotNull(signedMsg);
- // TODO add test to unsign the signedMsg and compare it ot clearMsg
+ // additional tests are performed in test01VerifyEd25519Signing()
}
-
-
- private void testJni(){
- OlmManager mgr = new OlmManager();
- String versionLib = mgr.getOlmLibVersion();
- Log.d(LOG_TAG, "## testJni(): lib version="+versionLib);
-
- OlmAccount account = new OlmAccount();
-
- long accountNativeId = account.getOlmAccountId();
- Log.d(LOG_TAG, "## testJni(): lib accountNativeId="+accountNativeId);
-
- JSONObject identityKeys = account.identityKeys();
- Log.d(LOG_TAG, "## testJni(): identityKeysJson="+identityKeys.toString());
-
- long maxOneTimeKeys = account.maxOneTimeKeys();
- Log.d(LOG_TAG, "## testJni(): lib maxOneTimeKeys="+maxOneTimeKeys);
-
- int generateRetCode = account.generateOneTimeKeys(50);
- Log.d(LOG_TAG, "## testJni(): generateRetCode="+generateRetCode);
-
- JSONObject oneTimeKeysKeysJson = account.oneTimeKeys();
- Log.d(LOG_TAG, "## testJni(): oneTimeKeysKeysJson="+oneTimeKeysKeysJson.toString());
-
- int asPublishedRetCode = account.markOneTimeKeysAsPublished();
- Log.d(LOG_TAG, "## testJni(): asPublishedRetCode="+asPublishedRetCode);
-
- String clearMsg ="My clear message";
- String signedMsg = account.signMessage(clearMsg);
- Log.d(LOG_TAG, "## testJni(): signedMsg="+signedMsg);
-
- account.releaseAccount();
- }
-
-
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
index 5a5ca57..fc3c1f0 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
@@ -17,16 +17,16 @@ import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class OlmGroupTest {
+public class OlmGroupSessionTest {
private static final String LOG_TAG = "OlmSessionTest";
private static OlmManager mOlmManager;
- private static OlmOutboundGroupSession mAliceOutboundSession;
+ private static OlmOutboundGroupSession mAliceOutboundGroupSession;
private static String mAliceSessionIdentifier;
private static long mAliceMessageIndex;
public static final String CLEAR_MESSAGE1 = "Hello!";
private static String mAliceToBobMessage;
- private static OlmInboundGroupSession mBobInboundSession;
+ private static OlmInboundGroupSession mBobInboundGroupSession;
private static String mAliceOutboundSessionKey;
private static String mBobSessionIdentifier;
private static String mBobDecryptedMessage;
@@ -53,7 +53,7 @@ public class OlmGroupTest {
public void test01CreateOutboundSession() {
// alice creates OUTBOUND GROUP SESSION
try {
- mAliceOutboundSession = new OlmOutboundGroupSession();
+ mAliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
@@ -62,7 +62,7 @@ public class OlmGroupTest {
@Test
public void test02GetOutboundGroupSessionIdentifier() {
// test session ID
- mAliceSessionIdentifier = mAliceOutboundSession.sessionIdentifier();
+ mAliceSessionIdentifier = mAliceOutboundGroupSession.sessionIdentifier();
assertNotNull(mAliceSessionIdentifier);
assertTrue(mAliceSessionIdentifier.length() > 0);
}
@@ -70,7 +70,7 @@ public class OlmGroupTest {
@Test
public void test03GetOutboundGroupSessionKey() {
// test session Key
- mAliceOutboundSessionKey = mAliceOutboundSession.sessionKey();
+ mAliceOutboundSessionKey = mAliceOutboundGroupSession.sessionKey();
assertNotNull(mAliceOutboundSessionKey);
assertTrue(mAliceOutboundSessionKey.length() > 0);
}
@@ -78,56 +78,48 @@ public class OlmGroupTest {
@Test
public void test04GetOutboundGroupMessageIndex() {
// test message index before any encryption
- mAliceMessageIndex = mAliceOutboundSession.messageIndex();
+ mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(0 == mAliceMessageIndex);
}
@Test
public void test05OutboundGroupEncryptMessage() {
// alice encrypts a message to bob
- mAliceToBobMessage = mAliceOutboundSession.encryptMessage(CLEAR_MESSAGE1);
+ mAliceToBobMessage = mAliceOutboundGroupSession.encryptMessage(CLEAR_MESSAGE1);
assertFalse(TextUtils.isEmpty(mAliceToBobMessage));
// test message index after encryption is incremented
- mAliceMessageIndex = mAliceOutboundSession.messageIndex();
- assertTrue(1== mAliceMessageIndex);
+ mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
+ assertTrue(1 == mAliceMessageIndex);
}
@Test
public void test06CreateInboundGroupSession() {
// bob creates INBOUND GROUP SESSION with alice outbound key
try {
- mBobInboundSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
+ mBobInboundGroupSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
} catch (OlmException e) {
assertTrue("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
}
@Test
- public void test07OutboundGroupSessionIdentifiers() {
- // check session identifiers are equals
- mAliceSessionIdentifier = mAliceOutboundSession.sessionIdentifier();
- assertFalse(TextUtils.isEmpty(mAliceSessionIdentifier));
- }
-
- @Test
- public void test08InboundGroupSessionIdentifiers() {
- // check session identifiers are equals
- mBobSessionIdentifier = mBobInboundSession.sessionIdentifier();
+ public void test08GetInboundGroupSessionIdentifier() {
+ // check both session identifiers are equals
+ mBobSessionIdentifier = mBobInboundGroupSession.sessionIdentifier();
assertFalse(TextUtils.isEmpty(mBobSessionIdentifier));
- assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
}
@Test
- public void test09SessionIdentifiersIdentical() {
- // check session identifiers are equals
+ public void test09SessionIdentifiersAreIdentical() {
+ // check both session identifiers are equals: alice vs bob
assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
}
@Test
public void test10InboundDecryptMessage() {
// test decrypted message
- mBobDecryptedMessage = mBobInboundSession.decryptMessage(mAliceToBobMessage);
+ mBobDecryptedMessage = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage);
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1));
}
@@ -141,12 +133,12 @@ public class OlmGroupTest {
@Test
public void test12ReleaseOutboundSession() {
// release group sessions
- mAliceOutboundSession.releaseSession();
+ mAliceOutboundGroupSession.releaseSession();
}
@Test
public void test13ReleaseInboundSession() {
// release group sessions
- mBobInboundSession.releaseSession();
+ mBobInboundGroupSession.releaseSession();
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
index 6056466..311d6a8 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
@@ -250,5 +250,4 @@ public class OlmSessionTest {
// must be the same for both ends of the conversation
assertTrue(aliceSessionId.equals(bobSessionId));
}
-
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
new file mode 100644
index 0000000..5175424
--- /dev/null
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
@@ -0,0 +1,89 @@
+package org.matrix.olm;
+
+import android.support.test.runner.AndroidJUnit4;
+import android.text.TextUtils;
+import android.util.Log;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+
+import java.util.Iterator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(AndroidJUnit4.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class OlmUtilityTest {
+ private static final String LOG_TAG = "OlmAccountTest";
+ private static final int GENERATION_ONE_TIME_KEYS_NUMBER = 50;
+
+ private static OlmManager mOlmManager;
+
+ @BeforeClass
+ public static void setUpClass(){
+ // load native lib
+ mOlmManager = new OlmManager();
+
+ String version = mOlmManager.getOlmLibVersion();
+ assertNotNull(version);
+ Log.d(LOG_TAG, "## setUpClass(): lib version="+version);
+ }
+
+ /**
+ * Test the signing API
+ */
+ @Test
+ public void test01VerifyEd25519Signing() {
+ String fingerPrintKey = null;
+ String errorMsg = new String();
+ String message = "{\"key1\":\"value1\",\"key2\":\"value2\"};";
+
+ // create account
+ OlmAccount account = new OlmAccount();
+ assertNotNull(account);
+
+ // sign message
+ String messageSignature = account.signMessage(message);
+ assertNotNull(messageSignature);
+
+ // get identity key
+ JSONObject identityKeysJson = account.identityKeys();
+ assertNotNull(identityKeysJson);
+ try {
+ fingerPrintKey = identityKeysJson.getString(OlmAccount.JSON_KEY_FINGER_PRINT_KEY);
+ assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ assertTrue("Exception MSg="+e.getMessage(), false);
+ }
+
+ // instance utility
+ OlmUtility utility = new OlmUtility();
+ boolean isVerified = utility.verifyEd25519Signature(messageSignature, fingerPrintKey, message, errorMsg);
+ assertTrue(isVerified);
+
+ utility.releaseUtility();
+ }
+
+
+ @Test
+ public void test02sha256() {
+ OlmUtility utility = new OlmUtility();
+ String msgToHash = "The quick brown fox jumps over the lazy dog";
+
+ String hashResult = utility.sha256(msgToHash);
+ assertFalse(TextUtils.isEmpty(hashResult));
+
+ utility.releaseUtility();
+ }
+}