Commit 88548f68 authored by ylecollen's avatar ylecollen
Browse files

OlmAccount methods trigger an exception when they fail.

parent 570e8bbe
...@@ -128,7 +128,12 @@ public class OlmAccountTest { ...@@ -128,7 +128,12 @@ public class OlmAccountTest {
*/ */
@Test @Test
public void test05IdentityKeys() { 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); assertNotNull(identityKeys);
Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys); Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys);
...@@ -157,8 +162,15 @@ public class OlmAccountTest { ...@@ -157,8 +162,15 @@ public class OlmAccountTest {
*/ */
@Test @Test
public void test07GenerateOneTimeKeys() { public void test07GenerateOneTimeKeys() {
int retValue = mOlmAccount.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER); String error = null;
assertTrue(0==retValue);
try {
mOlmAccount.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
error = e.getMessage();
}
assertTrue(null == error);
} }
/** /**
...@@ -167,7 +179,13 @@ public class OlmAccountTest { ...@@ -167,7 +179,13 @@ public class OlmAccountTest {
@Test @Test
public void test08OneTimeKeysJsonFormat() { public void test08OneTimeKeysJsonFormat() {
int oneTimeKeysCount = 0; 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); assertNotNull(oneTimeKeysJson);
try { try {
...@@ -195,26 +213,40 @@ public class OlmAccountTest { ...@@ -195,26 +213,40 @@ public class OlmAccountTest {
long sessionId = olmSession.getOlmSessionId(); long sessionId = olmSession.getOlmSessionId();
assertTrue(0 != sessionId); assertTrue(0 != sessionId);
int sessionRetCode = mOlmAccount.removeOneTimeKeysForSession(olmSession); String errorMessage = null;
// test against no matching keys
assertTrue(1 == sessionRetCode); try {
mOlmAccount.removeOneTimeKeys(olmSession);
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
olmSession.releaseSession(); olmSession.releaseSession();
sessionId = olmSession.getOlmSessionId(); sessionId = olmSession.getOlmSessionId();
assertTrue("sessionRetCode="+sessionRetCode,0 == sessionId); assertTrue(0 == sessionId);
} }
@Test @Test
public void test11MarkOneTimeKeysAsPublished() { public void test11MarkOneTimeKeysAsPublished() {
int retCode = mOlmAccount.markOneTimeKeysAsPublished(); try {
// if OK => retCode=0 mOlmAccount.markOneTimeKeysAsPublished();
assertTrue(0 == retCode); } catch (Exception e) {
assertTrue(e.getMessage(), false);
}
} }
@Test @Test
public void test12SignMessage() { public void test12SignMessage() {
String clearMsg = "String to be signed by olm"; 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); assertNotNull(signedMsg);
// additional tests are performed in test01VerifyEd25519Signing() // additional tests are performed in test01VerifyEd25519Signing()
} }
...@@ -237,12 +269,29 @@ public class OlmAccountTest { ...@@ -237,12 +269,29 @@ public class OlmAccountTest {
assertTrue(e.getMessage(),false); assertTrue(e.getMessage(),false);
} }
int retValue = accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER); try {
assertTrue(0==retValue); accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
} catch (Exception e) {
assertTrue(e.getMessage(),false);
}
// get keys references // get keys references
Map<String, String> identityKeysRef = accountRef.identityKeys(); Map<String, String> identityKeysRef = null;
Map<String, Map<String, String>> oneTimeKeysRef = accountRef.oneTimeKeys();
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(identityKeysRef);
assertNotNull(oneTimeKeysRef); assertNotNull(oneTimeKeysRef);
...@@ -304,12 +353,25 @@ public class OlmAccountTest { ...@@ -304,12 +353,25 @@ public class OlmAccountTest {
@Test @Test
public void test14GenerateOneTimeKeysError() { public void test14GenerateOneTimeKeysError() {
// keys number = 0 => no error // 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 // keys number = negative value
retValue = mOlmAccount.generateOneTimeKeys(-50); errorMessage = null;
assertTrue(-1==retValue); try {
mOlmAccount.generateOneTimeKeys(-50);
} catch (Exception e) {
errorMessage = e.getMessage();
}
assertTrue(null != errorMessage);
} }
@Test @Test
...@@ -321,9 +383,16 @@ public class OlmAccountTest { ...@@ -321,9 +383,16 @@ public class OlmAccountTest {
assertTrue(e.getMessage(),false); 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 // test against no matching keys
assertTrue(-1 == sessionRetCode); assertFalse(sessionRetCode);
olmAccount.releaseAccount(); olmAccount.releaseAccount();
} }
...@@ -336,7 +405,13 @@ public class OlmAccountTest { ...@@ -336,7 +405,13 @@ public class OlmAccountTest {
} catch (OlmException e) { } catch (OlmException e) {
assertTrue(e.getMessage(),false); assertTrue(e.getMessage(),false);
} }
String signedMsg = olmAccount.signMessage(null); String signedMsg = null;
try {
signedMsg = olmAccount.signMessage(null);
} catch (Exception e) {
}
assertNull(signedMsg); assertNull(signedMsg);
olmAccount.releaseAccount(); olmAccount.releaseAccount();
......
...@@ -92,13 +92,32 @@ public class OlmSessionTest { ...@@ -92,13 +92,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId()); assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key // 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); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey); assertTrue(null!=bobIdentityKey);
// get bob one time keys // get bob one time keys
assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); try {
Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys(); 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); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey); assertNotNull(bobOneTimeKey);
...@@ -141,7 +160,13 @@ public class OlmSessionTest { ...@@ -141,7 +160,13 @@ public class OlmSessionTest {
assertTrue(clearMsg.equals(decryptedMsg)); assertTrue(clearMsg.equals(decryptedMsg));
// clean objects.. // 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 // release accounts
bobAccount.releaseAccount(); bobAccount.releaseAccount();
...@@ -191,13 +216,32 @@ public class OlmSessionTest { ...@@ -191,13 +216,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId()); assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key // 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); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey); assertTrue(null!=bobIdentityKey);
// get bob one time keys // get bob one time keys
assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); try {
Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys(); 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); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey); assertNotNull(bobOneTimeKey);
...@@ -279,7 +323,14 @@ public class OlmSessionTest { ...@@ -279,7 +323,14 @@ public class OlmSessionTest {
assertTrue(clearMsg1.equals(decryptedMsg1)); assertTrue(clearMsg1.equals(decryptedMsg1));
// clean objects.. // 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(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(bobAccount.isReleased()); assertTrue(bobAccount.isReleased());
...@@ -369,15 +420,46 @@ public class OlmSessionTest { ...@@ -369,15 +420,46 @@ public class OlmSessionTest {
} }
// get bob/luke identity key // get bob/luke identity key
Map<String, String> bobIdentityKeys = bobAccount.identityKeys(); Map<String, String> bobIdentityKeys = null;
Map<String, String> aliceIdentityKeys = aliceAccount.identityKeys();
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 bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
String aliceIdentityKey = TestHelper.getIdentityKey(aliceIdentityKeys); String aliceIdentityKey = TestHelper.getIdentityKey(aliceIdentityKeys);
// get bob/luke one time keys // get bob/luke one time keys
assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); try {
assertTrue(0 == aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER);
Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys(); } 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); String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
// create alice inbound session for bob // create alice inbound session for bob
...@@ -401,7 +483,14 @@ public class OlmSessionTest { ...@@ -401,7 +483,14 @@ public class OlmSessionTest {
//assertTrue(false==bobSession.matchesInboundSessionFrom(bobIdentityKey, encryptedAliceToBobMsg1.mCipherText)); //assertTrue(false==bobSession.matchesInboundSessionFrom(bobIdentityKey, encryptedAliceToBobMsg1.mCipherText));
// release objects // 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(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(aliceAccount.isReleased()); assertTrue(aliceAccount.isReleased());
...@@ -443,13 +532,32 @@ public class OlmSessionTest { ...@@ -443,13 +532,32 @@ public class OlmSessionTest {
assertTrue(0!=aliceAccount.getOlmAccountId()); assertTrue(0!=aliceAccount.getOlmAccountId());
// get bob identity key // 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); bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null!=bobIdentityKey); assertTrue(null!=bobIdentityKey);
// get bob one time keys // get bob one time keys
assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); try {
Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys(); 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); bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey); assertNotNull(bobOneTimeKey);
...@@ -538,7 +646,14 @@ public class OlmSessionTest { ...@@ -538,7 +646,14 @@ public class OlmSessionTest {
assertTrue(clearMsg3.equals(decryptedMsg3)); assertTrue(clearMsg3.equals(decryptedMsg3));
// clean objects.. // 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(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
assertTrue(bobAccount.isReleased()); assertTrue(bobAccount.isReleased());
...@@ -588,13 +703,32 @@ public class OlmSessionTest { ...@@ -588,13 +703,32 @@ public class OlmSessionTest {
} }
// get bob identity key // 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); String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys);
assertTrue(null != bobIdentityKey); assertTrue(null != bobIdentityKey);
// get bob one time keys // get bob one time keys
assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); try {
Map<String, Map<String, String>> bobOneTimeKeys = bobAccount.oneTimeKeys(); 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); assertNotNull(bobOneTimeKeys);
String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1);
assertNotNull(bobOneTimeKey); assertNotNull(bobOneTimeKey);
...@@ -678,7 +812,14 @@ public class OlmSessionTest { ...@@ -678,7 +812,14 @@ public class OlmSessionTest {
assertTrue(!aliceSession.matchesInboundSessionFrom(null,null)); assertTrue(!aliceSession.matchesInboundSessionFrom(null,null));
// release objects // 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(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
assertTrue(aliceAccount.isReleased()); assertTrue(aliceAccount.isReleased());
......