def createSessionManagers(st_sync=None, st_async=None, expect=None): if st_sync == None: st_sync = SyncInMemoryStorage() if st_async == None: st_async = AsyncInMemoryStorage() try: sm_sync = SessionManager.create(st_sync, DeletingOTPKPolicy, SignalBackend, A_JID, A_DID) except Exception as e: assert expect != None assert isinstance(e, expect) sm_async_promise = SessionManager.create(st_async, DeletingOTPKPolicy, SignalBackend, A_JID, A_DID) if expect == None: sm_async = assertPromiseFulfilled(sm_async_promise) else: assert isinstance(assertPromiseRejected(sm_async_promise), expect) if expect == None: assert isinstance(sm_sync, SessionManager) assert isinstance(sm_async, SessionManager) return st_sync, sm_sync, st_async, sm_async
def createOtherSessionManagers(jid, dids, other_dids, otpk_policy=None): if otpk_policy == None: otpk_policy = DeletingOTPKPolicy sms_sync = {} sms_async = {} for did in dids: st_sync = SyncInMemoryStorage() st_async = AsyncInMemoryStorage() sm_sync = SessionManager.create(st_sync, otpk_policy, SignalBackend, jid, did) sm_async = assertPromiseFulfilled( SessionManager.create(st_async, otpk_policy, SignalBackend, jid, did)) assert isinstance(sm_sync, SessionManager) assert isinstance(sm_async, SessionManager) for other_jid in other_dids: newDeviceList(sm_sync, sm_async, other_jid, other_dids[other_jid]) sms_sync[did] = sm_sync sms_async[did] = sm_async return sms_sync, sms_async
def test_stresstest_async(): # Create 100 random JIDs with 10 random devices each devices = {} main_jid = None main_did = None while len(devices) < 100: jid = generateRandomJID() if main_jid == None: main_jid = jid devices[jid] = set() while len(devices[jid]) < 10: did = omemo.util.generateDeviceID(devices[jid]) if main_did == None: main_did = did devices[jid].add(did) sms = {} for jid in devices: sms[jid] = {} for did in devices[jid]: # Create a SessionManager for that jid+did sms[jid][did] = assertPromiseFulfilled( SessionManager.create(AsyncInMemoryStorage(), DeletingOTPKPolicy, SignalBackend, jid, did)) bundles = {} for jid in devices: bundles[jid] = {} for did in devices[jid]: bundles[jid][did] = sms[jid][did].public_bundle main = sms[main_jid][main_did] # Tell the main SessionManager about all of the other jids and devices for jid in devices: assertPromiseFulfilled(main.newDeviceList(jid, devices[jid])) # Tell the main SessionManager to trust all other jids and devices for jid in devices: for did in devices[jid]: main.trust(jid, did, sms[jid][did].public_bundle.ik) cProfile.runctx( """ assertPromiseFulfilledOrRaise(main.encryptMessage( list(devices.keys()), "This is a stresstest!".encode("UTF-8"), bundles = bundles )) """, {"assertPromiseFulfilledOrRaise": assertPromiseFulfilledOrRaise}, { "main": main, "devices": devices, "bundles": bundles }) # If the code reaches this point, the stress test has passed assert True