mirror of https://gitlab.com/bashrc2/epicyon
Check for capabilities storage
parent
a805a0052f
commit
994ce34a76
|
@ -140,7 +140,9 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
|||
# are capabilities attached? If so then store them
|
||||
if messageJson['object'].get('capabilities'):
|
||||
if isinstance(messageJson['object']['capabilities'], dict):
|
||||
capabilitiesGrantedSave(baseDir,messageJson['object']['capabilities'])
|
||||
capabilitiesGrantedSave(baseDir, \
|
||||
followedNickname,followedDomain, \
|
||||
messageJson['object']['capabilities'])
|
||||
|
||||
if followPerson(baseDir, \
|
||||
nickname,acceptedDomain, \
|
||||
|
|
|
@ -13,6 +13,9 @@ import json
|
|||
import commentjson
|
||||
from auth import createPassword
|
||||
|
||||
def getOcapFilename(baseDir :str,nickname: str,domain: str,actor :str,subdir: str) -> str:
|
||||
return baseDir+'/ocap/'+subdir+'/'+domain+':'+nickname+':'+actor.replace('/','#')+'.json'
|
||||
|
||||
def capabilitiesMakeDirs(baseDir: str):
|
||||
if not os.path.isdir(baseDir+'/ocap'):
|
||||
os.mkdir(baseDir+'/ocap')
|
||||
|
@ -39,7 +42,7 @@ def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
|||
"actor": requestedActor
|
||||
}
|
||||
return ocapRequest
|
||||
|
||||
|
||||
def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||
nickname: str,domain: str, port: int, \
|
||||
acceptedActor: str, saveToFile: bool, \
|
||||
|
@ -57,12 +60,12 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
|
||||
# make directories to store capabilities
|
||||
capabilitiesMakeDirs(baseDir)
|
||||
filename=baseDir+'/ocap/accept/'+acceptedActor.replace('/','#')+'.json'
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,acceptedActor,'accept')
|
||||
ocapAccept=None
|
||||
|
||||
# if the capability already exists then load it from file
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, 'r') as fp:
|
||||
if os.path.isfile(ocapFilename):
|
||||
with open(ocapFilename, 'r') as fp:
|
||||
ocapAccept=commentjson.load(fp)
|
||||
# otherwise create a new capability
|
||||
if not ocapAccept:
|
||||
|
@ -78,18 +81,18 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
||||
|
||||
if saveToFile:
|
||||
with open(filename, 'w') as fp:
|
||||
with open(ocapFilename, 'w') as fp:
|
||||
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
||||
return ocapAccept
|
||||
|
||||
def capabilitiesGrantedSave(baseDir :str,ocap: {}) -> bool:
|
||||
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
|
||||
"""A capabilities accept is received, so stor it for
|
||||
reference when sending to the actor
|
||||
"""
|
||||
if not ocap.get('actor'):
|
||||
return False
|
||||
filename=baseDir+'/ocap/granted/'+ocap['actor'].replace('/','#')+'.json'
|
||||
with open(filename, 'w') as fp:
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,ocap['actor'],'granted')
|
||||
with open(ocapFilename, 'w') as fp:
|
||||
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
||||
return True
|
||||
|
||||
|
|
11
inbox.py
11
inbox.py
|
@ -24,6 +24,7 @@ from pprint import pprint
|
|||
from cache import getPersonFromCache
|
||||
from cache import storePersonInCache
|
||||
from acceptreject import receiveAcceptReject
|
||||
from capabilities import getOcapFilename
|
||||
|
||||
def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
||||
if not personUrl:
|
||||
|
@ -126,6 +127,8 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
|
|||
sharedInboxItem=True
|
||||
|
||||
newQueueItem = {
|
||||
'nickname': nickname,
|
||||
'domain': domain,
|
||||
'sharedInbox': sharedInboxItem,
|
||||
'published': published,
|
||||
'host': host,
|
||||
|
@ -190,10 +193,14 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
|||
os.remove(queueFilename)
|
||||
queue.pop(0)
|
||||
continue
|
||||
ocapFilename=baseDir+'/ocap/accept/'+queueJson['post']['actor'].replace('/','#')+'.json'
|
||||
ocapFilename= \
|
||||
getOcapFilename(baseDir, \
|
||||
queueJson['nickname'],queueJson['domain'], \
|
||||
queueJson['post']['actor'],'accept')
|
||||
if not os.path.isfile(ocapFilename):
|
||||
if debug:
|
||||
print('DEBUG: capabilities for '+queueJson['post']['actor']+' do not exist')
|
||||
print('DEBUG: capabilities for '+ \
|
||||
queueJson['post']['actor']+' do not exist')
|
||||
os.remove(queueFilename)
|
||||
queue.pop(0)
|
||||
continue
|
||||
|
|
6
tests.py
6
tests.py
|
@ -313,7 +313,8 @@ def testFollowBetweenServers():
|
|||
for t in range(10):
|
||||
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
|
||||
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
|
||||
break
|
||||
if os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'):
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
# stop the servers
|
||||
|
@ -325,11 +326,12 @@ def testFollowBetweenServers():
|
|||
thrBob.join()
|
||||
assert thrBob.isAlive()==False
|
||||
|
||||
assert os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json')
|
||||
assert 'alice@'+aliceDomain in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
|
||||
assert 'bob@'+bobDomain in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(baseDir+'/.tests')
|
||||
#shutil.rmtree(baseDir+'/.tests')
|
||||
|
||||
def testFollowersOfPerson():
|
||||
print('testFollowersOfPerson')
|
||||
|
|
Loading…
Reference in New Issue