Merge branch 'bma/upgrade_gradle' into 'master'

Update gradle wrapper and build tools

See merge request matrix-org/olm!20
This commit is contained in:
Hubert Chathi 2021-04-16 20:17:51 +00:00
commit 3b3f2c71dc
16 changed files with 366 additions and 365 deletions

View file

@ -120,8 +120,7 @@ endorsed by the Matrix.org Foundation C.I.C.
First: bump version numbers in ``common.mk``, ``CMakeLists.txt``,
``javascript/package.json``, ``python/olm/__version__.py``, ``OLMKit.podspec``, ``Package.swift``,
and ``android/olm-sdk/build.gradle`` (``versionCode``, ``versionName`` and
``version``).
and ``android/olm-sdk/java/org/matrix/olm/OlmManager.java`` in function ``getVersion()```.
Also, ensure the changelog is up to date, and that everything is committed to
git.

View file

@ -24,6 +24,6 @@ Development
-----------
import the project from the ``android/`` path.
The project contains some JNI files and some Java wraper files.
The project contains some JNI files and some Java wrapper files.
The project contains some tests under AndroidTests package.

View file

@ -2,11 +2,11 @@
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:4.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@ -15,7 +15,7 @@ buildscript {
allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}

View file

@ -19,4 +19,5 @@
#systemProp.https.proxyHost=batproxy
#systemProp.http.proxyPort=8080
android.useAndroidX=true
org.gradle.configureondemand=false

View file

@ -1,6 +1,7 @@
#Thu Oct 13 09:38:01 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
distributionSha256Sum=81003f83b0056d20eedf48cddd4f52a9813163d4ba185bcf8abd34b8eeea4cbd
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

View file

@ -3,15 +3,17 @@ import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
compileSdkVersion 30
defaultConfig {
minSdkVersion 11
targetSdkVersion 28
versionCode 322
versionName "3.2.2"
version "3.2.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 14
targetSdkVersion 30
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
}
buildTypes {
debug {
@ -60,7 +62,8 @@ android {
}
tasks.withType(JavaCompile) {
compileTask -> if (compileTask.name.startsWith('compileDebugJava')) {
compileTask ->
if (compileTask.name.startsWith('compileDebugJava')) {
println 'test compile: Debug'
compileTask.dependsOn ndkBuildNativeDebug
} else if (compileTask.name.startsWith('compileReleaseJava')) {
@ -117,9 +120,11 @@ def gitRevisionDate() {
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
}

View file

@ -18,12 +18,12 @@
package org.matrix.olm;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@ -41,11 +41,13 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -59,15 +61,15 @@ public class OlmAccountTest {
private final String FILE_NAME = "SerialTestFile";
@BeforeClass
public static void setUpClass(){
public static void setUpClass() {
// load native lib
mOlmManager = new OlmManager();
String olmLibVersion = mOlmManager.getOlmLibVersion();
assertNotNull(olmLibVersion);
String olmSdkVersion = mOlmManager.getDetailedVersion(getInstrumentation().getContext());
String olmSdkVersion = mOlmManager.getDetailedVersion(ApplicationProvider.getApplicationContext());
assertNotNull(olmLibVersion);
Log.d(LOG_TAG, "## setUpClass(): Versions - Android Olm SDK = "+olmSdkVersion+" Olm lib ="+olmLibVersion);
Log.d(LOG_TAG, "## setUpClass(): Versions - Android Olm SDK = " + olmSdkVersion + " Olm lib =" + olmLibVersion);
}
@AfterClass
@ -77,7 +79,7 @@ public class OlmAccountTest {
@Before
public void setUp() {
if(mIsAccountCreated) {
if (mIsAccountCreated) {
assertNotNull(mOlmAccount);
}
}
@ -96,12 +98,12 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false);
fail("OlmAccount failed " + e.getMessage());
}
assertNotNull(mOlmAccount);
mOlmAccount.releaseAccount();
assertTrue(0 == mOlmAccount.getOlmAccountId());
assertEquals(0, mOlmAccount.getOlmAccountId());
}
@Test
@ -110,7 +112,7 @@ public class OlmAccountTest {
mOlmAccount = new OlmAccount();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmAccount failed " + e.getMessage(), false);
fail("OlmAccount failed " + e.getMessage());
}
assertNotNull(mOlmAccount);
mIsAccountCreated = true;
@ -119,8 +121,8 @@ public class OlmAccountTest {
@Test
public void test04GetOlmAccountId() {
long olmNativeInstance = mOlmAccount.getOlmAccountId();
Log.d(LOG_TAG,"## testGetOlmAccountId olmNativeInstance="+olmNativeInstance);
assertTrue(0!=olmNativeInstance);
Log.d(LOG_TAG, "## testGetOlmAccountId olmNativeInstance=" + olmNativeInstance);
assertTrue(0 != olmNativeInstance);
}
/**
@ -134,18 +136,18 @@ public class OlmAccountTest {
try {
identityKeys = mOlmAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
assertNotNull(identityKeys);
Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys);
Log.d(LOG_TAG, "## testIdentityKeys Keys=" + identityKeys);
// is JSON_KEY_FINGER_PRINT_KEY present?
String fingerPrintKey = TestHelper.getFingerprintKey(identityKeys);
assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey));
assertFalse("fingerprint key missing", TextUtils.isEmpty(fingerPrintKey));
// is JSON_KEY_IDENTITY_KEY present?
String identityKey = TestHelper.getIdentityKey(identityKeys);
assertTrue("identity key missing",!TextUtils.isEmpty(identityKey));
assertFalse("identity key missing", TextUtils.isEmpty(identityKey));
}
//****************************************************
@ -154,9 +156,9 @@ public class OlmAccountTest {
@Test
public void test06MaxOneTimeKeys() {
long maxOneTimeKeys = mOlmAccount.maxOneTimeKeys();
Log.d(LOG_TAG,"## testMaxOneTimeKeys(): maxOneTimeKeys="+maxOneTimeKeys);
Log.d(LOG_TAG, "## testMaxOneTimeKeys(): maxOneTimeKeys=" + maxOneTimeKeys);
assertTrue(maxOneTimeKeys>0);
assertTrue(maxOneTimeKeys > 0);
}
/**
@ -172,7 +174,7 @@ public class OlmAccountTest {
error = e.getMessage();
}
assertTrue(null == error);
assertNull(error);
}
/**
@ -186,21 +188,21 @@ public class OlmAccountTest {
try {
oneTimeKeysJson = mOlmAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(oneTimeKeysJson);
try {
Map<String, String> map = oneTimeKeysJson.get(OlmAccount.JSON_KEY_ONE_TIME_KEY);
assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=map);
assertNotNull(OlmAccount.JSON_KEY_ONE_TIME_KEY + " object is missing", map);
// test the count of the generated one time keys:
oneTimeKeysCount = map.size();
assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount);
assertEquals("Expected count=" + GENERATION_ONE_TIME_KEYS_NUMBER + " found=" + oneTimeKeysCount, GENERATION_ONE_TIME_KEYS_NUMBER, oneTimeKeysCount);
} catch (Exception e) {
assertTrue("Exception MSg="+e.getMessage(), false);
fail("Exception MSg=" + e.getMessage());
}
}
@ -210,7 +212,7 @@ public class OlmAccountTest {
try {
olmSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
long sessionId = olmSession.getOlmSessionId();
assertTrue(0 != sessionId);
@ -222,11 +224,11 @@ public class OlmAccountTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
olmSession.releaseSession();
sessionId = olmSession.getOlmSessionId();
assertTrue(0 == sessionId);
assertEquals(0, sessionId);
}
@Test
@ -234,7 +236,7 @@ public class OlmAccountTest {
try {
mOlmAccount.markOneTimeKeysAsPublished();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
@ -246,7 +248,7 @@ public class OlmAccountTest {
try {
signedMsg = mOlmAccount.signMessage(clearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(signedMsg);
@ -263,18 +265,18 @@ public class OlmAccountTest {
FileOutputStream fileOutput;
ObjectOutputStream objectOutput;
OlmAccount accountRef = null;
OlmAccount accountDeserial = null;
OlmAccount accountDeserial;
try {
accountRef = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
try {
accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
// get keys references
@ -283,7 +285,7 @@ public class OlmAccountTest {
try {
identityKeysRef = accountRef.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
Map<String, Map<String, String>> oneTimeKeysRef = null;
@ -291,14 +293,14 @@ public class OlmAccountTest {
try {
oneTimeKeysRef = accountRef.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(identityKeysRef);
assertNotNull(oneTimeKeysRef);
try {
Context context = getInstrumentation().getContext();
Context context = ApplicationProvider.getApplicationContext();
//context.getFilesDir();
fileOutput = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
@ -322,32 +324,28 @@ public class OlmAccountTest {
assertNotNull(oneTimeKeysDeserial);
// compare identity keys
assertTrue(identityKeysDeserial.toString().equals(identityKeysRef.toString()));
assertEquals(identityKeysDeserial.toString(), identityKeysRef.toString());
// compare onetime keys
assertTrue(oneTimeKeysDeserial.toString().equals(oneTimeKeysRef.toString()));
assertEquals(oneTimeKeysDeserial.toString(), oneTimeKeysRef.toString());
accountRef.releaseAccount();
accountDeserial.releaseAccount();
}
catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
}
catch (ClassNotFoundException e) {
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg==" + e.getMessage());
fail("test13Serialization failed " + e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
}
catch (IOException e) {
fail("test13Serialization failed " + e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
fail("test13Serialization failed " + e.getMessage());
}
/*catch (OlmException e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception OlmException Msg==" + e.getMessage());
}*/
catch (Exception e) {
}*/ catch (Exception e) {
Log.e(LOG_TAG, "## test13Serialization(): Exception Msg==" + e.getMessage());
assertTrue("test13Serialization failed " + e.getMessage(), false);
fail("test13Serialization failed " + e.getMessage());
}
}
@ -367,7 +365,7 @@ public class OlmAccountTest {
errorMessage = e.getMessage();
}
assertTrue(null == errorMessage);
assertNull(errorMessage);
// keys number = negative value
errorMessage = null;
@ -377,7 +375,7 @@ public class OlmAccountTest {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
}
@Test
@ -386,13 +384,13 @@ public class OlmAccountTest {
try {
olmAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
try {
olmAccount.removeOneTimeKeys(null);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
olmAccount.releaseAccount();
@ -404,7 +402,7 @@ public class OlmAccountTest {
try {
olmAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
String signedMsg = null;
@ -449,31 +447,31 @@ public class OlmAccountTest {
String identityKey1 = TestHelper.getIdentityKey(identityKeys1);
String identityKey2 = TestHelper.getIdentityKey(identityKeys2);
assertFalse(identityKey1.equals(identityKey2));
assertNotEquals(identityKey1, identityKey2);
String identityKey3 = TestHelper.getIdentityKey(identityKeys3);
assertFalse(identityKey2.equals(identityKey3));
assertNotEquals(identityKey2, identityKey3);
String identityKey4 = TestHelper.getIdentityKey(identityKeys4);
assertFalse(identityKey3.equals(identityKey4));
assertNotEquals(identityKey3, identityKey4);
String identityKey5 = TestHelper.getIdentityKey(identityKeys5);
assertFalse(identityKey4.equals(identityKey5));
assertNotEquals(identityKey4, identityKey5);
String identityKey6 = TestHelper.getIdentityKey(identityKeys6);
assertFalse(identityKey5.equals(identityKey6));
assertNotEquals(identityKey5, identityKey6);
String identityKey7 = TestHelper.getIdentityKey(identityKeys7);
assertFalse(identityKey6.equals(identityKey7));
assertNotEquals(identityKey6, identityKey7);
String identityKey8 = TestHelper.getIdentityKey(identityKeys8);
assertFalse(identityKey7.equals(identityKey8));
assertNotEquals(identityKey7, identityKey8);
String identityKey9 = TestHelper.getIdentityKey(identityKeys9);
assertFalse(identityKey8.equals(identityKey9));
assertNotEquals(identityKey8, identityKey9);
String identityKey10 = TestHelper.getIdentityKey(identityKeys10);
assertFalse(identityKey9.equals(identityKey10));
assertNotEquals(identityKey9, identityKey10);
account1.releaseAccount();
account2.releaseAccount();
@ -487,7 +485,7 @@ public class OlmAccountTest {
account10.releaseAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
}
}

View file

@ -18,10 +18,12 @@
package org.matrix.olm;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@ -36,10 +38,12 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -83,7 +87,7 @@ public class OlmGroupSessionTest {
try {
mAliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
}
@ -95,7 +99,7 @@ public class OlmGroupSessionTest {
try {
mAliceSessionIdentifier = mAliceOutboundGroupSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(mAliceSessionIdentifier);
@ -110,7 +114,7 @@ public class OlmGroupSessionTest {
try {
mAliceOutboundSessionKey = mAliceOutboundGroupSession.sessionKey();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(mAliceOutboundSessionKey);
assertTrue(mAliceOutboundSessionKey.length() > 0);
@ -120,7 +124,7 @@ public class OlmGroupSessionTest {
public void test04GetOutboundGroupMessageIndex() {
// test message index before any encryption
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(0 == mAliceMessageIndex);
assertEquals(0, mAliceMessageIndex);
}
@Test
@ -129,13 +133,13 @@ public class OlmGroupSessionTest {
try {
mAliceToBobMessage = mAliceOutboundGroupSession.encryptMessage(CLEAR_MESSAGE1);
} catch (Exception e) {
assertTrue("Exception in bob encryptMessage, Exception code=" + e.getMessage(), false);
fail("Exception in bob encryptMessage, Exception code=" + e.getMessage());
}
assertFalse(TextUtils.isEmpty(mAliceToBobMessage));
// test message index after encryption is incremented
mAliceMessageIndex = mAliceOutboundGroupSession.messageIndex();
assertTrue(1 == mAliceMessageIndex);
assertEquals(1, mAliceMessageIndex);
}
@Test
@ -144,7 +148,7 @@ public class OlmGroupSessionTest {
try {
mBobInboundGroupSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
} catch (OlmException e) {
assertTrue("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode());
}
}
@ -156,7 +160,7 @@ public class OlmGroupSessionTest {
try {
mBobSessionIdentifier = mBobInboundGroupSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertFalse(TextUtils.isEmpty(mBobSessionIdentifier));
}
@ -164,7 +168,7 @@ public class OlmGroupSessionTest {
@Test
public void test09SessionIdentifiersAreIdentical() {
// check both session identifiers are equals: alice vs bob
assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
assertEquals(mAliceSessionIdentifier, mBobSessionIdentifier);
}
@Test
@ -175,19 +179,19 @@ public class OlmGroupSessionTest {
try {
result = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// test decrypted message
mBobDecryptedMessage = result.mDecryptedMessage;
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(0 == result.mIndex);
assertEquals(0, result.mIndex);
}
@Test
public void test11InboundDecryptedMessageIdentical() {
// test decrypted message
assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1));
assertEquals(mBobDecryptedMessage, CLEAR_MESSAGE1);
}
@Test
@ -217,13 +221,13 @@ public class OlmGroupSessionTest {
try {
outboundGroupSessionRef = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(outboundGroupSessionRef);
// serialize alice session
Context context = getInstrumentation().getContext();
Context context = ApplicationProvider.getApplicationContext();
try {
FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_OUT_SESSION, Context.MODE_PRIVATE);
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
@ -245,7 +249,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionKeySerial));
// session keys comparison
assertTrue(sessionKeyRef.equals(sessionKeySerial));
assertEquals(sessionKeyRef, sessionKeySerial);
// get sessions IDs
String sessionIdRef = outboundGroupSessionRef.sessionIdentifier();
@ -254,7 +258,7 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison
assertTrue(sessionIdRef.equals(sessionIdSerial));
assertEquals(sessionIdRef, sessionIdSerial);
outboundGroupSessionRef.releaseSession();
outboundGroupSessionSerial.releaseSession();
@ -263,19 +267,19 @@ public class OlmGroupSessionTest {
assertTrue(outboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (OlmException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (Exception e) {
Log.e(LOG_TAG, "## test15SerializeOutboundSession(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
@ -289,7 +293,7 @@ public class OlmGroupSessionTest {
try {
aliceOutboundGroupSession = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(aliceOutboundGroupSession);
@ -299,7 +303,7 @@ public class OlmGroupSessionTest {
try {
sessionKeyRef = aliceOutboundGroupSession.sessionKey();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(sessionKeyRef);
@ -307,12 +311,12 @@ public class OlmGroupSessionTest {
try {
bobInboundGroupSessionRef = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) {
assertTrue("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode());
}
assertNotNull(bobInboundGroupSessionRef);
// serialize alice session
Context context = getInstrumentation().getContext();
Context context = ApplicationProvider.getApplicationContext();
try {
FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_IN_SESSION, Context.MODE_PRIVATE);
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
@ -336,8 +340,8 @@ public class OlmGroupSessionTest {
assertFalse(TextUtils.isEmpty(sessionIdSerial));
// session IDs comparison
assertTrue(aliceSessionId.equals(sessionIdSerial));
assertTrue(sessionIdRef.equals(sessionIdSerial));
assertEquals(aliceSessionId, sessionIdSerial);
assertEquals(sessionIdRef, sessionIdSerial);
aliceOutboundGroupSession.releaseSession();
bobInboundGroupSessionRef.releaseSession();
@ -348,19 +352,19 @@ public class OlmGroupSessionTest {
assertTrue(bobInboundGroupSessionSerial.isReleased());
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (OlmException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
} catch (Exception e) {
Log.e(LOG_TAG, "## test16SerializeInboundSession(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
@ -392,48 +396,48 @@ public class OlmGroupSessionTest {
// get the session key from the outbound group sessions
String sessionKey1 = outboundGroupSession1.sessionKey();
String sessionKey2 = outboundGroupSession2.sessionKey();
assertFalse(sessionKey1.equals(sessionKey2));
assertNotEquals(sessionKey1, sessionKey2);
String sessionKey3 = outboundGroupSession3.sessionKey();
assertFalse(sessionKey2.equals(sessionKey3));
assertNotEquals(sessionKey2, sessionKey3);
String sessionKey4 = outboundGroupSession4.sessionKey();
assertFalse(sessionKey3.equals(sessionKey4));
assertNotEquals(sessionKey3, sessionKey4);
String sessionKey5 = outboundGroupSession5.sessionKey();
assertFalse(sessionKey4.equals(sessionKey5));
assertNotEquals(sessionKey4, sessionKey5);
String sessionKey6 = outboundGroupSession6.sessionKey();
assertFalse(sessionKey5.equals(sessionKey6));
assertNotEquals(sessionKey5, sessionKey6);
String sessionKey7 = outboundGroupSession7.sessionKey();
assertFalse(sessionKey6.equals(sessionKey7));
assertNotEquals(sessionKey6, sessionKey7);
String sessionKey8 = outboundGroupSession8.sessionKey();
assertFalse(sessionKey7.equals(sessionKey8));
assertNotEquals(sessionKey7, sessionKey8);
// get the session IDs from the outbound group sessions
String sessionId1 = outboundGroupSession1.sessionIdentifier();
String sessionId2 = outboundGroupSession2.sessionIdentifier();
assertFalse(sessionId1.equals(sessionId2));
assertNotEquals(sessionId1, sessionId2);
String sessionId3 = outboundGroupSession3.sessionKey();
assertFalse(sessionId2.equals(sessionId3));
assertNotEquals(sessionId2, sessionId3);
String sessionId4 = outboundGroupSession4.sessionKey();
assertFalse(sessionId3.equals(sessionId4));
assertNotEquals(sessionId3, sessionId4);
String sessionId5 = outboundGroupSession5.sessionKey();
assertFalse(sessionId4.equals(sessionId5));
assertNotEquals(sessionId4, sessionId5);
String sessionId6 = outboundGroupSession6.sessionKey();
assertFalse(sessionId5.equals(sessionId6));
assertNotEquals(sessionId5, sessionId6);
String sessionId7 = outboundGroupSession7.sessionKey();
assertFalse(sessionId6.equals(sessionId7));
assertNotEquals(sessionId6, sessionId7);
String sessionId8 = outboundGroupSession8.sessionKey();
assertFalse(sessionId7.equals(sessionId8));
assertNotEquals(sessionId7, sessionId8);
outboundGroupSession1.releaseSession();
outboundGroupSession2.releaseSession();
@ -453,7 +457,7 @@ public class OlmGroupSessionTest {
assertTrue(outboundGroupSession7.isReleased());
assertTrue(outboundGroupSession8.isReleased());
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
fail("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode());
}
}
@ -476,7 +480,7 @@ public class OlmGroupSessionTest {
try {
bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false);
fail("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode());
}
OlmInboundGroupSession.DecryptMessageResult result = null;
@ -484,11 +488,11 @@ public class OlmGroupSessionTest {
try {
result = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji);
} catch (Exception e) {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getMessage(), false);
fail("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getMessage());
}
assertNotNull(result.mDecryptedMessage);
assertTrue(13 == result.mIndex);
assertEquals(13, result.mIndex);
}
/**
@ -508,7 +512,7 @@ public class OlmGroupSessionTest {
try {
bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef);
} catch (OlmException e) {
assertTrue("Exception in test19TestErrorMessageReturnedInDecrypt, Exception code=" + e.getExceptionCode(), false);
fail("Exception in test19TestErrorMessageReturnedInDecrypt, Exception code=" + e.getExceptionCode());
}
String exceptionMessage = null;
@ -518,8 +522,7 @@ public class OlmGroupSessionTest {
exceptionMessage = e.getMessage();
}
assertTrue(0!=EXPECTED_ERROR_MESSAGE.length());
assertTrue(EXPECTED_ERROR_MESSAGE.equals(exceptionMessage));
assertEquals(EXPECTED_ERROR_MESSAGE, exceptionMessage);
}
@ -544,7 +547,7 @@ public class OlmGroupSessionTest {
try {
inboundGroupSession = new OlmInboundGroupSession(sessionKey);
} catch (Exception e) {
assertTrue("OlmInboundGroupSession failed " + e.getMessage(), false);
fail("OlmInboundGroupSession failed " + e.getMessage());
}
boolean isVerified = false;
@ -552,7 +555,7 @@ public class OlmGroupSessionTest {
try {
isVerified = inboundGroupSession.isVerified();
} catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false);
fail("isVerified failed " + e.getMessage());
}
assertTrue(isVerified);
@ -562,26 +565,26 @@ public class OlmGroupSessionTest {
try {
result = inboundGroupSession.decryptMessage(message);
} catch (Exception e) {
assertTrue("decryptMessage failed " + e.getMessage(), false);
fail("decryptMessage failed " + e.getMessage());
}
assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message"));
assertTrue(0 == result.mIndex);
assertEquals(0, result.mIndex);
String export = null;
try {
export = inboundGroupSession.export(0);
} catch (Exception e) {
assertTrue("export failed " + e.getMessage(), false);
fail("export failed " + e.getMessage());
}
assertTrue(!TextUtils.isEmpty(export));
assertFalse(TextUtils.isEmpty(export));
long index = -1;
try {
index = inboundGroupSession.getFirstKnownIndex();
} catch (Exception e) {
assertTrue("getFirstKnownIndex failed " + e.getMessage(), false);
fail("getFirstKnownIndex failed " + e.getMessage());
}
assertTrue(index >=0);
@ -593,13 +596,13 @@ public class OlmGroupSessionTest {
try {
inboundGroupSession2 = inboundGroupSession.importSession(export);
} catch (Exception e) {
assertTrue("OlmInboundGroupSession failed " + e.getMessage(), false);
fail("OlmInboundGroupSession failed " + e.getMessage());
}
try {
isVerified = inboundGroupSession2.isVerified();
} catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false);
fail("isVerified failed " + e.getMessage());
}
assertFalse(isVerified);
@ -608,16 +611,16 @@ public class OlmGroupSessionTest {
try {
result = inboundGroupSession2.decryptMessage(message);
} catch (Exception e) {
assertTrue("decryptMessage failed " + e.getMessage(), false);
fail("decryptMessage failed " + e.getMessage());
}
assertTrue(TextUtils.equals(result.mDecryptedMessage, "Message"));
assertTrue(0 == result.mIndex);
assertEquals(0, result.mIndex);
try {
isVerified = inboundGroupSession2.isVerified();
} catch (Exception e) {
assertTrue("isVerified failed " + e.getMessage(), false);
fail("isVerified failed " + e.getMessage());
}
assertTrue(isVerified);

View file

@ -16,21 +16,22 @@
package org.matrix.olm;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import java.util.Arrays;
import androidx.test.ext.junit.runners.AndroidJUnit4;
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.assertFalse;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -47,13 +48,13 @@ public class OlmPkTest {
mOlmPkEncryption = new OlmPkEncryption();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false);
fail("OlmPkEncryption failed " + e.getMessage());
}
try {
mOlmPkDecryption = new OlmPkDecryption();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false);
fail("OlmPkEncryption failed " + e.getMessage());
}
assertNotNull(mOlmPkEncryption);
@ -63,13 +64,13 @@ public class OlmPkTest {
try {
key = mOlmPkDecryption.generateKey();
} catch (OlmException e) {
assertTrue("Exception in generateKey, Exception code=" + e.getExceptionCode(), false);
fail("Exception in generateKey, Exception code=" + e.getExceptionCode());
}
Log.d(LOG_TAG, "Ephemeral Key: " + key);
try {
mOlmPkEncryption.setRecipientKey(key);
} catch (OlmException e) {
assertTrue("Exception in setRecipientKey, Exception code=" + e.getExceptionCode(), false);
fail("Exception in setRecipientKey, Exception code=" + e.getExceptionCode());
}
String clearMessage = "Public key test";
@ -77,7 +78,7 @@ public class OlmPkTest {
try {
message = mOlmPkEncryption.encrypt(clearMessage);
} catch (OlmException e) {
assertTrue("Exception in encrypt, Exception code=" + e.getExceptionCode(), false);
fail("Exception in encrypt, Exception code=" + e.getExceptionCode());
}
Log.d(LOG_TAG, "message: " + message.mCipherText + " " + message.mMac + " " + message.mEphemeralKey);
@ -85,9 +86,9 @@ public class OlmPkTest {
try {
decryptedMessage = mOlmPkDecryption.decrypt(message);
} catch (OlmException e) {
assertTrue("Exception in decrypt, Exception code=" + e.getExceptionCode(), false);
fail("Exception in decrypt, Exception code=" + e.getExceptionCode());
}
assertTrue(clearMessage.equals(decryptedMessage));
assertEquals(clearMessage, decryptedMessage);
mOlmPkEncryption.releaseEncryption();
mOlmPkDecryption.releaseDecryption();
@ -101,28 +102,28 @@ public class OlmPkTest {
mOlmPkDecryption = new OlmPkDecryption();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmPkEncryption failed " + e.getMessage(), false);
fail("OlmPkEncryption failed " + e.getMessage());
}
assertNotNull(mOlmPkDecryption);
byte[] privateKey = {
(byte)0x77, (byte)0x07, (byte)0x6D, (byte)0x0A,
(byte)0x73, (byte)0x18, (byte)0xA5, (byte)0x7D,
(byte)0x3C, (byte)0x16, (byte)0xC1, (byte)0x72,
(byte)0x51, (byte)0xB2, (byte)0x66, (byte)0x45,
(byte)0xDF, (byte)0x4C, (byte)0x2F, (byte)0x87,
(byte)0xEB, (byte)0xC0, (byte)0x99, (byte)0x2A,
(byte)0xB1, (byte)0x77, (byte)0xFB, (byte)0xA5,
(byte)0x1D, (byte)0xB9, (byte)0x2C, (byte)0x2A
(byte) 0x77, (byte) 0x07, (byte) 0x6D, (byte) 0x0A,
(byte) 0x73, (byte) 0x18, (byte) 0xA5, (byte) 0x7D,
(byte) 0x3C, (byte) 0x16, (byte) 0xC1, (byte) 0x72,
(byte) 0x51, (byte) 0xB2, (byte) 0x66, (byte) 0x45,
(byte) 0xDF, (byte) 0x4C, (byte) 0x2F, (byte) 0x87,
(byte) 0xEB, (byte) 0xC0, (byte) 0x99, (byte) 0x2A,
(byte) 0xB1, (byte) 0x77, (byte) 0xFB, (byte) 0xA5,
(byte) 0x1D, (byte) 0xB9, (byte) 0x2C, (byte) 0x2A
};
assertTrue(privateKey.length == OlmPkDecryption.privateKeyLength());
assertEquals(privateKey.length, OlmPkDecryption.privateKeyLength());
try {
mOlmPkDecryption.setPrivateKey(privateKey);
} catch (OlmException e) {
assertTrue("Exception in setPrivateKey, Exception code=" + e.getExceptionCode(), false);
fail("Exception in setPrivateKey, Exception code=" + e.getExceptionCode());
}
byte[] privateKeyCopy = null;
@ -130,10 +131,10 @@ public class OlmPkTest {
try {
privateKeyCopy = mOlmPkDecryption.privateKey();
} catch (OlmException e) {
assertTrue("Exception in privateKey, Exception code=" + e.getExceptionCode(), false);
fail("Exception in privateKey, Exception code=" + e.getExceptionCode());
}
assertTrue(Arrays.equals(privateKey, privateKeyCopy));
assertArrayEquals(privateKey, privateKeyCopy);
mOlmPkDecryption.releaseDecryption();
assertTrue(mOlmPkDecryption.isReleased());
@ -145,7 +146,7 @@ public class OlmPkTest {
mOlmPkSigning = new OlmPkSigning();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("OlmPkSigning failed " + e.getMessage(), false);
fail("OlmPkSigning failed " + e.getMessage());
}
assertNotNull(mOlmPkSigning);
@ -155,17 +156,17 @@ public class OlmPkTest {
seed = OlmPkSigning.generateSeed();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("generateSeed failed " + e.getMessage(), false);
fail("generateSeed failed " + e.getMessage());
}
assertTrue(seed.length == OlmPkSigning.seedLength());
assertEquals(seed.length, OlmPkSigning.seedLength());
String pubkey = null;
try {
pubkey = mOlmPkSigning.initWithSeed(seed);
} catch (OlmException e) {
e.printStackTrace();
assertTrue("initWithSeed failed " + e.getMessage(), false);
fail("initWithSeed failed " + e.getMessage());
}
String message = "We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.";
@ -175,7 +176,7 @@ public class OlmPkTest {
signature = mOlmPkSigning.sign(message);
} catch (OlmException e) {
e.printStackTrace();
assertTrue("sign failed " + e.getMessage(), false);
fail("sign failed " + e.getMessage());
}
OlmUtility olmUtility = null;
@ -183,14 +184,14 @@ public class OlmPkTest {
olmUtility = new OlmUtility();
} catch (OlmException e) {
e.printStackTrace();
assertTrue("olmUtility failed " + e.getMessage(), false);
fail("olmUtility failed " + e.getMessage());
}
try {
olmUtility.verifyEd25519Signature(signature, pubkey, message);
} catch (OlmException e) {
e.printStackTrace();
assertTrue("Signature verification failed " + e.getMessage(), false);
fail("Signature verification failed " + e.getMessage());
}
mOlmPkSigning.releaseSigning();

View file

@ -16,10 +16,10 @@
package org.matrix.olm;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@ -29,6 +29,7 @@ import org.junit.runners.MethodSorters;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -91,7 +92,7 @@ public class OlmSasTest {
} catch (Exception e) {
assertTrue("OlmSas init failed " + e.getMessage(), false);
fail("OlmSas init failed " + e.getMessage());
e.printStackTrace();
} finally {
if (aliceSas != null) {

View file

@ -18,11 +18,12 @@
package org.matrix.olm;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONObject;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@ -37,10 +38,12 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -53,13 +56,13 @@ public class OlmSessionTest {
private static OlmManager mOlmManager;
@BeforeClass
public static void setUpClass(){
public static void setUpClass() {
// load native lib
mOlmManager = new OlmManager();
String version = mOlmManager.getOlmLibVersion();
assertNotNull(version);
Log.d(LOG_TAG, "## setUpClass(): lib version="+version);
Log.d(LOG_TAG, "## setUpClass(): lib version=" + version);
}
/**
@ -75,7 +78,7 @@ public class OlmSessionTest {
public void test01AliceToBob() {
final int ONE_TIME_KEYS_NUMBER = 5;
String bobIdentityKey = null;
String bobOneTimeKey=null;
String bobOneTimeKey = null;
OlmAccount bobAccount = null;
OlmAccount aliceAccount = null;
@ -84,12 +87,12 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
assertTrue(0!=aliceAccount.getOlmAccountId());
assertTrue(0 != bobAccount.getOlmAccountId());
assertTrue(0 != aliceAccount.getOlmAccountId());
// get bob identity key
Map<String, String> bobIdentityKeys = null;
@ -97,17 +100,17 @@ public class OlmSessionTest {
try {
bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
assertNotNull(bobIdentityKey);
// get bob one time keys
try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -115,10 +118,10 @@ public class OlmSessionTest {
try {
bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
assertNotNull(bobOneTimeKey);
// CREATE ALICE SESSION
@ -126,58 +129,58 @@ public class OlmSessionTest {
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=aliceSession.getOlmSessionId());
assertTrue(0 != aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String clearMsg = "Heloo bob , this is alice!";
OlmMessage encryptedMsgToBob = null;
try {
encryptedMsgToBob = aliceSession.encryptMessage(clearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsgToBob);
assertNotNull(encryptedMsgToBob.mCipherText);
Log.d(LOG_TAG,"## test01AliceToBob(): encryptedMsg="+encryptedMsgToBob.mCipherText);
Log.d(LOG_TAG, "## test01AliceToBob(): encryptedMsg=" + encryptedMsgToBob.mCipherText);
// CREATE BOB INBOUND SESSION and decrypt message from alice
OlmSession bobSession = null;
try {
bobSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=bobSession.getOlmSessionId());
assertTrue(0 != bobSession.getOlmSessionId());
try {
bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
fail("initInboundSessionWithAccount failed " + e.getMessage());
}
String decryptedMsg = null;
try {
decryptedMsg = bobSession.decryptMessage(encryptedMsgToBob);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg);
// MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(clearMsg.equals(decryptedMsg));
assertEquals(clearMsg, decryptedMsg);
// clean objects..
try {
bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// release accounts
@ -220,12 +223,12 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
assertTrue(0!=aliceAccount.getOlmAccountId());
assertTrue(0 != bobAccount.getOlmAccountId());
assertTrue(0 != aliceAccount.getOlmAccountId());
// get bob identity key
Map<String, String> bobIdentityKeys = null;
@ -233,17 +236,17 @@ public class OlmSessionTest {
try {
bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
assertNotNull(bobIdentityKey);
// get bob one time keys
try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -251,10 +254,10 @@ public class OlmSessionTest {
try {
bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
assertNotNull(bobOneTimeKey);
// CREATE ALICE SESSION
@ -262,15 +265,15 @@ public class OlmSessionTest {
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=aliceSession.getOlmSessionId());
assertTrue(0 != aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String helloClearMsg = "Hello I'm Alice!";
@ -280,7 +283,7 @@ public class OlmSessionTest {
try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedAliceToBobMsg1);
@ -291,15 +294,15 @@ public class OlmSessionTest {
try {
bobSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=bobSession.getOlmSessionId());
assertTrue(0 != bobSession.getOlmSessionId());
try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
fail("initInboundSessionWithAccount failed " + e.getMessage());
}
// DECRYPT MESSAGE FROM ALICE
@ -307,12 +310,12 @@ public class OlmSessionTest {
try {
decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg01);
// MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(helloClearMsg.equals(decryptedMsg01));
assertEquals(helloClearMsg, decryptedMsg01);
// BACK/FORTH MESSAGE COMPARISON
String clearMsg1 = "Hello I'm Bob!";
@ -324,7 +327,7 @@ public class OlmSessionTest {
try {
encryptedMsg1 = bobSession.encryptMessage(clearMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg1);
@ -332,7 +335,7 @@ public class OlmSessionTest {
try {
encryptedMsg2 = bobSession.encryptMessage(clearMsg2);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg2);
@ -341,7 +344,7 @@ public class OlmSessionTest {
try {
encryptedMsg3 = bobSession.encryptMessage(clearMsg3);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg3);
@ -350,7 +353,7 @@ public class OlmSessionTest {
try {
decryptedMsg1 = aliceSession.decryptMessage(encryptedMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg1);
@ -358,7 +361,7 @@ public class OlmSessionTest {
try {
decryptedMsg2 = aliceSession.decryptMessage(encryptedMsg2);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg2);
@ -366,14 +369,14 @@ public class OlmSessionTest {
try {
decryptedMsg3 = aliceSession.decryptMessage(encryptedMsg3);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg3);
// comparison tests
assertTrue(clearMsg1.equals(decryptedMsg1));
assertTrue(clearMsg2.equals(decryptedMsg2));
assertTrue(clearMsg3.equals(decryptedMsg3));
assertEquals(clearMsg1, decryptedMsg1);
assertEquals(clearMsg2, decryptedMsg2);
assertEquals(clearMsg3, decryptedMsg3);
// and one more from alice to bob
clearMsg1 = "another message from Alice to Bob!!";
@ -382,7 +385,7 @@ public class OlmSessionTest {
try {
encryptedMsg1 = aliceSession.encryptMessage(clearMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg1);
@ -390,20 +393,20 @@ public class OlmSessionTest {
try {
decryptedMsg1 = bobSession.decryptMessage(encryptedMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg1);
assertTrue(clearMsg1.equals(decryptedMsg1));
assertEquals(clearMsg1, decryptedMsg1);
// comparison test
assertTrue(clearMsg1.equals(decryptedMsg1));
assertEquals(clearMsg1, decryptedMsg1);
// clean objects..
try {
bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
bobAccount.releaseAccount();
@ -427,12 +430,12 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
assertTrue(0!=aliceAccount.getOlmAccountId());
assertTrue(0 != bobAccount.getOlmAccountId());
assertTrue(0 != aliceAccount.getOlmAccountId());
// CREATE ALICE SESSION
@ -440,9 +443,9 @@ public class OlmSessionTest {
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=aliceSession.getOlmSessionId());
assertTrue(0 != aliceSession.getOlmSessionId());
// CREATE ALICE SESSION
OlmSession bobSession = null;
@ -450,15 +453,15 @@ public class OlmSessionTest {
bobSession = new OlmSession();
} catch (OlmException e) {
e.printStackTrace();
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertTrue(0!=bobSession.getOlmSessionId());
assertTrue(0 != bobSession.getOlmSessionId());
String aliceSessionId = null;
try {
aliceSessionId = aliceSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(aliceSessionId);
@ -467,12 +470,12 @@ public class OlmSessionTest {
try {
bobSessionId = bobSession.sessionIdentifier();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(bobSessionId);
// must be the same for both ends of the conversation
assertTrue(aliceSessionId.equals(bobSessionId));
assertEquals(aliceSessionId, bobSessionId);
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
@ -487,7 +490,7 @@ public class OlmSessionTest {
@Test
public void test04MatchInboundSession() {
OlmAccount aliceAccount=null, bobAccount=null;
OlmAccount aliceAccount = null, bobAccount = null;
OlmSession aliceSession = null, bobSession = null;
// ACCOUNTS CREATION
@ -495,7 +498,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// CREATE ALICE SESSION
@ -503,7 +506,7 @@ public class OlmSessionTest {
aliceSession = new OlmSession();
bobSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
// get bob/luke identity key
@ -512,7 +515,7 @@ public class OlmSessionTest {
try {
bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
Map<String, String> aliceIdentityKeys = null;
@ -520,7 +523,7 @@ public class OlmSessionTest {
try {
aliceIdentityKeys = aliceAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
@ -530,13 +533,13 @@ public class OlmSessionTest {
try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
try {
aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -544,7 +547,7 @@ public class OlmSessionTest {
try {
bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
@ -553,7 +556,7 @@ public class OlmSessionTest {
try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String aliceClearMsg = "hello helooo to bob!";
@ -562,7 +565,7 @@ public class OlmSessionTest {
try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertFalse(bobSession.matchesInboundSession(encryptedAliceToBobMsg1.mCipherText));
@ -571,7 +574,7 @@ public class OlmSessionTest {
try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
fail("initInboundSessionWithAccount failed " + e.getMessage());
}
// test matchesInboundSession() and matchesInboundSessionFrom()
@ -584,7 +587,7 @@ public class OlmSessionTest {
try {
bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
aliceAccount.releaseAccount();
@ -601,6 +604,7 @@ public class OlmSessionTest {
// ********************************************************
// ************* SERIALIZATION TEST ***********************
// ********************************************************
/**
* Same as {@link #test02AliceToBobBackAndForth()}, but alice's session
* is serialized and de-serialized before performing the final
@ -620,12 +624,12 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
assertTrue(0!=aliceAccount.getOlmAccountId());
assertTrue(0 != bobAccount.getOlmAccountId());
assertTrue(0 != aliceAccount.getOlmAccountId());
// get bob identity key
Map<String, String> bobIdentityKeys = null;
@ -633,17 +637,17 @@ public class OlmSessionTest {
try {
bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
assertNotNull(bobIdentityKey);
// get bob one time keys
try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -651,10 +655,10 @@ public class OlmSessionTest {
try {
bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
assertNotNull(bobOneTimeKey);
// CREATE ALICE SESSION
@ -662,15 +666,15 @@ public class OlmSessionTest {
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=aliceSession.getOlmSessionId());
assertTrue(0 != aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
try {
aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
String helloClearMsg = "Hello I'm Alice!";
@ -679,7 +683,7 @@ public class OlmSessionTest {
try {
encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedAliceToBobMsg1);
assertNotNull(encryptedAliceToBobMsg1.mCipherText);
@ -689,15 +693,15 @@ public class OlmSessionTest {
try {
bobSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
assertTrue(0!=bobSession.getOlmSessionId());
assertTrue(0 != bobSession.getOlmSessionId());
// init bob session with alice PRE KEY
try {
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
fail("initInboundSessionWithAccount failed " + e.getMessage());
}
// DECRYPT MESSAGE FROM ALICE
@ -706,13 +710,13 @@ public class OlmSessionTest {
try {
decryptedMsg01 = bobSession.decryptMessage(encryptedAliceToBobMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(decryptedMsg01);
// MESSAGE COMPARISON: decrypted vs encrypted
assertTrue(helloClearMsg.equals(decryptedMsg01));
assertEquals(helloClearMsg, decryptedMsg01);
// BACK/FORTH MESSAGE COMPARISON
String clearMsg1 = "Hello I'm Bob!";
@ -724,7 +728,7 @@ public class OlmSessionTest {
try {
encryptedMsg1 = bobSession.encryptMessage(clearMsg1);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg1);
@ -732,7 +736,7 @@ public class OlmSessionTest {
try {
encryptedMsg2 = bobSession.encryptMessage(clearMsg2);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg2);
@ -740,12 +744,12 @@ public class OlmSessionTest {
try {
encryptedMsg3 = bobSession.encryptMessage(clearMsg3);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsg3);
// serialize alice session
Context context = getInstrumentation().getContext();
Context context = ApplicationProvider.getApplicationContext();
try {
FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_SESSION, Context.MODE_PRIVATE);
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
@ -771,15 +775,15 @@ public class OlmSessionTest {
assertNotNull(decryptedMsg3);
// comparison tests
assertTrue(clearMsg1.equals(decryptedMsg1));
assertTrue(clearMsg2.equals(decryptedMsg2));
assertTrue(clearMsg3.equals(decryptedMsg3));
assertEquals(clearMsg1, decryptedMsg1);
assertEquals(clearMsg2, decryptedMsg2);
assertEquals(clearMsg3, decryptedMsg3);
// clean objects..
try {
bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
bobAccount.releaseAccount();
@ -793,25 +797,21 @@ public class OlmSessionTest {
assertTrue(bobSession.isReleased());
assertTrue(aliceSession.isReleased());
assertTrue(aliceSessionDeserial.isReleased());
}
catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
assertTrue(e.getMessage(), false);
}
catch (ClassNotFoundException e) {
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg==" + e.getMessage());
fail(e.getMessage());
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
}
catch (IOException e) {
fail(e.getMessage());
} catch (IOException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
/*catch (OlmException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception OlmException Msg==" + e.getMessage());
}*/
catch (Exception e) {
}*/ catch (Exception e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage());
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
}
@ -831,7 +831,7 @@ public class OlmSessionTest {
aliceAccount = new OlmAccount();
bobAccount = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
// get bob identity key
@ -840,17 +840,17 @@ public class OlmSessionTest {
try {
bobIdentityKeys = bobAccount.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey);
assertNotNull(bobIdentityKey);
// get bob one time keys
try {
bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
Map<String, Map<String, String>> bobOneTimeKeys = null;
@ -858,11 +858,11 @@ public class OlmSessionTest {
try {
bobOneTimeKeys = bobAccount.oneTimeKeys();
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(bobOneTimeKeys);
String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
assertNotNull(bobOneTimeKey);
// CREATE ALICE SESSION
@ -870,7 +870,7 @@ public class OlmSessionTest {
try {
aliceSession = new OlmSession();
} catch (OlmException e) {
assertTrue("Exception Msg=" + e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
// SANITY CHECK TESTS FOR: initOutboundSessionWithAccount()
@ -880,7 +880,7 @@ public class OlmSessionTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
errorMessage = null;
try {
@ -888,7 +888,7 @@ public class OlmSessionTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
errorMessage = null;
try {
@ -896,7 +896,7 @@ public class OlmSessionTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
errorMessage = null;
try {
@ -904,7 +904,7 @@ public class OlmSessionTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
assertNotNull(errorMessage);
// init properly
errorMessage = null;
@ -913,23 +913,23 @@ public class OlmSessionTest {
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null == errorMessage);
assertNull(errorMessage);
// SANITY CHECK TESTS FOR: encryptMessage()
OlmMessage message = null;
try {
message = aliceSession.encryptMessage(null);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertTrue(null==message);
assertNull(message);
// encrypt properly
OlmMessage encryptedMsgToBob = null;
try {
encryptedMsgToBob = aliceSession.encryptMessage("A message for bob");
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(encryptedMsgToBob);
@ -944,7 +944,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage();
}
assertTrue(!TextUtils.isEmpty(errorMessage));
assertFalse(TextUtils.isEmpty(errorMessage));
errorMessage = null;
try {
@ -953,7 +953,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage();
}
assertTrue(!TextUtils.isEmpty(errorMessage));
assertFalse(TextUtils.isEmpty(errorMessage));
errorMessage = null;
try {
@ -962,7 +962,7 @@ public class OlmSessionTest {
errorMessage = e.getMessage();
}
assertTrue(!TextUtils.isEmpty(errorMessage));
assertFalse(TextUtils.isEmpty(errorMessage));
// init properly
errorMessage = null;
@ -974,7 +974,7 @@ public class OlmSessionTest {
assertTrue(TextUtils.isEmpty(errorMessage));
} catch (OlmException e) {
assertTrue("Exception Msg="+e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
// SANITY CHECK TESTS FOR: decryptMessage()
@ -982,22 +982,22 @@ public class OlmSessionTest {
try {
decryptedMsg = aliceSession.decryptMessage(null);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertTrue(null==decryptedMsg);
assertNull(decryptedMsg);
// SANITY CHECK TESTS FOR: matchesInboundSession()
assertTrue(!aliceSession.matchesInboundSession(null));
assertFalse(aliceSession.matchesInboundSession(null));
// SANITY CHECK TESTS FOR: matchesInboundSessionFrom()
assertTrue(!aliceSession.matchesInboundSessionFrom(null,null));
assertFalse(aliceSession.matchesInboundSessionFrom(null, null));
// release objects
try {
bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
aliceAccount.releaseAccount();

View file

@ -17,11 +17,11 @@
package org.matrix.olm;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONObject;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@ -33,6 +33,7 @@ import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ -43,13 +44,13 @@ public class OlmUtilityTest {
private static OlmManager mOlmManager;
@BeforeClass
public static void setUpClass(){
public static void setUpClass() {
// load native lib
mOlmManager = new OlmManager();
String version = mOlmManager.getOlmLibVersion();
assertNotNull(version);
Log.d(LOG_TAG, "## setUpClass(): lib version="+version);
Log.d(LOG_TAG, "## setUpClass(): lib version=" + version);
}
/**
@ -66,7 +67,7 @@ public class OlmUtilityTest {
try {
account = new OlmAccount();
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
fail(e.getMessage());
}
assertNotNull(account);
@ -76,7 +77,7 @@ public class OlmUtilityTest {
try {
messageSignature = account.signMessage(message);
} catch (Exception e) {
assertTrue(e.getMessage(), false);
fail(e.getMessage());
}
assertNotNull(messageSignature);
@ -87,12 +88,12 @@ public class OlmUtilityTest {
try {
identityKeys = account.identityKeys();
} catch (Exception e) {
assertTrue("identityKeys failed " + e.getMessage(), false);
fail("identityKeys failed " + e.getMessage());
}
assertNotNull(identityKeys);
fingerPrintKey = TestHelper.getFingerprintKey(identityKeys);
assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey));
assertFalse("fingerprint key missing", TextUtils.isEmpty(fingerPrintKey));
// instantiate utility object
OlmUtility utility = null;
@ -100,7 +101,7 @@ public class OlmUtilityTest {
try {
utility = new OlmUtility();
} catch (Exception e) {
assertTrue("failed to create OlmUtility", false);
fail("failed to create OlmUtility");
}
// verify signature
@ -121,10 +122,10 @@ public class OlmUtilityTest {
} catch (Exception e) {
errorMsg = e.getMessage();
}
assertTrue(!TextUtils.isEmpty(errorMsg));
assertFalse(TextUtils.isEmpty(errorMsg));
// check bad fingerprint size => errorMsg = INVALID_BASE64
String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2);
String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length() / 2);
errorMsg = null;
try {
@ -132,7 +133,7 @@ public class OlmUtilityTest {
} catch (Exception e) {
errorMsg = e.getMessage();
}
assertTrue(!TextUtils.isEmpty(errorMsg));
assertFalse(TextUtils.isEmpty(errorMsg));
utility.releaseUtility();
assertTrue(utility.isReleased());
@ -148,7 +149,7 @@ public class OlmUtilityTest {
try {
utility = new OlmUtility();
} catch (Exception e) {
assertTrue("OlmUtility creation failed", false);
fail("OlmUtility creation failed");
}
String msgToHash = "The quick brown fox jumps over the lazy dog";

View file

@ -22,6 +22,7 @@ import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Helper class providing helper methods used in the Olm Android SDK unit tests.
@ -39,7 +40,7 @@ public class TestHelper {
try {
idKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_IDENTITY_KEY);
} catch (Exception e) {
assertTrue("Exception MSg=" + e.getMessage(), false);
fail("Exception MSg=" + e.getMessage());
}
return idKey;
}
@ -55,7 +56,7 @@ public class TestHelper {
try {
fingerprintKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_FINGER_PRINT_KEY);
} catch (Exception e) {
assertTrue("Exception MSg=" + e.getMessage(), false);
fail("Exception MSg=" + e.getMessage());
}
return fingerprintKey;
}
@ -75,7 +76,7 @@ public class TestHelper {
firstOneTimeKey = (new ArrayList<>(generatedKeys.values())).get(aKeyPosition - 1);
} catch (Exception e) {
assertTrue("Exception Msg=" + e.getMessage(), false);
fail("Exception Msg=" + e.getMessage());
}
return firstOneTimeKey;
}

View file

@ -1,8 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.matrix.olm">
<application
android:allowBackup="true"
android:label="@string/app_name">
</application>
</manifest>
<manifest package="org.matrix.olm" />

View file

@ -46,7 +46,7 @@ public class OlmManager {
* @return the library version
*/
public String getVersion() {
return BuildConfig.VERSION_NAME;
return "3.2.2";
}
/**

View file

@ -1,3 +0,0 @@
<resources>
<string name="app_name">OlmSdk</string>
</resources>