mirror of https://gitlab.com/bashrc2/epicyon
c2s send test
parent
6ec09d3909
commit
92fb124713
|
@ -214,9 +214,9 @@ if args.tests:
|
|||
|
||||
if args.testsnetwork:
|
||||
print('Network Tests')
|
||||
testPostMessageBetweenServers()
|
||||
testFollowBetweenServers()
|
||||
testClientToServer()
|
||||
#testPostMessageBetweenServers()
|
||||
#testFollowBetweenServers()
|
||||
sys.exit()
|
||||
|
||||
if args.posts:
|
||||
|
|
3
posts.py
3
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:
|
||||
|
|
|
@ -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)
|
||||
|
|
29
tests.py
29
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...')
|
||||
|
|
Loading…
Reference in New Issue