Allow deletes in tests

master
Bob Mottram 2019-07-17 20:31:52 +01:00
parent ab62e04721
commit 5ff4c121ce
3 changed files with 59 additions and 2 deletions

View File

@ -36,6 +36,7 @@ from threads import threadWithTrace
from media import getMediaPath
from media import createMediaDirs
from delete import outboxDelete
from like import outboxLike
import os
import sys
@ -206,6 +207,11 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug:
print('DEBUG: handle any unfollow requests')
outboxUndoFollow(self.server.baseDir,messageJson,self.server.debug)
if self.server.debug:
print('DEBUG: handle any like requests')
outboxLike(self.server.baseDir,self.server.httpPrefix, \
self.postToNickname,self.server.domain,self.server.port, \
messageJson,self.server.debug)
if self.server.debug:
print('DEBUG: handle delete requests')
outboxDelete(self.server.baseDir,self.server.httpPrefix, \
@ -847,7 +853,7 @@ def runDaemon(clientToServer: bool,baseDir: str,domain: str, \
httpd.ocapAlways=ocapAlways
httpd.maxMessageLength=5000
httpd.maxImageSize=10*1024*1024
httpd.allowDeletion=nodeletion
httpd.allowDeletion=allowDeletion
httpd.acceptedCaps=["inbox:write","objects:read"]
if noreply:
httpd.acceptedCaps.append('inbox:noreply')

51
like.py
View File

@ -14,6 +14,10 @@ from utils import getNicknameFromActor
from utils import getDomainFromActor
from utils import locatePost
from posts import sendSignedJson
from session import postJson
from webfinger import webfingerHandle
from auth import createBasicAuthHeader
from posts import getPersonBox
def undoLikesCollectionEntry(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
"""Undoes a like for a particular actor
@ -406,3 +410,50 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str,
print('DEBUG: c2s POST undo like success')
return newUndoLikeJson
def outboxLike(baseDir: str,httpPrefix: str, \
nickname: str,domain: str,port: int, \
messageJson: {},debug: bool) -> None:
""" When a like request is received by the outbox from c2s
"""
if not messageJson.get('type'):
if debug:
print('DEBUG: like - no type')
return
if not messageJson['type']=='Like':
if debug:
print('DEBUG: not a like')
return
if not messageJson.get('object'):
if debug:
print('DEBUG: no object in like')
return
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: like object is not string')
return
if debug:
print('DEBUG: c2s like request arrived in outbox')
messageId=messageJson['object'].replace('/activity','')
if '/statuses/' not in messageId:
if debug:
print('DEBUG: c2s like object is not a status')
return
if '/users/' not in messageId:
if debug:
print('DEBUG: c2s like object has no nickname')
return
likeNickname=getNicknameFromActor(messageId)
likeDomain,likePort=getDomainFromActor(messageId)
if ':' in domain:
domain=domain.split(':')[0]
postFilename=locatePost(baseDir,likeNickname,likeDomain,messageId)
if not postFilename:
if debug:
print('DEBUG: c2s like post not found in inbox or outbox')
print(messageId)
return True
updateLikesCollection(postFilename,messageId,messageJson['actor'],debug)
if debug:
print('DEBUG: post liked via c2s - '+postFilename)

View File

@ -203,7 +203,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
maxReplies=64
domainMaxPostsPerDay=1000
accountMaxPostsPerDay=1000
allowDeletion=False
allowDeletion=True
privateKeyPem,publicKeyPem,person,wfEndpoint= \
createPerson(path,nickname,domain,port,httpPrefix,True,password)
deleteAllPosts(path,nickname,domain,'inbox')