From 92fb124713e73f5be4b027baa105c17c7e7dbfca Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 16 Jul 2019 12:33:40 +0100 Subject: [PATCH] c2s send test --- epicyon.py | 4 ++-- posts.py | 3 +++ session.py | 1 + tests.py | 29 +++++++++++++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/epicyon.py b/epicyon.py index 5d8caf6fc..7c480eea3 100644 --- a/epicyon.py +++ b/epicyon.py @@ -214,9 +214,9 @@ if args.tests: if args.testsnetwork: print('Network Tests') + testPostMessageBetweenServers() + testFollowBetweenServers() testClientToServer() - #testPostMessageBetweenServers() - #testFollowBetweenServers() sys.exit() if args.posts: diff --git a/posts.py b/posts.py index fb6a5a944..20ff60cd4 100644 --- a/posts.py +++ b/posts.py @@ -673,6 +673,9 @@ def sendPostViaServer(session,fromNickname: str,password: str, \ debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int: """Send a post via a proxy (c2s) """ + if not session: + print('WARN: No session for sendPostViaServer') + return 6 withDigest=True if toPort!=80 and toPort!=443: diff --git a/session.py b/session.py index 0400eaabe..dab3bc7b1 100644 --- a/session.py +++ b/session.py @@ -50,6 +50,7 @@ def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers if not capability.startswith('cap'): # check that we are posting to a permitted domain if not urlPermitted(inboxUrl,federationList,capability): + print('postJson: '+inboxUrl+' not permitted') return None postResult = session.post(url = inboxUrl, data = json.dumps(postJsonObject), headers=headers) diff --git a/tests.py b/tests.py index 556d220f8..26f22425a 100644 --- a/tests.py +++ b/tests.py @@ -1022,7 +1022,9 @@ def testClientToServer(): personCache={} password='alicepass' outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox' + inboxPath=bobDir+'/accounts/bob@'+bobDomain+'/inbox' assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0 + assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==0 sendResult= \ sendPostViaServer(sessionAlice,'alice',password, \ aliceDomain,alicePort, \ @@ -1032,15 +1034,38 @@ def testClientToServer(): cachedWebfingers,personCache, \ True,None,None,None) print('sendResult: '+str(sendResult)) - assert sendResult==0 for i in range(30): if os.path.isdir(outboxPath): if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1: break time.sleep(1) - + assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1 + print(">>> c2s post arrived in Alice's outbox") + + for i in range(30): + if os.path.isdir(inboxPath): + if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1: + break + time.sleep(1) + + assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1 + print(">>> s2s post arrived in Bob's inbox") + print("c2s send success") + + # stop the servers + thrAlice.kill() + thrAlice.join() + assert thrAlice.isAlive()==False + + thrBob.kill() + thrBob.join() + assert thrBob.isAlive()==False + + os.chdir(baseDir) + shutil.rmtree(aliceDir) + shutil.rmtree(bobDir) def runAllTests(): print('Running tests...')