Fix network test

master
Bob Mottram 2019-07-04 21:25:19 +01:00
parent 3a8801e544
commit 8d02e8fdc2
3 changed files with 17 additions and 8 deletions

View File

@ -223,8 +223,10 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False self.server.GETbusy=False
return return
# look up a person # look up a person
print('************personLookup start '+self.server.domain+' '+self.path+' '+self.server.baseDir)
getPerson = personLookup(self.server.domain,self.path, \ getPerson = personLookup(self.server.domain,self.path, \
self.server.baseDir) self.server.baseDir)
print('************personLookup end '+str(getPerson))
if getPerson: if getPerson:
self._set_headers('application/json') self._set_headers('application/json')
self.wfile.write(json.dumps(getPerson).encode('utf-8')) self.wfile.write(json.dumps(getPerson).encode('utf-8'))
@ -391,6 +393,7 @@ class PubServer(BaseHTTPRequestHandler):
self.postToNickname, \ self.postToNickname, \
self.server.domain, \ self.server.domain, \
messageJson, messageJson,
self.headers['host'],
self.headers['signature']) self.headers['signature'])
if cacheFilename: if cacheFilename:
if cacheFilename not in self.server.inboxQueue: if cacheFilename not in self.server.inboxQueue:
@ -425,7 +428,7 @@ def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https',fedList=[],use
httpd.httpPrefix=httpPrefix httpd.httpPrefix=httpPrefix
httpd.debug=debug httpd.debug=debug
httpd.federationList=fedList.copy() httpd.federationList=fedList.copy()
httpd.baseDir=os.getcwd() httpd.baseDir=baseDir
httpd.personCache={} httpd.personCache={}
httpd.cachedWebfingers={} httpd.cachedWebfingers={}
httpd.useTor=useTor httpd.useTor=useTor

View File

@ -20,9 +20,9 @@ from session import getJson
from follow import receiveFollowRequest from follow import receiveFollowRequest
from pprint import pprint from pprint import pprint
from cache import getPersonFromCache from cache import getPersonFromCache
from cache import storePersonInCache
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str: def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
if not personUrl: if not personUrl:
return None return None
personUrl=personUrl.replace('#main-key','') personUrl=personUrl.replace('#main-key','')
@ -30,6 +30,7 @@ def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
if not personJson: if not personJson:
if debug: if debug:
print('DEBUG: Obtaining public key for '+personUrl) print('DEBUG: Obtaining public key for '+personUrl)
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personJson = getJson(session,personUrl,asHeader,None) personJson = getJson(session,personUrl,asHeader,None)
if not personJson: if not personJson:
return None return None
@ -87,7 +88,7 @@ def validPublishedDate(published) -> bool:
return False return False
return True return True
def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJson: {},headers: str) -> str: def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJson: {},host: str,headers: str) -> str:
"""Saves the give json to the inbox queue for the person """Saves the give json to the inbox queue for the person
keyId specifies the actor sending the post keyId specifies the actor sending the post
""" """
@ -111,6 +112,7 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
newQueueItem = { newQueueItem = {
'published': published, 'published': published,
'host': host,
'headers': headers, 'headers': headers,
'post': postJson, 'post': postJson,
'filename': filename, 'filename': filename,
@ -185,10 +187,14 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
continue continue
# check the signature # check the signature
verifyHeaders={
'host': queueJson['host'],
'signature': queueJson['headers']
}
if not verifyPostHeaders(httpPrefix, \ if not verifyPostHeaders(httpPrefix, \
pubKey, queueJson.headers, \ pubKey, verifyHeaders, \
'/inbox', False, \ '/inbox', False, \
json.dumps(messageJson)): json.dumps(queueJson['post'])):
if debug: if debug:
print('DEBUG: Header signature check failed') print('DEBUG: Header signature check failed')
os.remove(queueFilename) os.remove(queueFilename)
@ -199,7 +205,7 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
print('DEBUG: Signature check success') print('DEBUG: Signature check success')
if receiveFollowRequest(baseDir, \ if receiveFollowRequest(baseDir, \
queueJson.post, \ queueJson['post'], \
federationList): federationList):
if debug: if debug:

View File

@ -189,7 +189,7 @@ def testPostMessageBetweenServers():
while not (testServerAliceRunning and testServerBobRunning): while not (testServerAliceRunning and testServerBobRunning):
time.sleep(1) time.sleep(1)
time.sleep(8) time.sleep(1)
print('Alice sends to Bob') print('Alice sends to Bob')
os.chdir(aliceDir) os.chdir(aliceDir)
@ -208,7 +208,7 @@ def testPostMessageBetweenServers():
sendResult = sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, 'bob', bobDomain, bobPort, ccUrl, httpPrefix, 'Why is a mouse when it spins?', followersOnly, saveToFile, clientToServer, federationList, aliceSendThreads, alicePostLog, aliceCachedWebfingers,alicePersonCache,inReplyTo, inReplyToAtomUri, subject) sendResult = sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, 'bob', bobDomain, bobPort, ccUrl, httpPrefix, 'Why is a mouse when it spins?', followersOnly, saveToFile, clientToServer, federationList, aliceSendThreads, alicePostLog, aliceCachedWebfingers,alicePersonCache,inReplyTo, inReplyToAtomUri, subject)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))
for i in range(60): for i in range(5):
time.sleep(1) time.sleep(1)
# stop the servers # stop the servers