blob: 482ae0fedf439ec74f771aba0a79ab09a78a0d35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package org.matrix.olm;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
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.assertNotNull;
import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OlmGroupTest {
private static final String LOG_TAG = "OlmSessionTest";
private static OlmManager mOlmManager;
@BeforeClass
public static void setUpClass(){
// load native lib
mOlmManager = new OlmManager();
String version = mOlmManager.getOlmLibVersion();
assertNotNull(version);
Log.d(LOG_TAG, "## setUpClass(): lib version="+version);
}
@Test
public void test00AliceToBob() {
// TBD
}
/**
* Basic test:
* - alice creates an account
* - bob creates an account
* - alice creates an outbound group session
* - bob creates an inbound group session with alice's outbound session key
* - alice encrypts a message with its session
* - bob decrypts the encrypted message with its session
*/
//@Test
public void test01AliceToBob() {
// creates alice outbound session
OlmOutboundGroupSession aliceOutboundSession = new OlmOutboundGroupSession();
// test accounts creation
String aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier();
assertNotNull(aliceSessionIdentifier);
assertTrue(aliceSessionIdentifier.length()>0);
String aliceOutboundSessionKey = aliceOutboundSession.sessionKey();
assertNotNull(aliceOutboundSessionKey);
assertTrue(aliceOutboundSessionKey.length()>0);
long messageIndex = aliceOutboundSession.messageIndex();
assertTrue(0==messageIndex);
String clearMessage = "Hello!";
String encryptedMessage = aliceOutboundSession.encryptMessage(clearMessage);
assertNotNull(encryptedMessage);
messageIndex = aliceOutboundSession.messageIndex();
assertTrue(1==messageIndex);
assertTrue(encryptedMessage.length()>=0);
OlmInboundGroupSession bobInboundSession = new OlmInboundGroupSession();
bobInboundSession.initInboundGroupSessionWithSessionKey(aliceOutboundSessionKey);
// check session identifiers are equals
aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier();
String bobSessionIdentifier = aliceOutboundSession.sessionIdentifier();
assertTrue(aliceSessionIdentifier.equals(bobSessionIdentifier ));
String decryptedMessage = bobInboundSession.decryptMessage(encryptedMessage);
assertTrue(decryptedMessage.equals(bobSessionIdentifier ));
}
//@Test
public void test02InboundGroupSession() {
// creates alice outbound session
OlmInboundGroupSession aliceInboundSession = new OlmInboundGroupSession();
// test session identifier
String sessionIdentifier = aliceInboundSession.sessionIdentifier();
assertNotNull(sessionIdentifier);
assertTrue(sessionIdentifier.length()>0);
}
}
|