From dcbbbca0200e639ddce9c68d845baef97090c470 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 1 Mar 2020 15:15:18 +0100 Subject: [PATCH] random timing for minimail --- test/minimail.py | 20 ++++++++++++++------ test/sync_handshake.py | 11 +++++++---- test/sync_test.py | 6 +++++- utils/pEp | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/test/minimail.py b/test/minimail.py index 3f7766b..06108d4 100644 --- a/test/minimail.py +++ b/test/minimail.py @@ -13,8 +13,8 @@ delete the marker file to re-read all messages """ -# Minimail 1.1 -# Copyleft 2019, p≡p foundation +# Minimail 1.2 +# Copyleft 2019, 2020, p≡p foundation # this file is under GNU General Public License 3.0 @@ -22,11 +22,19 @@ delete the marker file to re-read all messages import os from secrets import token_urlsafe from time import sleep +from random import random -timing = .1 +# set timing to None for random timing +timing = None +def snooze(): + if timing is None: + sleep(random()/2) + else: + sleep(timing) + def unlock(inbox): "clear the inbox from lockfile" @@ -49,14 +57,14 @@ class Lock: def __enter__(self): lockfile = self.inbox / "lock" while lockfile.is_file(): - sleep(timing) + snooze() lockfile.touch() def send(inbox, msg, marker): "send msg to inbox in MIME format" - sleep(timing) + snooze() with Lock(inbox): name = marker + "_" + token_urlsafe(16) + ".eml" with open(inbox / name, "wb") as f: @@ -95,7 +103,7 @@ def recv_all(inbox, marker): txt = f.read(-1) r.append((p, txt)) if not r: - sleep(timing) + snooze() return r diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 36ac4d0..4fec483 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -130,10 +130,11 @@ class UserInterface(pEp.UserInterface): ]) sleep(.5) # user is reading message try: - if options.reject: - self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) - else: - self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) + if not options.noanswer: + if options.reject: + self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) + else: + self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) except NameError: self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) @@ -234,6 +235,8 @@ if __name__=="__main__": help="reject device group") optParser.add_option("--accept", action="store_false", dest="reject", help="accept device group (default)") + optParser.add_option("--no-answer", action="store_true", dest="noanswer", + help="do not answer device group handshake") optParser.add_option("-E", "--end-on", dest="notifications", help="end test on these notifications") optParser.add_option("-j", "--multi-threaded", action="store_true", diff --git a/test/sync_test.py b/test/sync_test.py index 175a2f9..a2cd355 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -102,6 +102,10 @@ if __name__ == "__main__": optParser.add_option("-i", "--imap", action="store_true", dest="imap", help="use imap instead of minimail") + optParser.add_option("-A", "--add-account-after-sync", action="store_true", + dest="add_account", + help="after sync add an account") + options, args = optParser.parse_args() if options.imap: @@ -207,7 +211,7 @@ if __name__ == "__main__": # Phone runs with own_ident = 2 Phone = Process(target=test_for, args=("Phone", "red", end_on, - options.multithreaded, options.imap, 2)) + options.multithreaded, options.imap, 1)) # others run with own_ident = 1 Laptop = Process(target=test_for, args=("Laptop", "green", end_on, diff --git a/utils/pEp b/utils/pEp index 4854e9c..304d241 100755 --- a/utils/pEp +++ b/utils/pEp @@ -72,7 +72,7 @@ try: dst = src.encrypt() else: src.dir = 0 - dst, keys, rating, consumed, flags = src.decrypt() + dst, keys, rating, flags = src.decrypt() print(str(dst))