forked from indymedia/epicyon
c2s send test
parent
6ec09d3909
commit
92fb124713
|
@ -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:
|
||||||
|
|
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:
|
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:
|
||||||
|
|
|
@ -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)
|
||||||
|
|
29
tests.py
29
tests.py
|
@ -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,15 +1034,38 @@ 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):
|
||||||
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1:
|
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1:
|
||||||
break
|
break
|
||||||
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...')
|
||||||
|
|
Loading…
Reference in New Issue