mirror of https://gitlab.com/bashrc2/epicyon
Test for accessing catalog of local instance
parent
9c435b9f7e
commit
ccc0d09ece
41
daemon.py
41
daemon.py
|
@ -215,6 +215,7 @@ from shares import addShare
|
|||
from shares import removeSharedItem
|
||||
from shares import expireShares
|
||||
from shares import sharesCatalogEndpoint
|
||||
from shares import sharesCatalogAccountEndpoint
|
||||
from shares import sharesCatalogCSVEndpoint
|
||||
from categories import setHashtagCategory
|
||||
from languages import getActorLanguages
|
||||
|
@ -10815,6 +10816,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
(self.path.startswith('/users/') and '/catalog' in self.path):
|
||||
catalogAuthorized = authorized
|
||||
if not catalogAuthorized:
|
||||
if self.server.debug:
|
||||
print('Catalog access is not authorized. Checking' +
|
||||
'Authorization header')
|
||||
# basic auth access to shared items catalog
|
||||
if self.headers.get('Authorization'):
|
||||
permittedDomains = \
|
||||
|
@ -10827,6 +10831,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.debug,
|
||||
sharedItemTokens):
|
||||
catalogAuthorized = True
|
||||
elif self.server.debug:
|
||||
print('Authorization token refused for ' +
|
||||
'shared items federation')
|
||||
elif self.server.debug:
|
||||
print('No authorization header is available for ' +
|
||||
'shared items federation')
|
||||
# show shared items catalog for federation
|
||||
if self._hasAccept(callingDomain) and catalogAuthorized:
|
||||
catalogType = 'json'
|
||||
|
@ -10834,14 +10844,35 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
catalogType = 'csv'
|
||||
elif self.path.endswith('.json') or not self._requestHTTP():
|
||||
catalogType = 'json'
|
||||
if self.server.debug:
|
||||
print('Preparing DFC catalog in format ' + catalogType)
|
||||
|
||||
if catalogType == 'json':
|
||||
# catalog as a json
|
||||
catalogJson = \
|
||||
sharesCatalogEndpoint(self.server.baseDir,
|
||||
self.server.httpPrefix,
|
||||
self.server.domainFull,
|
||||
self.path)
|
||||
if not self.path.startswith('/users/'):
|
||||
if self.server.debug:
|
||||
print('Catalog for the instance')
|
||||
catalogJson = \
|
||||
sharesCatalogEndpoint(self.server.baseDir,
|
||||
self.server.httpPrefix,
|
||||
self.server.domainFull,
|
||||
self.path)
|
||||
else:
|
||||
domainFull = self.server.domainFull
|
||||
httpPrefix = self.server.httpPrefix
|
||||
nickname = self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname = nickname.split('/')[0]
|
||||
if self.server.debug:
|
||||
print('Catalog for account: ' + nickname)
|
||||
catalogJson = \
|
||||
sharesCatalogAccountEndpoint(self.server.baseDir,
|
||||
httpPrefix,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
domainFull,
|
||||
self.path,
|
||||
self.server.debug)
|
||||
msg = json.dumps(catalogJson,
|
||||
ensure_ascii=False).encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
|
8
posts.py
8
posts.py
|
@ -2689,10 +2689,10 @@ def _hasSharedInbox(session, httpPrefix: str, domain: str,
|
|||
"""Returns true if the given domain has a shared inbox
|
||||
This tries the new and the old way of webfingering the shared inbox
|
||||
"""
|
||||
tryHandles = [
|
||||
domain + '@' + domain,
|
||||
'inbox@' + domain
|
||||
]
|
||||
tryHandles = []
|
||||
if ':' not in domain:
|
||||
tryHandles.append(domain + '@' + domain)
|
||||
tryHandles.append('inbox@' + domain)
|
||||
for handle in tryHandles:
|
||||
wfRequest = webfingerHandle(session, handle, httpPrefix, {},
|
||||
None, __version__, debug, False)
|
||||
|
|
13
shares.py
13
shares.py
|
@ -68,8 +68,7 @@ def _loadDfcIds(baseDir: str, systemLanguage: str,
|
|||
for label in productTypes['@graph'][0]['rdfs:label']:
|
||||
if not label.get('@language'):
|
||||
continue
|
||||
if productTypes['@graph'][0]['rdfs:label']['@language'] == \
|
||||
systemLanguage:
|
||||
if label['@language'] == systemLanguage:
|
||||
languageExists = True
|
||||
break
|
||||
if not languageExists:
|
||||
|
@ -783,6 +782,7 @@ def outboxShareUpload(baseDir: str, httpPrefix: str,
|
|||
if debug:
|
||||
print('Adding shared item')
|
||||
pprint(messageJson)
|
||||
|
||||
addShare(baseDir,
|
||||
httpPrefix, nickname, domain, port,
|
||||
messageJson['object']['displayName'],
|
||||
|
@ -866,7 +866,7 @@ def _sharesCatalogParams(path: str) -> (bool, float, float, str):
|
|||
def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str,
|
||||
nickname: str, domain: str,
|
||||
domainFull: str,
|
||||
path: str) -> {}:
|
||||
path: str, debug: bool) -> {}:
|
||||
"""Returns the endpoint for the shares catalog of a particular account
|
||||
See https://github.com/datafoodconsortium/ontology
|
||||
"""
|
||||
|
@ -893,13 +893,19 @@ def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str,
|
|||
|
||||
sharesFilename = acctDir(baseDir, nickname, domain) + '/shares.json'
|
||||
if not os.path.isfile(sharesFilename):
|
||||
if debug:
|
||||
print('shares.json file not found: ' + sharesFilename)
|
||||
return endpoint
|
||||
sharesJson = loadJson(sharesFilename, 1, 2)
|
||||
if not sharesJson:
|
||||
if debug:
|
||||
print('Unable to load json for ' + sharesFilename)
|
||||
return endpoint
|
||||
|
||||
for itemID, item in sharesJson.items():
|
||||
if not item.get('dfcId'):
|
||||
if debug:
|
||||
print('Item does not have dfcId: ' + itemID)
|
||||
continue
|
||||
if '#' not in item['dfcId']:
|
||||
continue
|
||||
|
@ -980,6 +986,7 @@ def sharesCatalogEndpoint(baseDir: str, httpPrefix: str,
|
|||
acctDir(baseDir, nickname, domain) + '/shares.json'
|
||||
if not os.path.isfile(sharesFilename):
|
||||
continue
|
||||
print('Test 78363 ' + sharesFilename)
|
||||
sharesJson = loadJson(sharesFilename, 1, 2)
|
||||
if not sharesJson:
|
||||
continue
|
||||
|
|
16
tests.py
16
tests.py
|
@ -1464,7 +1464,16 @@ def testSharedItemsFederation():
|
|||
|
||||
print('\n\n*********************************************************')
|
||||
print('Bob publishes some shared items')
|
||||
if os.path.isdir(bobDir + '/ontology'):
|
||||
shutil.rmtree(bobDir + '/ontology')
|
||||
os.mkdir(bobDir + '/ontology')
|
||||
copyfile(baseDir + '/img/logo.png', bobDir + '/logo.png')
|
||||
copyfile(baseDir + '/ontology/foodTypes.json',
|
||||
bobDir + '/ontology/foodTypes.json')
|
||||
copyfile(baseDir + '/ontology/toolTypes.json',
|
||||
bobDir + '/ontology/toolTypes.json')
|
||||
copyfile(baseDir + '/ontology/clothesTypes.json',
|
||||
bobDir + '/ontology/clothesTypes.json')
|
||||
sessionBob = createSession(proxyType)
|
||||
sharedItemName = 'cheddar'
|
||||
sharedItemDescription = 'Some cheese'
|
||||
|
@ -1546,6 +1555,10 @@ def testSharedItemsFederation():
|
|||
assert sharesJson
|
||||
pprint(sharesJson)
|
||||
assert len(sharesJson.items()) == 3
|
||||
for itemID, item in sharesJson.items():
|
||||
if not item.get('dfcId'):
|
||||
print(itemID + ' does not have dfcId field')
|
||||
assert item.get('dfcId')
|
||||
|
||||
print('\n\n*********************************************************')
|
||||
print('Bob can read the shared items catalog on his own instance')
|
||||
|
@ -4029,8 +4042,7 @@ def _testFunctions():
|
|||
'E2EEremoveDevice',
|
||||
'setOrganizationScheme',
|
||||
'fill_headers',
|
||||
'_nothing',
|
||||
'sharesCatalogAccountEndpoint'
|
||||
'_nothing'
|
||||
]
|
||||
excludeImports = [
|
||||
'link',
|
||||
|
|
Loading…
Reference in New Issue