aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-04 11:46:37 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-04 11:46:37 +0100
commit88548f687e7f6f51a48ac9cf3a342354731ad694 (patch)
tree5ed745488632b9801308f388e85d6ee27938e297 /java/android/OlmLibSdk/olm-sdk/src/androidTest
parent570e8bbe939f04abc31a78eb99e5e0d3c461728f (diff)
OlmAccount methods trigger an exception when they fail.
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.java121
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java185
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java18
3 files changed, 277 insertions, 47 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 b275688..569b520 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
@@ -128,7 +128,12 @@ public class OlmAccountTest {
*/
@Test
public void test05IdentityKeys() {
- Map<String, String> identityKeys = mOlmAccount.identityKeys();
+ Map<String, String> identityKeys = null;
+ try {
+ identityKeys = mOlmAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
assertNotNull(identityKeys);
Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys);
@@ -157,8 +162,15 @@ public class OlmAccountTest {
*/
@Test
public void test07GenerateOneTimeKeys() {
- int retValue = mOlmAccount.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
- assertTrue(0==retValue);
+ String error = null;
+
+ try {
+ mOlmAccount.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ error = e.getMessage();
+ }
+
+ assertTrue(null == error);
}
/**
@@ -167,7 +179,13 @@ public class OlmAccountTest {
@Test
public void test08OneTimeKeysJsonFormat() {
int oneTimeKeysCount = 0;
- Map<String, Map<String, String>> oneTimeKeysJson = mOlmAccount.oneTimeKeys();
+ Map<String, Map<String, String>> oneTimeKeysJson = null;
+
+ try {
+ oneTimeKeysJson = mOlmAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
assertNotNull(oneTimeKeysJson);
try {
@@ -195,26 +213,40 @@ public class OlmAccountTest {
long sessionId = olmSession.getOlmSessionId();
assertTrue(0 != sessionId);
- int sessionRetCode = mOlmAccount.removeOneTimeKeysForSession(olmSession);
- // test against no matching keys
- assertTrue(1 == sessionRetCode);
+ String errorMessage = null;
+
+ try {
+ mOlmAccount.removeOneTimeKeys(olmSession);
+ } catch (Exception e) {
+ errorMessage = e.getMessage();
+ }
+ assertTrue(null != errorMessage);
olmSession.releaseSession();
sessionId = olmSession.getOlmSessionId();
- assertTrue("sessionRetCode="+sessionRetCode,0 == sessionId);
+ assertTrue(0 == sessionId);
}
@Test
public void test11MarkOneTimeKeysAsPublished() {
- int retCode = mOlmAccount.markOneTimeKeysAsPublished();
- // if OK => retCode=0
- assertTrue(0 == retCode);
+ try {
+ mOlmAccount.markOneTimeKeysAsPublished();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
}
@Test
public void test12SignMessage() {
String clearMsg = "String to be signed by olm";
- String signedMsg = mOlmAccount.signMessage(clearMsg);
+ String signedMsg = null;
+
+ try {
+ signedMsg = mOlmAccount.signMessage(clearMsg);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
assertNotNull(signedMsg);
// additional tests are performed in test01VerifyEd25519Signing()
}
@@ -237,12 +269,29 @@ public class OlmAccountTest {
assertTrue(e.getMessage(),false);
}
- int retValue = accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
- assertTrue(0==retValue);
+ try {
+ accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(),false);
+ }
// get keys references
- Map<String, String> identityKeysRef = accountRef.identityKeys();
- Map<String, Map<String, String>> oneTimeKeysRef = accountRef.oneTimeKeys();
+ Map<String, String> identityKeysRef = null;
+
+ try {
+ identityKeysRef = accountRef.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> oneTimeKeysRef = null;
+
+ try {
+ oneTimeKeysRef = accountRef.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
assertNotNull(identityKeysRef);
assertNotNull(oneTimeKeysRef);
@@ -304,12 +353,25 @@ public class OlmAccountTest {
@Test
public void test14GenerateOneTimeKeysError() {
// keys number = 0 => no error
- int retValue = mOlmAccount.generateOneTimeKeys(0);
- assertTrue(0==retValue);
+
+ String errorMessage = null;
+ try {
+ mOlmAccount.generateOneTimeKeys(0);
+ } catch (Exception e) {
+ errorMessage = e.getMessage();
+ }
+
+ assertTrue(null == errorMessage);
// keys number = negative value
- retValue = mOlmAccount.generateOneTimeKeys(-50);
- assertTrue(-1==retValue);
+ errorMessage = null;
+ try {
+ mOlmAccount.generateOneTimeKeys(-50);
+ } catch (Exception e) {
+ errorMessage = e.getMessage();
+ }
+
+ assertTrue(null != errorMessage);
}
@Test
@@ -321,9 +383,16 @@ public class OlmAccountTest {
assertTrue(e.getMessage(),false);
}
- int sessionRetCode = olmAccount.removeOneTimeKeysForSession(null);
+ boolean sessionRetCode = true;
+
+ try {
+ sessionRetCode = olmAccount.removeOneTimeKeys(null);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
// test against no matching keys
- assertTrue(-1 == sessionRetCode);
+ assertFalse(sessionRetCode);
olmAccount.releaseAccount();
}
@@ -336,7 +405,13 @@ public class OlmAccountTest {
} catch (OlmException e) {
assertTrue(e.getMessage(),false);
}
- String signedMsg = olmAccount.signMessage(null);
+ String signedMsg = null;
+
+ try {
+ signedMsg = olmAccount.signMessage(null);
+ } catch (Exception e) {
+ }
+
assertNull(signedMsg);
olmAccount.releaseAccount();
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 675d72c..e8b2288 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
@@ -92,13 +92,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key
- Map<String, String> bobIdentityKeys = bobAccount.identityKeys();
+ Map<String, String> bobIdentityKeys = null;
+
+ try {
+ bobIdentityKeys = bobAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
// get bob one time keys
- assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys();
+ try {
+ bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> bobOneTimeKeys = null;
+
+ try {
+ bobOneTimeKeys = bobAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey);
@@ -141,7 +160,13 @@ public class OlmSessionTest {
assertTrue(clearMsg.equals(decryptedMsg));
// clean objects..
- assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
+ boolean res = false;
+ try {
+ res = bobAccount.removeOneTimeKeys(bobSession);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+ assertTrue(res);
// release accounts
bobAccount.releaseAccount();
@@ -191,13 +216,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key
- Map<String, String> bobIdentityKeys = bobAccount.identityKeys();
+ Map<String, String> bobIdentityKeys = null;
+
+ try {
+ bobIdentityKeys = bobAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
// get bob one time keys
- assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys();
+ try {
+ bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> bobOneTimeKeys = null;
+
+ try {
+ bobOneTimeKeys = bobAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey);
@@ -279,7 +323,14 @@ public class OlmSessionTest {
assertTrue(clearMsg1.equals(decryptedMsg1));
// clean objects..
- assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
+ boolean res = false;
+ try {
+ res = bobAccount.removeOneTimeKeys(bobSession);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+ assertTrue(res);
+
bobAccount.releaseAccount();
aliceAccount.releaseAccount();
assertTrue(bobAccount.isReleased());
@@ -369,15 +420,46 @@ public class OlmSessionTest {
}
// get bob/luke identity key
- Map<String, String> bobIdentityKeys = bobAccount.identityKeys();
- Map<String, String> aliceIdentityKeys = aliceAccount.identityKeys();
+ Map<String, String> bobIdentityKeys = null;
+
+ try {
+ bobIdentityKeys = bobAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
+ Map<String, String> aliceIdentityKeys = null;
+
+ try {
+ aliceIdentityKeys = aliceAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
String aliceIdentityKey = TestHelper.getIdentityKey(aliceIdentityKeys);
// get bob/luke one time keys
- assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- assertTrue(0 == aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys();
+ try {
+ bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ try {
+ aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> bobOneTimeKeys = null;
+
+ try {
+ bobOneTimeKeys = bobAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
// create alice inbound session for bob
@@ -401,7 +483,14 @@ public class OlmSessionTest {
//assertTrue(false==bobSession.matchesInboundSessionFrom(bobIdentityKey, encryptedAliceToBobMsg1.mCipherText));
// release objects
- assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
+ boolean res = false;
+ try {
+ res = bobAccount.removeOneTimeKeys(bobSession);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+ assertTrue(res);
+
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
assertTrue(aliceAccount.isReleased());
@@ -443,13 +532,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key
- Map<String, String> bobIdentityKeys = bobAccount.identityKeys();
+ Map<String, String> bobIdentityKeys = null;
+
+ try {
+ bobIdentityKeys = bobAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey);
// get bob one time keys
- assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys();
+ try {
+ bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> bobOneTimeKeys = null;
+
+ try {
+ bobOneTimeKeys = bobAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey);
@@ -538,7 +646,14 @@ public class OlmSessionTest {
assertTrue(clearMsg3.equals(decryptedMsg3));
// clean objects..
- assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
+ boolean res = false;
+ try {
+ res = bobAccount.removeOneTimeKeys(bobSession);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+ assertTrue(res);
+
bobAccount.releaseAccount();
aliceAccount.releaseAccount();
assertTrue(bobAccount.isReleased());
@@ -588,13 +703,32 @@ public class OlmSessionTest {
}
// get bob identity key
- Map<String, String> bobIdentityKeys = bobAccount.identityKeys();
+ Map<String, String> bobIdentityKeys = null;
+
+ try {
+ bobIdentityKeys = bobAccount.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey);
// get bob one time keys
- assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER));
- Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys();
+ try {
+ bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
+ Map<String, Map<String, String>> bobOneTimeKeys = null;
+
+ try {
+ bobOneTimeKeys = bobAccount.oneTimeKeys();
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
assertNotNull(bobOneTimeKeys);
String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey);
@@ -678,7 +812,14 @@ public class OlmSessionTest {
assertTrue(!aliceSession.matchesInboundSessionFrom(null,null));
// release objects
- assertTrue(0==bobAccount.removeOneTimeKeysForSession(bobSession));
+ boolean res = false;
+ try {
+ res = bobAccount.removeOneTimeKeys(bobSession);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+ assertTrue(res);
+
aliceAccount.releaseAccount();
bobAccount.releaseAccount();
assertTrue(aliceAccount.isReleased());
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
index e3ca544..4096001 100644
--- 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
@@ -71,11 +71,25 @@ public class OlmUtilityTest {
assertNotNull(account);
// sign message
- String messageSignature = account.signMessage(message);
+ String messageSignature = null;
+
+ try {
+ messageSignature = account.signMessage(message);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), false);
+ }
+
assertNotNull(messageSignature);
// get identities key (finger print key)
- Map<String, String> identityKeys = account.identityKeys();
+ Map<String, String> identityKeys = null;
+
+ try {
+ identityKeys = account.identityKeys();
+ } catch (Exception e) {
+ assertTrue("identityKeys failed " + e.getMessage(), false);
+ }
+
assertNotNull(identityKeys);
fingerPrintKey = TestHelper.getFingerprintKey(identityKeys);
assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey));