From cabf730cae0d02fc37f104b00c6b64c8c5d4a573 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Fri, 25 Oct 2019 12:11:53 +0200 Subject: [PATCH 1/5] add engine debug color --- src/pEpmodule.cc | 10 +++++++++- test/sync_handshake.py | 6 ++++++ utils/pEp | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 8b0cab8..1a01338 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -113,6 +113,11 @@ namespace pEp { { adapter.shutdown_sync(); } + + void debug_color(int ansi_color) + { + ::set_debug_color(adapter.session(), ansi_color); + } } } @@ -370,7 +375,7 @@ BOOST_PYTHON_MODULE(pEp) .def("__deepcopy__", &Message::deepcopy) .def("__copy__", &Message::copy); - // basic API + // basic API and key management API def("update_identity", &pEp::PythonAdapter::update_identity, "update_identity(ident)\n" @@ -518,6 +523,9 @@ BOOST_PYTHON_MODULE(pEp) "call this from another thread to shut down the sync thread\n" ); + def("debug_color", &pEp::PythonAdapter::debug_color, + "for debug builds set ANSI color value"); + // codecs call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search)); diff --git a/test/sync_handshake.py b/test/sync_handshake.py index a3a993a..3f94b77 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -132,6 +132,12 @@ def run(name, color=None): if color: global output output = lambda x: print(colored(x, color)) + if color == "red": + pEp.debug_color(31) + elif color == "green": + pEp.debug_color(32) + elif color == "cyan": + pEp.debug_color(36) me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name) pEp.myself(me) diff --git a/utils/pEp b/utils/pEp index d245d9b..4854e9c 100755 --- a/utils/pEp +++ b/utils/pEp @@ -26,6 +26,8 @@ parser.add_argument('--decrypt', '-d', help='decrypt p≡p message', action='store_true', dest='decrypt') parser.add_argument('--import', '-i', help='import key data in PGP format', action='store_true', dest='keyimport') +parser.add_argument('--export', '-x', help='export key data in PGP format', + action='store_true', dest='keyexport') parser.add_argument('--version', '-V', help='show program version', action='store_true', dest='version') parser.add_argument('files', metavar='FILE', nargs='*', @@ -33,8 +35,8 @@ parser.add_argument('files', metavar='FILE', nargs='*', args = parser.parse_args() -if not(args.encrypt) and not(args.decrypt) and not (args.keyimport) and not(args.version): - print('use either --encrypt, --decrypt or --import', file=sys.stderr) +if not(args.encrypt) and not(args.decrypt) and not (args.keyimport) and not (args.keyexport) and not(args.version): + print('use either --encrypt, --decrypt, --import or --export', file=sys.stderr) sys.exit(2) if args.version: @@ -85,6 +87,17 @@ try: except RuntimeError: print("error importing key(s)", file=sys.stderr) + elif args.keyexport: + if filename == '-': + text = sys.stdin.read() + else: + with open(filename, "rb") as f: + text = f.read() + try: + import_key(text) + except RuntimeError: + print("error exporting key(s)", file=sys.stderr) + except KeyboardInterrupt: print('\n', file=sys.stderr) sys.exit(1) From 419072ce7e4455bd05520e5021815575f3630ec7 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Tue, 29 Oct 2019 12:03:56 +0100 Subject: [PATCH 2/5] adding dependency description --- dependencies.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 dependencies.txt diff --git a/dependencies.txt b/dependencies.txt new file mode 100644 index 0000000..45d5a15 --- /dev/null +++ b/dependencies.txt @@ -0,0 +1,4 @@ +pEpPythonAdapter => Python 3 + => g++ | clang | CL.EXE + -> boost::python + -> pEpEngine From 14e0e458f1e43ba092aa041247d03c9c6a5d35a0 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 14 Nov 2019 12:19:01 +0100 Subject: [PATCH 3/5] yellow color for notify --- test/sync_handshake.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 3f94b77..2d60cdb 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -98,8 +98,9 @@ def messageToSend(msg): class UserInterface(pEp.UserInterface): def notifyHandshake(self, me, partner, signal): - output("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " + - str(partner.fpr)) + print(colored(str(signal), "yellow"), end=" ") + output("on " + device_name + "" if not me.fpr else + "for identities " + str(me.fpr) + " " + str(partner.fpr)) if me.fpr and partner.fpr: assert me.fpr != partner.fpr From f7af6ebb21b9b92f3044ff65a3d073a0e7b07f48 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 14 Nov 2019 14:40:39 +0100 Subject: [PATCH 4/5] add new notify --- src/pEpmodule.cc | 2 +- test/sync_handshake.py | 11 ++++++++--- test/sync_test.py | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 1a01338..d3ed6a6 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -480,7 +480,7 @@ BOOST_PYTHON_MODULE(pEp) .value("SYNC_NOTIFY_TIMEOUT" , SYNC_NOTIFY_TIMEOUT) .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED) .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED) - .value("SYNC_NOTIFY_OVERTAKEN" , SYNC_NOTIFY_OVERTAKEN) + .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED", SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED) .value("SYNC_NOTIFY_SOLE" , SYNC_NOTIFY_SOLE) .value("SYNC_NOTIFY_IN_GROUP" , SYNC_NOTIFY_IN_GROUP); diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 2d60cdb..67d28f9 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -48,10 +48,11 @@ SYNC_HANDSHAKE_ACCEPTED = 0 SYNC_HANDSHAKE_REJECTED = 1 the_end = False -end_on = ( +end_on = [ pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED, - pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED - ) + pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED, + pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED, + ] def print_msg(p): @@ -109,6 +110,10 @@ class UserInterface(pEp.UserInterface): pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE, pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP ): + end_on.extend([ + pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE, + pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP, + ]) try: if options.reject: self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) diff --git a/test/sync_test.py b/test/sync_test.py index 1849305..b8ad700 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -110,6 +110,14 @@ if __name__ == "__main__": if options.cleanall: rmrf("Backup") + if options.setup_only: + os.makedirs("TestInbox", exist_ok=True) + setup("Phone") + setup("Laptop") + if options.third: + setup("Pad") + + elif options.backup: rmrf("Backup") From e3dc1efaa967a806a5ee98f0c0a11b732f87883b Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 14 Nov 2019 15:39:16 +0100 Subject: [PATCH 5/5] option -n: no end --- test/sync_handshake.py | 14 ++++++++++---- test/sync_test.py | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 67d28f9..564fe61 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -110,10 +110,11 @@ class UserInterface(pEp.UserInterface): pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE, pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP ): - end_on.extend([ - pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE, - pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP, - ]) + if isinstance(end_on, list): + end_on.extend([ + pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE, + pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP, + ]) try: if options.reject: self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) @@ -197,6 +198,8 @@ if __name__=="__main__": optParser.add_option("-j", "--multi-threaded", action="store_true", dest="multithreaded", help="use multithreaded instead of single threaded implementation") + optParser.add_option("-n", "--noend", action="store_true", + dest="noend", help="do not end") options, args = optParser.parse_args() if not options.exec_for: @@ -208,6 +211,9 @@ if __name__=="__main__": except TypeError: end_on = (end_on,) + if options.noend: + end_on = (None,) + multithreaded = options.multithreaded run(options.exec_for, options.color) diff --git a/test/sync_test.py b/test/sync_test.py index b8ad700..1083f09 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -89,6 +89,8 @@ if __name__ == "__main__": help="setup environment, then stop") optParser.add_option("-p", "--print", action="store_true", dest="print", help="print sync message trace in inbox") + optParser.add_option("-n", "--noend", action="store_true", dest="noend", + help="do not end") optParser.add_option("-E", "--end-on", dest="notifications", help="end test on these notifications") optParser.add_option("-3", "--third-device", action="store_true", dest="third", @@ -167,6 +169,9 @@ if __name__ == "__main__": try: None in end_on except TypeError: end_on = (end_on,) + elif options.noend: + end_on = (None,) + Phone = Process(target=test_for, args=("Phone", "red", end_on, options.multithreaded)) Laptop = Process(target=test_for, args=("Laptop", "green", end_on,