use of org.matrix.androidsdk.common.SessionTestParams in project matrix-android-sdk by matrix-org.
the class LazyLoadingTestHelper method createScenario.
/**
* Create a base scenario for all lazy loading tests
* Common initial conditions:
* - Bob create a public room named "LazyLoading Test Room"
* - Sam and Alice join the room
* - Dave is invited
* - Alice sends 50 messages
* - Bob sends 1 message
* - Alice sends 50 messages
* - Alice makes an initial /sync with lazy-loading enabled or not
*
* @param withLazyLoading true to enable lazy loading for Alice, Bob and Sam accounts
* @return initialized data
*/
public LazyLoadingScenarioData createScenario(boolean withLazyLoading) throws Exception {
final SessionTestParams createSessionParams = new SessionTestParams(true);
MXSession aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, createSessionParams);
MXSession bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, createSessionParams);
MXSession samSession = mTestHelper.createAccount(TestConstants.USER_SAM, createSessionParams);
final String aliceId = aliceSession.getMyUserId();
final String bobId = bobSession.getMyUserId();
final String samId = samSession.getMyUserId();
final Map<String, String> results = new HashMap<>();
CountDownLatch latch = new CountDownLatch(1);
bobSession.createRoom(new TestApiCallback<String>(latch) {
@Override
public void onSuccess(String info) {
results.put("roomId", info);
super.onSuccess(info);
}
});
mTestHelper.await(latch);
final String roomId = results.get("roomId");
final Room bobRoom = bobSession.getDataHandler().getRoom(roomId);
// update name and join rules
latch = new CountDownLatch(1);
bobRoom.updateName("LazyLoading Test Room", new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
latch = new CountDownLatch(1);
bobRoom.updateJoinRules(RoomState.JOIN_RULE_PUBLIC, new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
// sam join
latch = new CountDownLatch(1);
samSession.joinRoom(roomId, new TestApiCallback<String>(latch));
mTestHelper.await(latch);
// alice join
latch = new CountDownLatch(1);
aliceSession.joinRoom(roomId, new TestApiCallback<String>(latch));
mTestHelper.await(latch);
final Room aliceRoom = aliceSession.getDataHandler().getStore().getRoom(roomId);
// invite dave
latch = new CountDownLatch(1);
bobRoom.invite(bobSession, "@dave:localhost:8480", new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
// Send messages
final List<Event> aliceFirstMessages = mTestHelper.sendTextMessage(aliceRoom, "Alice message", 50);
final List<Event> bobMessages = mTestHelper.sendTextMessage(bobRoom, "Bob message", 1);
final List<Event> aliceLastMessages = mTestHelper.sendTextMessage(aliceRoom, "Alice message", 50);
Assert.assertEquals(50, aliceFirstMessages.size());
Assert.assertEquals(1, bobMessages.size());
Assert.assertEquals(50, aliceLastMessages.size());
final String bobMessageId = bobMessages.isEmpty() ? null : bobMessages.get(0).eventId;
// Clear sessions and open new ones
final Context context = InstrumentationRegistry.getContext();
aliceSession.clear(context);
bobSession.clear(context);
samSession.clear(context);
final SessionTestParams logSessionParams = new SessionTestParams(false, false, withLazyLoading);
aliceSession = mTestHelper.logIntoAccount(aliceId, logSessionParams);
bobSession = mTestHelper.logIntoAccount(bobId, logSessionParams);
samSession = mTestHelper.logIntoAccount(samId, logSessionParams);
return new LazyLoadingScenarioData(aliceSession, bobSession, samSession, roomId, bobMessageId);
}
use of org.matrix.androidsdk.common.SessionTestParams in project matrix-android-sdk by matrix-org.
the class RoomNameTestHelper method createScenario.
/**
* Create a base scenario for all room name tests
*
* @param nbOfUsers nb of user to create and to invite in the room (min to 1)
* @param roomName initial room name, or null for no room name
* @param withLazyLoading true to enable lazy loading for alice account
* @return initialized data
*/
public RoomNameScenarioData createScenario(final int nbOfUsers, @Nullable final String roomName, final boolean withLazyLoading) throws Exception {
final SessionTestParams createSessionParams = new SessionTestParams(true);
List<MXSession> createdSessions = new ArrayList<>(nbOfUsers);
// Create all the accounts
for (int i = 0; i < nbOfUsers; i++) {
MXSession session = mTestHelper.createAccount("User_" + i, createSessionParams);
createdSessions.add(session);
}
Assert.assertEquals(nbOfUsers, createdSessions.size());
// First user create a Room
final MXSession firstSession = createdSessions.get(0);
final Map<String, String> results = new HashMap<>();
CountDownLatch latch = new CountDownLatch(1);
firstSession.createRoom(new TestApiCallback<String>(latch) {
@Override
public void onSuccess(String info) {
results.put("roomId", info);
super.onSuccess(info);
}
});
mTestHelper.await(latch);
final String roomId = results.get("roomId");
final Room room = firstSession.getDataHandler().getRoom(roomId);
// Update room name
if (roomName != null) {
latch = new CountDownLatch(1);
room.updateName(roomName, new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
}
// update join rules
latch = new CountDownLatch(1);
room.updateJoinRules(RoomState.JOIN_RULE_PUBLIC, new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
// all other users join the room
for (int i = 1; i < nbOfUsers; i++) {
latch = new CountDownLatch(1);
createdSessions.get(i).joinRoom(roomId, new TestApiCallback<String>(latch));
mTestHelper.await(latch);
}
// invite dave
latch = new CountDownLatch(1);
room.invite(firstSession, "@dave:localhost:8480", new TestApiCallback<Void>(latch));
mTestHelper.await(latch);
final SessionTestParams logSessionParams = new SessionTestParams(true, false, withLazyLoading);
List<MXSession> loggedSessions = new ArrayList<>(nbOfUsers);
// open new sessions, using the same user ids
for (MXSession session : createdSessions) {
MXSession loggedSession = mTestHelper.logIntoAccount(session.getMyUserId(), logSessionParams);
loggedSessions.add(loggedSession);
}
// Clear created sessions (must be done after getting the user ids)
mTestHelper.clearAllSessions(createdSessions);
return new RoomNameScenarioData(loggedSessions, roomId);
}
use of org.matrix.androidsdk.common.SessionTestParams in project matrix-android-sdk by matrix-org.
the class CryptoRestTest method test03_testClaimOneTimeKeysForUsersDevices.
@Test
public void test03_testClaimOneTimeKeysForUsersDevices() throws Exception {
Context context = InstrumentationRegistry.getContext();
final SessionTestParams testParams = new SessionTestParams(true);
final MXSession bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, testParams);
final MXSession aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, testParams);
final Map<String, Object> results = new HashMap<>();
final Map<String, Object> otks = new HashMap<>();
{
Map<String, Object> map = new HashMap<>();
map.put("key", "ueuHES/Q0P1MZ4J3IUpC8iQTkgQNX66ZpxVLUaTDuB8");
Map<String, String> signaturesubMap = new HashMap<>();
signaturesubMap.put("ed25519:deviceId1", "signature1");
Map<String, Object> signatureMap = new HashMap<>();
signatureMap.put("@user1", signaturesubMap);
map.put("signatures", signatureMap);
otks.put("curve25519:AAAABQ", map);
}
{
Map<String, Object> map = new HashMap<>();
map.put("key", "PmyaaB68Any+za9CuZXzFsQZW31s/TW6XbAB9akEpQs");
Map<String, String> signaturesubMap = new HashMap<>();
signaturesubMap.put("ed25519:deviceId2", "signature2");
Map<String, Object> signatureMap = new HashMap<>();
signatureMap.put("@user2", signaturesubMap);
map.put("signatures", signatureMap);
otks.put("curve25519:AAAABA", map);
}
CountDownLatch lock1 = new CountDownLatch(1);
bobSession.getCryptoRestClientForTest().uploadKeys(null, otks, "dev1", new TestApiCallback<KeysUploadResponse>(lock1) {
@Override
public void onSuccess(KeysUploadResponse keysUploadResponse) {
results.put("keysUploadResponse", keysUploadResponse);
super.onSuccess(keysUploadResponse);
}
});
mTestHelper.await(lock1);
KeysUploadResponse bobKeysUploadResponse = (KeysUploadResponse) results.get("keysUploadResponse");
Assert.assertNotNull(bobKeysUploadResponse);
MXUsersDevicesMap<String> usersDevicesKeyTypesMap = new MXUsersDevicesMap<>();
usersDevicesKeyTypesMap.setObject("curve25519", bobSession.getMyUserId(), "dev1");
CountDownLatch lock2 = new CountDownLatch(1);
aliceSession.getCryptoRestClientForTest().claimOneTimeKeysForUsersDevices(usersDevicesKeyTypesMap, new TestApiCallback<MXUsersDevicesMap<MXKey>>(lock2) {
@Override
public void onSuccess(MXUsersDevicesMap<MXKey> usersDevicesMap) {
results.put("usersDevicesMap", usersDevicesMap);
super.onSuccess(usersDevicesMap);
}
});
mTestHelper.await(lock2);
MXUsersDevicesMap<MXKey> oneTimeKeys = (MXUsersDevicesMap<MXKey>) results.get("usersDevicesMap");
Assert.assertNotNull(oneTimeKeys);
Assert.assertNotNull(oneTimeKeys.getMap());
Assert.assertEquals(1, oneTimeKeys.getMap().size());
MXKey bobOtk = oneTimeKeys.getObject("dev1", bobSession.getMyUserId());
Assert.assertNotNull(bobOtk);
Assert.assertEquals(MXKey.KEY_CURVE_25519_TYPE, bobOtk.type);
Assert.assertEquals("AAAABA", bobOtk.keyId);
Assert.assertEquals("curve25519:AAAABA", bobOtk.getKeyFullId());
Assert.assertEquals("PmyaaB68Any+za9CuZXzFsQZW31s/TW6XbAB9akEpQs", bobOtk.value);
Assert.assertNotNull(bobOtk.signatures);
List<String> keys = new ArrayList<>(bobOtk.signatures.keySet());
Assert.assertEquals(1, keys.size());
bobSession.clear(context);
aliceSession.clear(context);
}
use of org.matrix.androidsdk.common.SessionTestParams in project matrix-android-sdk by matrix-org.
the class CryptoRestTest method test01_testDeviceKeys.
@Test
public void test01_testDeviceKeys() throws Exception {
final Context context = InstrumentationRegistry.getContext();
final SessionTestParams testParams = new SessionTestParams(true);
final MXSession bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, testParams);
final Map<String, Object> results = new HashMap<>();
String ed25519key = "wV5E3EUSHpHuoZLljNzojlabjGdXT3Mz7rugG9zgbkI";
MXDeviceInfo bobDevice = new MXDeviceInfo("dev1");
bobDevice.userId = bobSession.getMyUserId();
bobDevice.algorithms = Arrays.asList(CryptoConstantsKt.MXCRYPTO_ALGORITHM_OLM);
Map<String, String> keysMap = new HashMap<>();
keysMap.put("ed25519:" + bobDevice.deviceId, ed25519key);
bobDevice.keys = keysMap;
CountDownLatch lock0 = new CountDownLatch(1);
bobSession.getCryptoRestClientForTest().uploadKeys(bobDevice.JSONDictionary(), null, "dev1", new TestApiCallback<KeysUploadResponse>(lock0) {
@Override
public void onSuccess(KeysUploadResponse keysUploadResponse) {
results.put("keysUploadResponse", keysUploadResponse);
super.onSuccess(keysUploadResponse);
}
});
mTestHelper.await(lock0);
KeysUploadResponse keysUploadResponse = (KeysUploadResponse) results.get("keysUploadResponse");
Assert.assertNotNull(keysUploadResponse);
Assert.assertNotNull(keysUploadResponse.oneTimeKeyCounts);
Assert.assertTrue(keysUploadResponse.oneTimeKeyCounts.isEmpty());
Assert.assertEquals(0, keysUploadResponse.oneTimeKeyCountsForAlgorithm("deded"));
CountDownLatch lock1 = new CountDownLatch(1);
bobSession.getCryptoRestClientForTest().downloadKeysForUsers(Arrays.asList(bobSession.getMyUserId()), null, new TestApiCallback<KeysQueryResponse>(lock1) {
@Override
public void onSuccess(KeysQueryResponse keysQueryResponse) {
results.put("keysQueryResponse", keysQueryResponse);
super.onSuccess(keysQueryResponse);
}
});
mTestHelper.await(lock1);
KeysQueryResponse keysQueryResponse = (KeysQueryResponse) results.get("keysQueryResponse");
Assert.assertNotNull(keysQueryResponse);
Assert.assertNotNull(keysQueryResponse.deviceKeys);
MXUsersDevicesMap<MXDeviceInfo> deviceInfos = new MXUsersDevicesMap<>(keysQueryResponse.deviceKeys);
Assert.assertNotNull(deviceInfos.getUserIds());
Assert.assertEquals(1, deviceInfos.getUserIds().size());
List<String> deviceIds = deviceInfos.getUserDeviceIds(bobSession.getMyUserId());
Assert.assertNotNull(deviceIds);
Assert.assertEquals(1, deviceIds.size());
MXDeviceInfo bobDevice2 = deviceInfos.getObject("dev1", bobSession.getMyUserId());
Assert.assertNotNull(bobDevice2);
Assert.assertEquals("dev1", bobDevice2.deviceId);
Assert.assertEquals(bobDevice2.userId, bobSession.getMyUserId());
bobSession.clear(context);
}
use of org.matrix.androidsdk.common.SessionTestParams in project matrix-android-sdk by matrix-org.
the class CryptoRestTest method test02_testOneTimeKeys.
@Test
public void test02_testOneTimeKeys() throws Exception {
Context context = InstrumentationRegistry.getContext();
final SessionTestParams testParams = new SessionTestParams(true);
final MXSession bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, testParams);
final Map<String, Object> results = new HashMap<>();
final Map<String, Object> otks = new HashMap<>();
otks.put("curve25519:AAAABQ", "ueuHES/Q0P1MZ4J3IUpC8iQTkgQNX66ZpxVLUaTDuB8");
otks.put("curve25519:AAAABA", "PmyaaB68Any+za9CuZXzFsQZW31s/TW6XbAB9akEpQs");
CountDownLatch lock1 = new CountDownLatch(1);
bobSession.getCryptoRestClientForTest().uploadKeys(null, otks, "dev1", new TestApiCallback<KeysUploadResponse>(lock1) {
@Override
public void onSuccess(KeysUploadResponse keysUploadResponse) {
results.put("keysUploadResponse", keysUploadResponse);
super.onSuccess(keysUploadResponse);
}
});
mTestHelper.await(lock1);
KeysUploadResponse keysUploadResponse = (KeysUploadResponse) results.get("keysUploadResponse");
Assert.assertNotNull(keysUploadResponse);
Assert.assertNotNull(keysUploadResponse.oneTimeKeyCounts);
Assert.assertEquals(1, keysUploadResponse.oneTimeKeyCounts.size());
Assert.assertEquals(2, keysUploadResponse.oneTimeKeyCountsForAlgorithm("curve25519"));
Assert.assertEquals(0, keysUploadResponse.oneTimeKeyCountsForAlgorithm("deded"));
bobSession.clear(context);
}
Aggregations