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