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:
print('Network Tests')
testPostMessageBetweenServers()
testFollowBetweenServers()
testClientToServer()
#testPostMessageBetweenServers()
#testFollowBetweenServers()
sys.exit()
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:
"""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:

View File

@ -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)

View File

@ -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...')