forked from indymedia/epicyon
Set up two test servers
parent
8705b9e44c
commit
906e3de1de
|
@ -12,9 +12,6 @@ import json
|
||||||
import cgi
|
import cgi
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from tests import testHttpsig
|
|
||||||
from tests import testCache
|
|
||||||
from tests import testThreads
|
|
||||||
from webfinger import webfingerMeta
|
from webfinger import webfingerMeta
|
||||||
from webfinger import webfingerLookup
|
from webfinger import webfingerLookup
|
||||||
from person import personLookup
|
from person import personLookup
|
||||||
|
@ -205,12 +202,6 @@ def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None:
|
||||||
return
|
return
|
||||||
session = createSession(useTor)
|
session = createSession(useTor)
|
||||||
|
|
||||||
print('Running tests...')
|
|
||||||
testHttpsig()
|
|
||||||
testCache()
|
|
||||||
testThreads()
|
|
||||||
print('Tests succeeded\n')
|
|
||||||
|
|
||||||
serverAddress = ('', port)
|
serverAddress = ('', port)
|
||||||
httpd = HTTPServer(serverAddress, PubServer)
|
httpd = HTTPServer(serverAddress, PubServer)
|
||||||
httpd.domain=domain
|
httpd.domain=domain
|
||||||
|
|
|
@ -31,6 +31,10 @@ from follow import followPerson
|
||||||
from follow import followerOfPerson
|
from follow import followerOfPerson
|
||||||
from follow import unfollowPerson
|
from follow import unfollowPerson
|
||||||
from follow import unfollowerOfPerson
|
from follow import unfollowerOfPerson
|
||||||
|
from tests import testPostMessageBetweenServers
|
||||||
|
from tests import runAllTests
|
||||||
|
|
||||||
|
runAllTests()
|
||||||
|
|
||||||
federationList=['mastodon.social','wild.com','trees.com','127.0.0.1']
|
federationList=['mastodon.social','wild.com','trees.com','127.0.0.1']
|
||||||
username='testuser'
|
username='testuser'
|
||||||
|
@ -75,10 +79,11 @@ setBio(username,domain,'Some personal info')
|
||||||
#outboxJson=createOutbox(username,domain,port,https,2,True,None)
|
#outboxJson=createOutbox(username,domain,port,https,2,True,None)
|
||||||
#pprint(outboxJson)
|
#pprint(outboxJson)
|
||||||
|
|
||||||
runDaemon(domain,port,https,federationList,useTor)
|
testPostMessageBetweenServers()
|
||||||
|
#runDaemon(domain,port,https,federationList,useTor)
|
||||||
|
|
||||||
#testHttpsig()
|
#testHttpsig()
|
||||||
#sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
#pprint(person)
|
#pprint(person)
|
||||||
#print('\n')
|
#print('\n')
|
||||||
|
|
1
posts.py
1
posts.py
|
@ -264,6 +264,7 @@ def createPostBase(username: str, domain: str, toUrl: str, ccUrl: str, https: bo
|
||||||
postCC=''
|
postCC=''
|
||||||
newPostId=prefix+'://'+domain+'/users/'+username+'/statuses/'+statusNumber
|
newPostId=prefix+'://'+domain+'/users/'+username+'/statuses/'+statusNumber
|
||||||
sensitive=False
|
sensitive=False
|
||||||
|
summary=None
|
||||||
if subject:
|
if subject:
|
||||||
summary=subject
|
summary=subject
|
||||||
sensitive=True
|
sensitive=True
|
||||||
|
|
88
tests.py
88
tests.py
|
@ -8,6 +8,8 @@ __status__ = "Production"
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
from person import createPerson
|
from person import createPerson
|
||||||
from Crypto.Hash import SHA256
|
from Crypto.Hash import SHA256
|
||||||
from httpsig import signPostHeaders
|
from httpsig import signPostHeaders
|
||||||
|
@ -15,6 +17,13 @@ from httpsig import verifyPostHeaders
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from threads import threadWithTrace
|
from threads import threadWithTrace
|
||||||
|
from daemon import runDaemon
|
||||||
|
from session import createSession
|
||||||
|
from person import createPerson
|
||||||
|
from posts import deleteAllPosts
|
||||||
|
from posts import createPublicPost
|
||||||
|
from follow import followPerson
|
||||||
|
from follow import followerOfPerson
|
||||||
|
|
||||||
def testHttpsigBase(withDigest):
|
def testHttpsigBase(withDigest):
|
||||||
print('testHttpsig(' + str(withDigest) + ')')
|
print('testHttpsig(' + str(withDigest) + ')')
|
||||||
|
@ -72,3 +81,82 @@ def testThreads():
|
||||||
thr.kill()
|
thr.kill()
|
||||||
thr.join()
|
thr.join()
|
||||||
assert thr.isAlive()==False
|
assert thr.isAlive()==False
|
||||||
|
|
||||||
|
def createServerAlice(path: str,port: int):
|
||||||
|
print('Creating test server: Alice on port '+str(port))
|
||||||
|
if os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
os.mkdir(path)
|
||||||
|
os.chdir(path)
|
||||||
|
federationList=['127.0.0.1']
|
||||||
|
username='alice'
|
||||||
|
domain='127.0.0.1'
|
||||||
|
https=False
|
||||||
|
useTor=False
|
||||||
|
session = createSession(useTor)
|
||||||
|
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,port,https,True)
|
||||||
|
deleteAllPosts(username,domain)
|
||||||
|
followPerson(username,domain,'bob','127.0.0.1:61936',federationList)
|
||||||
|
followerOfPerson(username,domain,'bob','127.0.0.1:61936',federationList)
|
||||||
|
createPublicPost(username, domain, https, "No wise fish would go anywhere without a porpoise", False, True)
|
||||||
|
createPublicPost(username, domain, https, "Curiouser and curiouser!", False, True)
|
||||||
|
createPublicPost(username, domain, https, "In the gardens of memory, in the palace of dreams, that is where you and I shall meet", False, True)
|
||||||
|
print('Server running: Alice')
|
||||||
|
runDaemon(domain,port,https,federationList,useTor)
|
||||||
|
|
||||||
|
def createServerBob(path: str,port: int):
|
||||||
|
print('Creating test server: Bob on port '+str(port))
|
||||||
|
if os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
os.mkdir(path)
|
||||||
|
os.chdir(path)
|
||||||
|
federationList=['127.0.0.1']
|
||||||
|
username='alice'
|
||||||
|
domain='127.0.0.1'
|
||||||
|
https=False
|
||||||
|
useTor=False
|
||||||
|
session = createSession(useTor)
|
||||||
|
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,port,https,True)
|
||||||
|
deleteAllPosts(username,domain)
|
||||||
|
followPerson(username,domain,'alice','127.0.0.1:61935',federationList)
|
||||||
|
followerOfPerson(username,domain,'alice','127.0.0.1:61935',federationList)
|
||||||
|
createPublicPost(username, domain, https, "It's your life, live it your way.", False, True)
|
||||||
|
createPublicPost(username, domain, https, "One of the things I've realised is that I am very simple", False, True)
|
||||||
|
createPublicPost(username, domain, https, "Quantum physics is a bit of a passion of mine", False, True)
|
||||||
|
print('Server running: Bob')
|
||||||
|
runDaemon(domain,port,https,federationList,useTor)
|
||||||
|
|
||||||
|
def testPostMessageBetweenServers():
|
||||||
|
print('Testing sending message from one server to the inbox of another')
|
||||||
|
baseDir=os.getcwd()
|
||||||
|
if not os.path.isdir(baseDir+'/.tests'):
|
||||||
|
os.mkdir(baseDir+'/.tests')
|
||||||
|
|
||||||
|
# create the servers
|
||||||
|
thrAlice = threadWithTrace(target=createServerAlice,args=(baseDir+'/.tests/alice',61935),daemon=True)
|
||||||
|
thrAlice.start()
|
||||||
|
assert thrAlice.isAlive()==True
|
||||||
|
|
||||||
|
thrBob = threadWithTrace(target=createServerBob,args=(baseDir+'/.tests/bob',61936),daemon=True)
|
||||||
|
thrBob.start()
|
||||||
|
assert thrBob.isAlive()==True
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# stop the servers
|
||||||
|
thrAlice.kill()
|
||||||
|
thrAlice.join()
|
||||||
|
assert thrAlice.isAlive()==False
|
||||||
|
|
||||||
|
thrBob.kill()
|
||||||
|
thrBob.join()
|
||||||
|
assert thrBob.isAlive()==False
|
||||||
|
|
||||||
|
def runAllTests():
|
||||||
|
print('Running tests...')
|
||||||
|
testHttpsig()
|
||||||
|
testCache()
|
||||||
|
testThreads()
|
||||||
|
print('Tests succeeded\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue