forked from indymedia/epicyon
Run test in its own subdirectory
parent
60b14d751f
commit
d769c5b258
2
Makefile
2
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__
|
||||
|
|
33
content.py
33
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]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+replaceDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
|
||||
# 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]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
|
||||
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]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+replaceDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
|
||||
replaceFound=True
|
||||
break
|
||||
return replaceFound
|
||||
return True
|
||||
return False
|
||||
|
||||
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||
nickname: str,domain: str,content: str, \
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
18
tests.py
18
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)
|
||||
|
|
Loading…
Reference in New Issue