aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-09 10:25:18 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-09 10:25:18 +0100
commitf257580cb1adb798943b2b9bc54192320c2821e2 (patch)
treed1a9880e896a74f9330018a18c45128f30ac2656 /java/android/OlmLibSdk/olm-sdk/src/androidTest
parent03396102691409083143882ee1ed54e137f183d2 (diff)
verifyEd25519Signature triggers an exception instead of filling an error buffer
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java37
1 files changed, 29 insertions, 8 deletions
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 4096001..bd53e6e 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
@@ -58,7 +58,7 @@ public class OlmUtilityTest {
@Test
public void test01VerifyEd25519Signing() {
String fingerPrintKey = null;
- StringBuffer errorMsg = new StringBuffer();
+ String errorMsg = null;
String message = "{\"algorithms\":[\"m.megolm.v1.aes-sha2\",\"m.olm.v1.curve25519-aes-sha2\"],\"device_id\":\"YMBYCWTWCG\",\"keys\":{\"curve25519:YMBYCWTWCG\":\"KZFa5YUXV2EOdhK8dcGMMHWB67stdgAP4+xwiS69mCU\",\"ed25519:YMBYCWTWCG\":\"0cEgQJJqjgtXUGp4ZXQQmh36RAxwxr8HJw2E9v1gvA0\"},\"user_id\":\"@mxBob14774891254276b253f42-f267-43ec-bad9-767142bfea30:localhost:8480\"}";
OlmAccount account = null;
@@ -98,22 +98,43 @@ public class OlmUtilityTest {
OlmUtility utility = new OlmUtility();
// verify signature
- errorMsg.append("init with anything");
- boolean isVerified = utility.verifyEd25519Signature(messageSignature, fingerPrintKey, message, errorMsg);
+ boolean isVerified;
+
+ isVerified = false;
+ errorMsg = null;
+ try {
+ isVerified = utility.verifyEd25519Signature(messageSignature, fingerPrintKey, message);
+ } catch (Exception e) {
+ errorMsg = e.getMessage();
+ }
assertTrue(isVerified);
- assertTrue(String.valueOf(errorMsg).isEmpty());
+ assertTrue(TextUtils.isEmpty(errorMsg));
// check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC
String badSignature = "Bad signature Bad signature Bad signature..";
- isVerified = utility.verifyEd25519Signature(badSignature, fingerPrintKey, message, errorMsg);
+
+ isVerified = false;
+ errorMsg = null;
+ try {
+ isVerified = utility.verifyEd25519Signature(badSignature, fingerPrintKey, message);
+ } catch (Exception e) {
+ errorMsg = e.getMessage();
+ }
assertFalse(isVerified);
- assertFalse(String.valueOf(errorMsg).isEmpty());
+ assertTrue(!TextUtils.isEmpty(errorMsg));
// check bad fingerprint size => errorMsg = INVALID_BASE64
String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2);
- isVerified = utility.verifyEd25519Signature(messageSignature, badSizeFingerPrintKey, message, errorMsg);
+
+ isVerified = false;
+ errorMsg = null;
+ try {
+ isVerified = utility.verifyEd25519Signature(messageSignature, badSizeFingerPrintKey, message);
+ } catch (Exception e) {
+ errorMsg = e.getMessage();
+ }
assertFalse(isVerified);
- assertFalse(String.valueOf(errorMsg).isEmpty());
+ assertTrue(!TextUtils.isEmpty(errorMsg));
utility.releaseUtility();
assertTrue(utility.isReleased());