diff --git a/Makefile b/Makefile index edb11c27..a06078ed 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: debug: clean: - rm -f *.md~ *.py~ *.json~ *.css~ Makefile~ + rm -f *.txt~ *.md~ *.py~ *.json~ *.css~ Makefile~ rm -rf __pycache__ diff --git a/content.py b/content.py index d7ade1fe..647f8181 100644 --- a/content.py +++ b/content.py @@ -17,9 +17,20 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r if len(wordStr)<2: return False possibleHandle=wordStr[1:] - if '@' not in possibleHandle: - return False - replaceFound=False + #if '@' not in possibleHandle: + # # fall back to a best effort match against the following list + # # if no domain was specified. eg. @nick + # possibleNickname=possibleHandle + # for follow in following: + # if follow.startswith(possibleNickname+'@'): + # replaceDomain=follow.replace('\n','').split('@')[1] + # recipientActor=httpPrefix+"://"+replaceDomain+"/users/"+possibleNickname + # if recipientActor not in recipients: + # recipients.append(recipientActor) + # replaceMentions[wordStr]="@"+possibleNickname+"" + # replaceFound=True + # return True + # return False possibleNickname=possibleHandle.split('@')[0] possibleDomain=possibleHandle.split('@')[1] for follow in following: @@ -28,20 +39,8 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r if recipientActor not in recipients: recipients.append(recipientActor) replaceMentions[wordStr]="@"+possibleNickname+"" - replaceFound=True - break - if not replaceFound: - # fall back to a best effort match if an exact one is not found - for follow in following: - if follow.startswith(possibleNickname+'@'): - replaceDomain=follow.replace('\n','').split('@')[1] - recipientActor=httpPrefix+"://"+replaceDomain+"/users/"+possibleNickname - if recipientActor not in recipients: - recipients.append(recipientActor) - replaceMentions[wordStr]="@"+possibleNickname+"" - replaceFound=True - break - return replaceFound + return True + return False def addHtmlTags(baseDir: str,httpPrefix: str, \ nickname: str,domain: str,content: str, \ diff --git a/httpsig.py b/httpsig.py index ab0d7537..6e229816 100644 --- a/httpsig.py +++ b/httpsig.py @@ -30,7 +30,7 @@ def signPostHeaders(privateKeyPem: str, nickname: str, domain: str, \ else: bodyDigest = \ base64.b64encode(SHA256.new(messageBodyJson.encode()).digest()) - headers = {'host': domain, 'digest': f'SHA-256={bodyDigest}'} + headers = {'host': domain, 'digest': f'SHA-256={bodyDigest}'} privateKeyPem = RSA.import_key(privateKeyPem) headers.update({ '(request-target)': f'post {path}', diff --git a/person.py b/person.py index 13d2564a..d65d412e 100644 --- a/person.py +++ b/person.py @@ -258,6 +258,8 @@ def createPerson(baseDir: str,nickname: str,domain: str,port: int, \ setRole(baseDir,nickname,domain,'instance','moderator') setRole(baseDir,nickname,domain,'instance','delegator') + if not os.path.isdir(baseDir+'/accounts'): + os.mkdir(baseDir+'/accounts') if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain): os.mkdir(baseDir+'/accounts/'+nickname+'@'+domain) diff --git a/tests.py b/tests.py index 6591c6d4..9a614b32 100644 --- a/tests.py +++ b/tests.py @@ -65,14 +65,22 @@ testServerEveRunning = False def testHttpsigBase(withDigest): print('testHttpsig(' + str(withDigest) + ')') + + baseDir=os.getcwd() + path=baseDir+'/.testHttpsigBase' + if os.path.isdir(path): + shutil.rmtree(path) + os.mkdir(path) + os.chdir(path) + nickname='socrates' domain='argumentative.social' httpPrefix='https' port=5576 - baseDir=os.getcwd() password='SuperSecretPassword' privateKeyPem,publicKeyPem,person,wfEndpoint= \ - createPerson(baseDir,nickname,domain,port,httpPrefix,False,password) + createPerson(path,nickname,domain,port,httpPrefix,False,password) + assert privateKeyPem messageBodyJsonStr = '{"a key": "a value", "another key": "A string"}' headersDomain=domain @@ -86,9 +94,9 @@ def testHttpsigBase(withDigest): base64.b64encode(SHA256.new(messageBodyJsonStr.encode()).digest()) headers = {'host': headersDomain, 'digest': f'SHA-256={bodyDigest}'} - path='/inbox' + boxpath='/inbox' signatureHeader = \ - signPostHeaders(privateKeyPem, nickname, domain, port, path, httpPrefix, None) + signPostHeaders(privateKeyPem, nickname, domain, port, boxpath, httpPrefix, None) headers['signature'] = signatureHeader assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \ '/inbox' ,False, messageBodyJsonStr) @@ -107,6 +115,8 @@ def testHttpsigBase(withDigest): headers['signature'] = signatureHeader assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \ '/inbox', True, messageBodyJsonStr) == False + os.chdir(baseDir) + shutil.rmtree(path) def testHttpsig(): testHttpsigBase(False)