diff --git a/daemon.py b/daemon.py index 41e764fd..33d2d23e 100644 --- a/daemon.py +++ b/daemon.py @@ -155,6 +155,7 @@ class PubServer(BaseHTTPRequestHandler): self._set_headers('application/json') def do_POST(self): + print('**************** POST recieved!') try: if self.POSTbusy: self.send_response(429) @@ -162,35 +163,53 @@ class PubServer(BaseHTTPRequestHandler): return except: pass + print('**************** POST ready to receive') self.POSTbusy=True - ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) + if not self.headers.get('Content-type'): + print('**************** No Content-type') + self.send_response(400) + self.end_headers() + self.POSTbusy=False + return + print('*****************headers: '+str(self.headers)) # refuse to receive non-json content - if ctype != 'application/json': + if self.headers['Content-type'] != 'application/json': + print("**************** That's no Json!") self.send_response(400) self.end_headers() self.POSTbusy=False return # read the message and convert it into a python dictionary - length = int(self.headers.getheader('content-length')) + length = int(self.headers['Content-length']) + print('**************** content-length: '+str(length)) if length>maxMessageLength: self.send_response(400) self.end_headers() self.POSTbusy=False return - message = json.loads(self.rfile.read(length)) + print('**************** Reading message') + messageBytes=self.rfile.read(length) + messageJson = json.loads(messageBytes) - if not inboxPermittedMessage(message,self.server.federationList): + if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList): + print('**************** Ah Ah Ah') self.send_response(403) self.end_headers() - else: - # add a property to the object, just to mess with data - message['received'] = 'ok' + self.POSTbusy=False + return - # send the message back - self._set_headers('application/json') - self.wfile.write(json.dumps(message).encode('utf-8')) + print('**************** POST valid') + pprint(messageJson) + # add a property to the object, just to mess with data + #message['received'] = 'ok' + + # send the message back + #self._set_headers('application/json') + #self.wfile.write(json.dumps(message).encode('utf-8')) + self.send_response(200) + self.end_headers() self.POSTbusy=False def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None: diff --git a/inbox.py b/inbox.py index 3ecb3bb0..1b6352e2 100644 --- a/inbox.py +++ b/inbox.py @@ -10,7 +10,7 @@ import json import os import datetime -def inboxPermittedMessage(messageJson: {},federationList: []) -> bool: +def inboxPermittedMessage(domain: str,messageJson: {},federationList: []) -> bool: """ check that we are receiving from a permitted domain """ testParam='actor' @@ -18,7 +18,7 @@ def inboxPermittedMessage(messageJson: {},federationList: []) -> bool: return False actor=messageJson[testParam] # always allow the local domain - if thisDomain in actor: + if domain in actor: return True permittedDomain=False diff --git a/posts.py b/posts.py index f21e310e..6b607844 100644 --- a/posts.py +++ b/posts.py @@ -16,6 +16,7 @@ import shutil import threading import sys import trace +import time from threads import threadWithTrace from cache import storePersonInCache from cache import getPersonFromCache diff --git a/tests.py b/tests.py index c11c86ce..921f5bf8 100644 --- a/tests.py +++ b/tests.py @@ -176,7 +176,7 @@ def testPostMessageBetweenServers(): while not (testServerAliceRunning and testServerBobRunning): time.sleep(1) - time.sleep(3) + time.sleep(5) print('Alice sends to Bob') os.chdir(aliceDir)