forked from indymedia/epicyon
Extra test for content length
parent
a688f2aeab
commit
80a0560fed
|
@ -50,7 +50,8 @@ def signPostHeaders(dateStr: str,privateKeyPem: str, \
|
||||||
headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'content-type': 'application/json'}
|
headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'content-type': 'application/json'}
|
||||||
else:
|
else:
|
||||||
bodyDigest=messageContentDigest(messageBodyJsonStr)
|
bodyDigest=messageContentDigest(messageBodyJsonStr)
|
||||||
headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': 'application/activity+json'}
|
contentLength=len(messageBodyJsonStr)
|
||||||
|
headers={'(request-target)': f'post {path}','host': toDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': 'application/activity+json','content-length': str(contentLength)}
|
||||||
privateKeyPem=RSA.import_key(privateKeyPem)
|
privateKeyPem=RSA.import_key(privateKeyPem)
|
||||||
#headers.update({
|
#headers.update({
|
||||||
# '(request-target)': f'post {path}',
|
# '(request-target)': f'post {path}',
|
||||||
|
|
13
tests.py
13
tests.py
|
@ -114,7 +114,8 @@ def testHttpsigBase(withDigest):
|
||||||
boxpath, httpPrefix, None)
|
boxpath, httpPrefix, None)
|
||||||
else:
|
else:
|
||||||
bodyDigest = messageContentDigest(messageBodyJsonStr)
|
bodyDigest = messageContentDigest(messageBodyJsonStr)
|
||||||
headers = {'host': headersDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType}
|
contentLength=len(messageBodyJsonStr)
|
||||||
|
headers = {'host': headersDomain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType,'content-length': str(contentLength)}
|
||||||
signatureHeader = \
|
signatureHeader = \
|
||||||
signPostHeaders(dateStr,privateKeyPem, nickname, \
|
signPostHeaders(dateStr,privateKeyPem, nickname, \
|
||||||
domain, port, \
|
domain, port, \
|
||||||
|
@ -125,6 +126,12 @@ def testHttpsigBase(withDigest):
|
||||||
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
||||||
boxpath,False,None, \
|
boxpath,False,None, \
|
||||||
messageBodyJsonStr,False)
|
messageBodyJsonStr,False)
|
||||||
|
if withDigest:
|
||||||
|
# everything correct except for content-length
|
||||||
|
headers['content-length']=str(contentLength+2)
|
||||||
|
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
||||||
|
boxpath,False,None, \
|
||||||
|
messageBodyJsonStr,False) == False
|
||||||
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
||||||
'/parambulator'+boxpath,False,None, \
|
'/parambulator'+boxpath,False,None, \
|
||||||
messageBodyJsonStr,False) == False
|
messageBodyJsonStr,False) == False
|
||||||
|
@ -137,12 +144,14 @@ def testHttpsigBase(withDigest):
|
||||||
else:
|
else:
|
||||||
# correct domain but fake message
|
# correct domain but fake message
|
||||||
messageBodyJsonStr = '{"a key": "a value", "another key": "Fake GNUs", "yet another key": "More Fake GNUs"}'
|
messageBodyJsonStr = '{"a key": "a value", "another key": "Fake GNUs", "yet another key": "More Fake GNUs"}'
|
||||||
|
contentLength=len(messageBodyJsonStr)
|
||||||
bodyDigest = messageContentDigest(messageBodyJsonStr)
|
bodyDigest = messageContentDigest(messageBodyJsonStr)
|
||||||
headers = {'host': domain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType}
|
headers = {'host': domain,'date': dateStr,'digest': f'SHA-256={bodyDigest}','content-type': contentType,'content-length': str(contentLength)}
|
||||||
headers['signature'] = signatureHeader
|
headers['signature'] = signatureHeader
|
||||||
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
assert verifyPostHeaders(httpPrefix,publicKeyPem,headers, \
|
||||||
boxpath,True,None, \
|
boxpath,True,None, \
|
||||||
messageBodyJsonStr,False) == False
|
messageBodyJsonStr,False) == False
|
||||||
|
|
||||||
os.chdir(baseDir)
|
os.chdir(baseDir)
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue