aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-11-28 11:56:20 +0100
committerpedroGitt <pedro.contreiras@amdocs.com>2016-11-28 11:56:20 +0100
commitac0ccb224dfac108276f30606e5cd114db3c5691 (patch)
tree7ed7f59e530305f5ea876dc7a20c546720f625a4 /java/android/OlmLibSdk/olm-sdk/src/androidTest
parent0263cd3039568bd5e5b374451efc0e37c2629592 (diff)
Update decryptMessage() API with the error message as an output parameter
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
index 7e0324b..fe36858 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
@@ -151,8 +151,10 @@ public class OlmGroupSessionTest {
@Test
public void test10InboundDecryptMessage() {
// test decrypted message
+ StringBuffer errorMsg = new StringBuffer();
OlmInboundGroupSession.DecryptIndex index = new OlmInboundGroupSession.DecryptIndex();
- mBobDecryptedMessage = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage, index);
+
+ mBobDecryptedMessage = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage, index, errorMsg);
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(0==index.mIndex);
}
@@ -437,11 +439,43 @@ public class OlmGroupSessionTest {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false);
}
+ StringBuffer errorMsg = new StringBuffer();
OlmInboundGroupSession.DecryptIndex index = new OlmInboundGroupSession.DecryptIndex();
- String decryptedMessage = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji, index);
+
+ String decryptedMessage = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji, index, errorMsg);
assertNotNull(decryptedMessage);
assertTrue(13==index.mIndex);
}
+
+ /**
+ * Specific test to check an error message is returned by decryptMessage() API.<br>
+ * A corrupted encrypted message is passed, and a INVALID_BASE64 is
+ * espexted.
+ **/
+ @Test
+ public void test19TestErrorMessageReturnedInDecrypt() {
+ OlmInboundGroupSession bobInboundGroupSession=null;
+ final String EXPECTED_ERROR_MESSAGE= "INVALID_BASE64";
+ StringBuffer errorMsg = new StringBuffer();
+ OlmInboundGroupSession.DecryptIndex index = new OlmInboundGroupSession.DecryptIndex();
+
+ String sessionKeyRef = "AgAAAAycZE6AekIctJWYxd2AWLOY15YmxZODm/WkgbpWkyycp6ytSp/R+wo84jRrzBNWmv6ySLTZ9R0EDOk9VI2eZyQ6Efdwyo1mAvrWvTkZl9yALPdkOIVHywyG65f1SNiLrnsln3hgsT1vUrISGyKtsljoUgQpr3JDPEhD0ilAi63QBjhnGCW252b+7nF+43rb6O6lwm93LaVwe2341Gdp6EkhTUvetALezEqDOtKN00wVqAbq0RQAnUJIowxHbMswg+FyoR1K1oCjnVEoF23O9xlAn5g1XtuBZP3moJlR2lwsBA";
+ String corruptedEncryptedMsg = "AwgANYTHINGf87ge45ge7gr*/rg5ganything4gr41rrgr4re55tanythingmcsXUkhDv0UePj922kgf+";
+
+ // valid INBOUND GROUP SESSION
+ try {
+ bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef);
+ } catch (OlmException e) {
+ assertTrue("Exception in test19TestErrorMessageReturnedInDecrypt, Exception code=" + e.getExceptionCode(), false);
+ }
+
+ String decryptedMessage = bobInboundGroupSession.decryptMessage(corruptedEncryptedMsg, index, errorMsg);
+ assertTrue(0!=EXPECTED_ERROR_MESSAGE.length());
+ assertTrue(EXPECTED_ERROR_MESSAGE.equals(errorMsg.toString()));
+ assertTrue(null==decryptedMessage);
+ assertTrue(0==index.mIndex);
+ }
+
}