From fad1e9fe2282f4e292a543bb3d8915900b71a0d8 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 3 Dec 2022 12:45:28 -0800 Subject: [PATCH] add test for pk version of the commands... One missing thing is the ability to generate public keys from private keys for running the code standalone.. --- lora.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lora.py b/lora.py index 3f4b392..07329bb 100644 --- a/lora.py +++ b/lora.py @@ -1576,19 +1576,36 @@ class TestLORAmain(unittest.TestCase): init_key = X25519.gen() resp_key = X25519.gen() + f = {} + for i in [ 'init', 'resp' ]: + key = locals()['%s_key' % i] + + for j in [ 'pub', 'priv' ]: + data = getattr(key, 'get%s' % j)().hex() + file = self.basetempdir / ('%s_%s.key' % (i, j)) + f['%s_%s_key_file' % (i, j)] = file + + with file.open('w') as fp: + fp.write(data) + + keys.append(('pk', ( + [ '-k', f['init_priv_key_file'], + '-p', f['resp_pub_key_file'] ], + [ '-k', f['resp_priv_key_file'], + '-p', f['init_pub_key_file'] ] + ))) for name, (initargs, respargs) in keys: - with self.subTest(name=name): + # XXX - macosx specific library path var + with self.subTest(name=name), patch.dict(os.environ, + dict(DYLD_LIBRARY_PATH=self.origcwd)): self.run_program_keyargs(initargs, respargs) def run_program_keyargs(self, initargs, respargs): try: - # XXX - macosx specific library path var - with patch.dict(os.environ, - dict(DYLD_LIBRARY_PATH=self.origcwd)): - resp = subprocess.Popen([ 'python', __file__, - '-r', 'dummy:TestAttr.dummy_func' ] + - respargs, stdin=DEVNULL, stderr=PIPE, - stdout=PIPE) + resp = subprocess.Popen([ 'python', __file__, + '-r', 'dummy:TestAttr.dummy_func' ] + + respargs, stdin=DEVNULL, stderr=PIPE, + stdout=PIPE) init = subprocess.Popen([ 'python', __file__ ] + initargs + [ 'ping' ], stdin=DEVNULL, stderr=PIPE, @@ -1608,10 +1625,12 @@ class TestLORAmain(unittest.TestCase): self.assertEqual(errout, b'') finally: - init.terminate() + init.kill() _, errout = init.communicate() + #print(repr(errout)) + #sys.stdout.flush() self.assertEqual(errout, b'') - resp.terminate() + resp.kill() _, errout = resp.communicate() self.assertEqual(errout, b'')