c2s send test

master
Bob Mottram 2019-07-16 12:33:40 +01:00
parent 6ec09d3909
commit 92fb124713
4 changed files with 33 additions and 4 deletions

View File

@ -214,9 +214,9 @@ if args.tests:
if args.testsnetwork: if args.testsnetwork:
print('Network Tests') print('Network Tests')
testPostMessageBetweenServers()
testFollowBetweenServers()
testClientToServer() testClientToServer()
#testPostMessageBetweenServers()
#testFollowBetweenServers()
sys.exit() sys.exit()
if args.posts: if args.posts:

View File

@ -673,6 +673,9 @@ def sendPostViaServer(session,fromNickname: str,password: str, \
debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int: debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int:
"""Send a post via a proxy (c2s) """Send a post via a proxy (c2s)
""" """
if not session:
print('WARN: No session for sendPostViaServer')
return 6
withDigest=True withDigest=True
if toPort!=80 and toPort!=443: if toPort!=80 and toPort!=443:

View File

@ -50,6 +50,7 @@ def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers
if not capability.startswith('cap'): if not capability.startswith('cap'):
# check that we are posting to a permitted domain # check that we are posting to a permitted domain
if not urlPermitted(inboxUrl,federationList,capability): if not urlPermitted(inboxUrl,federationList,capability):
print('postJson: '+inboxUrl+' not permitted')
return None return None
postResult = session.post(url = inboxUrl, data = json.dumps(postJsonObject), headers=headers) postResult = session.post(url = inboxUrl, data = json.dumps(postJsonObject), headers=headers)

View File

@ -1022,7 +1022,9 @@ def testClientToServer():
personCache={} personCache={}
password='alicepass' password='alicepass'
outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox' 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(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= \ sendResult= \
sendPostViaServer(sessionAlice,'alice',password, \ sendPostViaServer(sessionAlice,'alice',password, \
aliceDomain,alicePort, \ aliceDomain,alicePort, \
@ -1032,7 +1034,6 @@ def testClientToServer():
cachedWebfingers,personCache, \ cachedWebfingers,personCache, \
True,None,None,None) True,None,None,None)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))
assert sendResult==0
for i in range(30): for i in range(30):
if os.path.isdir(outboxPath): if os.path.isdir(outboxPath):
@ -1041,6 +1042,30 @@ def testClientToServer():
time.sleep(1) time.sleep(1)
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==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(): def runAllTests():
print('Running tests...') print('Running tests...')