mirror of https://gitlab.com/bashrc2/epicyon
Unit test for shared item federation tokens
parent
3c8e4bb5fb
commit
ceaefc6ee9
16
shares.py
16
shares.py
|
@ -945,16 +945,18 @@ def sharesCatalogCSVEndpoint(baseDir: str, httpPrefix: str,
|
|||
|
||||
|
||||
def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [],
|
||||
baseDir: str) -> None:
|
||||
baseDir: str) -> {}:
|
||||
"""Generates tokens for shared item federated domains
|
||||
"""
|
||||
if not sharedItemsFederatedDomains:
|
||||
return
|
||||
|
||||
tokensFilename = baseDir + '/accounts/sharedItemsFederationTokens.json'
|
||||
tokensJson = {}
|
||||
if not os.path.isfile(tokensFilename):
|
||||
tokensJson = loadJson(tokensFilename)
|
||||
if baseDir:
|
||||
tokensFilename = \
|
||||
baseDir + '/accounts/sharedItemsFederationTokens.json'
|
||||
if not os.path.isfile(tokensFilename):
|
||||
tokensJson = loadJson(tokensFilename)
|
||||
|
||||
tokensAdded = False
|
||||
for domain in sharedItemsFederatedDomains:
|
||||
|
@ -963,8 +965,10 @@ def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [],
|
|||
tokensAdded = True
|
||||
|
||||
if not tokensAdded:
|
||||
return
|
||||
saveJson(tokensJson, tokensFilename)
|
||||
return tokensJson
|
||||
if baseDir:
|
||||
saveJson(tokensJson, tokensFilename)
|
||||
return tokensJson
|
||||
|
||||
|
||||
def authorizeSharedItems(sharedItemsFederatedDomains: [],
|
||||
|
|
24
tests.py
24
tests.py
|
@ -128,6 +128,8 @@ from languages import setActorLanguages
|
|||
from languages import getActorLanguages
|
||||
from languages import getLinksFromContent
|
||||
from languages import addLinksToContent
|
||||
from shares import authorizeSharedItems
|
||||
from shares import generateSharedItemFederationTokens
|
||||
|
||||
testServerAliceRunning = False
|
||||
testServerBobRunning = False
|
||||
|
@ -4268,9 +4270,31 @@ def _testValidPassword():
|
|||
assert validPassword('Abcdef!g123456')
|
||||
|
||||
|
||||
def _testAuthorizeSharedItems():
|
||||
print('testAuthorizeSharedItems')
|
||||
sharedItemsFederatedDomains = \
|
||||
['dog.domain', 'cat.domain', 'birb.domain']
|
||||
tokensJson = \
|
||||
generateSharedItemFederationTokens(sharedItemsFederatedDomains, None)
|
||||
assert tokensJson
|
||||
assert tokensJson.get('dog.domain')
|
||||
assert tokensJson.get('cat.domain')
|
||||
assert tokensJson.get('birb.domain')
|
||||
assert len(tokensJson['dog.domain']) >= 64
|
||||
assert len(tokensJson['cat.domain']) >= 64
|
||||
assert len(tokensJson['birb.domain']) >= 64
|
||||
assert not authorizeSharedItems(sharedItemsFederatedDomains, None,
|
||||
'dog.domain', 'w' * 86,
|
||||
False, tokensJson)
|
||||
assert authorizeSharedItems(sharedItemsFederatedDomains, None,
|
||||
'dog.domain', tokensJson['dog.domain'],
|
||||
False, tokensJson)
|
||||
|
||||
|
||||
def runAllTests():
|
||||
print('Running tests...')
|
||||
updateDefaultThemesList(os.getcwd())
|
||||
_testAuthorizeSharedItems()
|
||||
_testValidPassword()
|
||||
_testGetLinksFromContent()
|
||||
_testSetActorLanguages()
|
||||
|
|
Loading…
Reference in New Issue