From 57ec6fff885e25b32e749d3e63788ff010b1fdfd Mon Sep 17 00:00:00 2001 From: pedroGitt Date: Thu, 13 Oct 2016 19:21:01 +0200 Subject: Temp commit.. adding group session API in progress --- .../java/org/matrix/olm/OlmAccountTest.java | 5 +- .../java/org/matrix/olm/OlmGroupTest.java | 95 ++++++++++++++++++++++ .../java/org/matrix/olm/OlmSessionTest.java | 4 +- 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupTest.java (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest') 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 ec1d49c..ad875c5 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 @@ -152,9 +152,8 @@ public class OlmAccountTest { long sessionId = olmSession.getOlmSessionId(); assertTrue(0 != sessionId); - int sessionRetCode = mOlmAccount.removeOneTimeKeysForSession(sessionId); - // no one time key has been use in the session, so removeOneTimeKeysForSession() returns an error - assertTrue(0 != sessionRetCode); + int sessionRetCode = mOlmAccount.removeOneTimeKeysForSession(olmSession); + assertTrue(0 == sessionRetCode); olmSession.releaseSession(); sessionId = olmSession.getOlmSessionId(); 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/OlmGroupTest.java new file mode 100644 index 0000000..482ae0f --- /dev/null +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupTest.java @@ -0,0 +1,95 @@ +package org.matrix.olm; + +import android.support.test.runner.AndroidJUnit4; +import android.util.Log; + +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class OlmGroupTest { + private static final String LOG_TAG = "OlmSessionTest"; + + 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 + public void test00AliceToBob() { + // TBD + } + + /** + * Basic test: + * - alice creates an account + * - bob creates an account + * - alice creates an outbound group session + * - bob creates an inbound group session with alice's outbound session key + * - alice encrypts a message with its session + * - bob decrypts the encrypted message with its session + */ + //@Test + public void test01AliceToBob() { + // creates alice outbound session + OlmOutboundGroupSession aliceOutboundSession = new OlmOutboundGroupSession(); + + // test accounts creation + String aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier(); + assertNotNull(aliceSessionIdentifier); + assertTrue(aliceSessionIdentifier.length()>0); + + String aliceOutboundSessionKey = aliceOutboundSession.sessionKey(); + assertNotNull(aliceOutboundSessionKey); + assertTrue(aliceOutboundSessionKey.length()>0); + + long messageIndex = aliceOutboundSession.messageIndex(); + assertTrue(0==messageIndex); + + String clearMessage = "Hello!"; + String encryptedMessage = aliceOutboundSession.encryptMessage(clearMessage); + assertNotNull(encryptedMessage); + + messageIndex = aliceOutboundSession.messageIndex(); + assertTrue(1==messageIndex); + + assertTrue(encryptedMessage.length()>=0); + + OlmInboundGroupSession bobInboundSession = new OlmInboundGroupSession(); + bobInboundSession.initInboundGroupSessionWithSessionKey(aliceOutboundSessionKey); + // check session identifiers are equals + aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier(); + String bobSessionIdentifier = aliceOutboundSession.sessionIdentifier(); + assertTrue(aliceSessionIdentifier.equals(bobSessionIdentifier )); + + String decryptedMessage = bobInboundSession.decryptMessage(encryptedMessage); + assertTrue(decryptedMessage.equals(bobSessionIdentifier )); + } + + //@Test + public void test02InboundGroupSession() { + // creates alice outbound session + OlmInboundGroupSession aliceInboundSession = new OlmInboundGroupSession(); + + // test session identifier + String sessionIdentifier = aliceInboundSession.sessionIdentifier(); + assertNotNull(sessionIdentifier); + assertTrue(sessionIdentifier.length()>0); + } + +} 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 0b8e6b4..6056466 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 @@ -105,7 +105,7 @@ public class OlmSessionTest { assertTrue(clearMsg.equals(decryptedMsg)); // clean objects.. - assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession.getOlmSessionId())); + assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); // release accounts bobAccount.releaseAccount(); aliceAccount.releaseAccount(); @@ -191,7 +191,7 @@ public class OlmSessionTest { // MESSAGE COMPARISON: decrypted vs encrypted assertTrue(helloClearMsg.equals(decryptedMsg01)); - assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession.getOlmSessionId())); + assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession)); // BACK/FORTH MESSAGE COMPARISON String clearMsg1 = "Hello I'm Bob!"; -- cgit v1.2.3