forked from indymedia/epicyon
Set up two test servers
parent
8705b9e44c
commit
906e3de1de
|
@ -12,9 +12,6 @@ import json
|
|||
import cgi
|
||||
from pprint import pprint
|
||||
from session import createSession
|
||||
from tests import testHttpsig
|
||||
from tests import testCache
|
||||
from tests import testThreads
|
||||
from webfinger import webfingerMeta
|
||||
from webfinger import webfingerLookup
|
||||
from person import personLookup
|
||||
|
@ -205,12 +202,6 @@ def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None:
|
|||
return
|
||||
session = createSession(useTor)
|
||||
|
||||
print('Running tests...')
|
||||
testHttpsig()
|
||||
testCache()
|
||||
testThreads()
|
||||
print('Tests succeeded\n')
|
||||
|
||||
serverAddress = ('', port)
|
||||
httpd = HTTPServer(serverAddress, PubServer)
|
||||
httpd.domain=domain
|
||||
|
|
|
@ -31,6 +31,10 @@ from follow import followPerson
|
|||
from follow import followerOfPerson
|
||||
from follow import unfollowPerson
|
||||
from follow import unfollowerOfPerson
|
||||
from tests import testPostMessageBetweenServers
|
||||
from tests import runAllTests
|
||||
|
||||
runAllTests()
|
||||
|
||||
federationList=['mastodon.social','wild.com','trees.com','127.0.0.1']
|
||||
username='testuser'
|
||||
|
@ -75,10 +79,11 @@ setBio(username,domain,'Some personal info')
|
|||
#outboxJson=createOutbox(username,domain,port,https,2,True,None)
|
||||
#pprint(outboxJson)
|
||||
|
||||
runDaemon(domain,port,https,federationList,useTor)
|
||||
testPostMessageBetweenServers()
|
||||
#runDaemon(domain,port,https,federationList,useTor)
|
||||
|
||||
#testHttpsig()
|
||||
#sys.exit()
|
||||
sys.exit()
|
||||
|
||||
#pprint(person)
|
||||
#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=''
|
||||
newPostId=prefix+'://'+domain+'/users/'+username+'/statuses/'+statusNumber
|
||||
sensitive=False
|
||||
summary=None
|
||||
if subject:
|
||||
summary=subject
|
||||
sensitive=True
|
||||
|
|
88
tests.py
88
tests.py
|
@ -8,6 +8,8 @@ __status__ = "Production"
|
|||
|
||||
import base64
|
||||
import time
|
||||
import os
|
||||
import shutil
|
||||
from person import createPerson
|
||||
from Crypto.Hash import SHA256
|
||||
from httpsig import signPostHeaders
|
||||
|
@ -15,6 +17,13 @@ from httpsig import verifyPostHeaders
|
|||
from cache import storePersonInCache
|
||||
from cache import getPersonFromCache
|
||||
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):
|
||||
print('testHttpsig(' + str(withDigest) + ')')
|
||||
|
@ -72,3 +81,82 @@ def testThreads():
|
|||
thr.kill()
|
||||
thr.join()
|
||||
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