forked from indymedia/epicyon
Run test in its own subdirectory
parent
60b14d751f
commit
d769c5b258
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
all:
|
all:
|
||||||
debug:
|
debug:
|
||||||
clean:
|
clean:
|
||||||
rm -f *.md~ *.py~ *.json~ *.css~ Makefile~
|
rm -f *.txt~ *.md~ *.py~ *.json~ *.css~ Makefile~
|
||||||
rm -rf __pycache__
|
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:
|
if len(wordStr)<2:
|
||||||
return False
|
return False
|
||||||
possibleHandle=wordStr[1:]
|
possibleHandle=wordStr[1:]
|
||||||
if '@' not in possibleHandle:
|
#if '@' not in possibleHandle:
|
||||||
return False
|
# # fall back to a best effort match against the following list
|
||||||
replaceFound=False
|
# # 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]
|
possibleNickname=possibleHandle.split('@')[0]
|
||||||
possibleDomain=possibleHandle.split('@')[1]
|
possibleDomain=possibleHandle.split('@')[1]
|
||||||
for follow in following:
|
for follow in following:
|
||||||
|
@ -28,20 +39,8 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
|
||||||
if recipientActor not in recipients:
|
if recipientActor not in recipients:
|
||||||
recipients.append(recipientActor)
|
recipients.append(recipientActor)
|
||||||
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
|
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
|
||||||
replaceFound=True
|
return True
|
||||||
break
|
return False
|
||||||
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
|
|
||||||
|
|
||||||
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
nickname: str,domain: str,content: str, \
|
nickname: str,domain: str,content: str, \
|
||||||
|
|
|
@ -30,7 +30,7 @@ def signPostHeaders(privateKeyPem: str, nickname: str, domain: str, \
|
||||||
else:
|
else:
|
||||||
bodyDigest = \
|
bodyDigest = \
|
||||||
base64.b64encode(SHA256.new(messageBodyJson.encode()).digest())
|
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)
|
privateKeyPem = RSA.import_key(privateKeyPem)
|
||||||
headers.update({
|
headers.update({
|
||||||
'(request-target)': f'post {path}',
|
'(request-target)': f'post {path}',
|
||||||
|
|
|
@ -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','moderator')
|
||||||
setRole(baseDir,nickname,domain,'instance','delegator')
|
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):
|
if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
|
||||||
os.mkdir(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):
|
def testHttpsigBase(withDigest):
|
||||||
print('testHttpsig(' + str(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'
|
nickname='socrates'
|
||||||
domain='argumentative.social'
|
domain='argumentative.social'
|
||||||
httpPrefix='https'
|
httpPrefix='https'
|
||||||
port=5576
|
port=5576
|
||||||
baseDir=os.getcwd()
|
|
||||||
password='SuperSecretPassword'
|
password='SuperSecretPassword'
|
||||||
privateKeyPem,publicKeyPem,person,wfEndpoint= \
|
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"}'
|
messageBodyJsonStr = '{"a key": "a value", "another key": "A string"}'
|
||||||
|
|
||||||
headersDomain=domain
|
headersDomain=domain
|
||||||
|
@ -86,9 +94,9 @@ def testHttpsigBase(withDigest):
|
||||||
base64.b64encode(SHA256.new(messageBodyJsonStr.encode()).digest())
|
base64.b64encode(SHA256.new(messageBodyJsonStr.encode()).digest())
|
||||||
headers = {'host': headersDomain, 'digest': f'SHA-256={bodyDigest}'}
|
headers = {'host': headersDomain, 'digest': f'SHA-256={bodyDigest}'}
|
||||||
|
|
||||||
path='/inbox'
|
boxpath='/inbox'
|
||||||
signatureHeader = \
|
signatureHeader = \
|
||||||
signPostHeaders(privateKeyPem, nickname, domain, port, path, httpPrefix, None)
|
signPostHeaders(privateKeyPem, nickname, domain, port, boxpath, httpPrefix, None)
|
||||||
headers['signature'] = signatureHeader
|
headers['signature'] = signatureHeader
|
||||||
assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \
|
assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \
|
||||||
'/inbox' ,False, messageBodyJsonStr)
|
'/inbox' ,False, messageBodyJsonStr)
|
||||||
|
@ -107,6 +115,8 @@ def testHttpsigBase(withDigest):
|
||||||
headers['signature'] = signatureHeader
|
headers['signature'] = signatureHeader
|
||||||
assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \
|
assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, \
|
||||||
'/inbox', True, messageBodyJsonStr) == False
|
'/inbox', True, messageBodyJsonStr) == False
|
||||||
|
os.chdir(baseDir)
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def testHttpsig():
|
def testHttpsig():
|
||||||
testHttpsigBase(False)
|
testHttpsigBase(False)
|
||||||
|
|
Loading…
Reference in New Issue