From 555c93691af4112e3f2883e59935816e221f5fe3 Mon Sep 17 00:00:00 2001 From: Edouard Tisserant Date: Tue, 11 Oct 2016 01:48:19 +0200 Subject: [PATCH] various enhancements in multiprocess test - to be continued --- test/mp_sync_test.py | 46 ++++++++++++++++++++++++++++++++------------ test/multipEp.py | 35 +++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/test/mp_sync_test.py b/test/mp_sync_test.py index e526637..123ab39 100644 --- a/test/mp_sync_test.py +++ b/test/mp_sync_test.py @@ -2,30 +2,52 @@ test for simplest keysync scenario : two device setting up same account Launch it with something like : -DYLD_LIBRARY_PATH=/Users/ed/lib/ PYTHONPATH=`pwd`/../build/lib.macosx-10.11-x86_64-3.4 python3.4 sync_test.py +LC_ALL=en_US.UTF-8 \ +DYLD_LIBRARY_PATH=/Users/ed/lib/ \ +PYTHONPATH=`pwd`/../build/lib.macosx-10.11-x86_64-3.4 \ +python3.4 mp_sync_test.py """ -import multipEp as mp +stored_message = [] +def store_message(res, action): + stored_message.append(res) +def print_res(res, action): + print(res) + +from multipEp import * + + #("instance name", [instance_action_func, [args], {kwargs}], result_func), + #(manager_action_func, [args], {kwargs}, result_func), scenario0 = [ - #("instance name", [func, [args], {kwargs}]), - ("A", [mp.create_account, ["some.one@some.where", "Some One"]]), - ("B", [mp.create_account, ["some.one@some.where", "Some One"]]), - (mp.cycle_until_no_change, ["A", "B"]), - ("C", [mp.create_account, ["some.one@some.where", "Some One"]]), - (mp.cycle_until_no_change, ["A", "B", "C"]), + ("GroupA1", [create_account, ["some.one@some.where", "Some One"]]), + ("SoloA", [create_account, ["some.other@else.where", "Some Other"]]), + # key exchange + ("SoloA", [send_message, ["some.other@else.where", "some.one@some.where", + "Hey Bro", "Heeeey Brooooo"]]), + ("GroupA1", [send_message, ["some.one@some.where", "some.other@else.where", + "Yo Dude", "Yooooo Duuuude"]]), + ("SoloA", [encrypted_message, ["some.other@else.where", + "some.one@some.where", + "read this", "this is a secret message"]], store_message), + (flush_all_mails,), + ("GroupA2", [create_account, ["some.one@some.where", "Some One"]]), + (cycle_until_no_change, ["GroupA1", "GroupA2"], expect(4)), + ("GroupA2", [decrypt_message, [stored_message]], print_res), + ("GroupA3", [create_account, ["some.one@some.where", "Some One"]]), + (cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(3)), # force consume messages - ("C", [None, None, None, -60*15]) + ("GroupA3", [None, None, None, -60*15]) ] scenario1 = [ #("instance name", [func, [args], {kwargs}]), - ("A", [mp.send_message, ["some.one@some.where", "some.other@else.where", "Hey Bro", "Heeeey Brooooo"]]), - ("B", [mp.send_message, ["some.other@else.where", "some.one@some.where", "Hey Bro", "Heeeey Brooooo"]]), + ("B", [send_message, ["some.other@else.where", "some.one@some.where", "Hey Bro", "Heeeey Brooooo"]]), + ("A", [send_message, ["some.one@some.where", "some.other@else.where", "Hey Bro", "Heeeey Brooooo"]]), ] if __name__ == "__main__": - mp.run_scenario(scenario0) + run_scenario(scenario0) diff --git a/test/multipEp.py b/test/multipEp.py index 0bc99c0..02ed88a 100644 --- a/test/multipEp.py +++ b/test/multipEp.py @@ -39,13 +39,17 @@ def _send_message(address, msg): msgs.append(str(msg)) msgs_folders[address] = msgs +def flush_all_mails(): + global msgs_folders + msgs_folders.clear() + def _encrypted_message(from_address, to_address, shortmsg, longmsg): - m = pEp.outgoing_message(Identity(from_address, from_address)) + m = pEp.outgoing_message(pEp.Identity(from_address, from_address)) m.to = [pEp.Identity(to_address, to_address)] m.shortmsg = shortmsg m.longmsg = longmsg m.encrypt() - return msg + return m def encrypted_message(from_address, to_address, shortmsg, longmsg): return str(_encrypted_message(from_address, to_address, shortmsg, longmsg)) @@ -54,9 +58,19 @@ def send_message(from_address, to_address, shortmsg, longmsg): msg = _encrypted_message(from_address, to_address, shortmsg, longmsg) _send_message(to_address, msg) -def decrypt_message(msgstr): - msg = pEp.incoming_message(msgstr) - msg2, keys, rating, consumed, flags = msg.decrypt() +def decrypt_message(msgs): + res = [] + for msgstr in msgs: + msg = pEp.incoming_message(msgstr) + printi("--- decrypt()") + msg.recv = int(time.time()) + printmsg(msg) + msg2, keys, rating, consumed, flags = msg.decrypt() + res.append(rating) + printi("->-", rating, "->-") + printmsg(msg2) + printi("---") + return res def printi(*args): global indent @@ -255,10 +269,10 @@ def run_scenario(scenario): handshakes_seen = manager.list() handshakes_validated = manager.list() - res = None for action in scenario: + res = None output = None - if type(action[-1]) == types.FunctionType: + if len(action) > 1 and type(action[-1]) == types.FunctionType: output = action[-1] action = action[:-1] @@ -288,9 +302,14 @@ def cycle_until_no_change(*instancelist, maxcycles=20): count += 1 if dict(msgs_folders) == tmp: - return + return count if count >= maxcycles: raise Exception("Too many cycles waiting for stability") +def expect(expectation): + def _expect(res, action): + if(expectation != res): + raise Exception("Expected " + str(expectation) + ", got " + str(res)) + return _expect