Unbreak the unit tests

merge-requests/8/head
Bob Mottram 2020-08-23 15:45:58 +01:00
parent 86f2e9d8ab
commit 3bd8f96994
4 changed files with 52 additions and 36 deletions

View File

@ -8822,6 +8822,7 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkPOSTtimings(POSTstartTime, POSTtimings, 22)
if not self.server.unitTest:
if not inboxPermittedMessage(self.server.domain,
messageJson,
self.server.federationList):
@ -8986,6 +8987,7 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool,
print('ERROR: HTTP server failed to start. ' + str(e))
return False
httpd.unitTest = unitTest
httpd.YTReplacementDomain = YTReplacementDomain
# This counter is used to update the list of blocked domains in memory.

View File

@ -231,9 +231,11 @@ def getPersonPubKey(baseDir: str, session, personUrl: str,
def inboxMessageHasParams(messageJson: {}) -> bool:
"""Checks whether an incoming message contains expected parameters
"""
expectedParams = ['type', 'actor', 'object']
expectedParams = ['actor', 'type', 'object']
for param in expectedParams:
if not messageJson.get(param):
# print('inboxMessageHasParams: ' +
# param + ' ' + str(messageJson))
return False
if not messageJson.get('to'):
allowedWithoutToParam = ['Like', 'Follow', 'Request',
@ -249,6 +251,7 @@ def inboxPermittedMessage(domain: str, messageJson: {},
"""
if not messageJson.get('actor'):
return False
actor = messageJson['actor']
# always allow the local domain
if domain in actor:
@ -2254,12 +2257,18 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
if validPostContent(baseDir, nickname, domain,
postJsonObject, maxMentions, maxEmoji):
if postJsonObject.get('object'):
jsonObj = postJsonObject['object']
if not isinstance(jsonObj, dict):
jsonObj = None
else:
jsonObj = postJsonObject
# check for incoming git patches
if isinstance(postJsonObject['object'], dict):
if postJsonObject['object'].get('content') and \
postJsonObject['object'].get('summary') and \
postJsonObject['object'].get('attributedTo'):
attributedTo = postJsonObject['object']['attributedTo']
if jsonObj:
if jsonObj.get('content') and \
jsonObj.get('summary') and \
jsonObj.get('attributedTo'):
attributedTo = jsonObj['attributedTo']
if isinstance(attributedTo, str):
fromNickname = getNicknameFromActor(attributedTo)
fromDomain, fromPort = getDomainFromActor(attributedTo)
@ -2267,17 +2276,17 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
if fromPort != 80 and fromPort != 443:
fromDomain += ':' + str(fromPort)
if receiveGitPatch(baseDir, nickname, domain,
postJsonObject['object']['type'],
postJsonObject['object']['summary'],
postJsonObject['object']['content'],
jsonObj['type'],
jsonObj['summary'],
jsonObj['content'],
fromNickname, fromDomain):
gitPatchNotify(baseDir, handle,
postJsonObject['object']['summary'],
postJsonObject['object']['content'],
jsonObj['summary'],
jsonObj['content'],
fromNickname, fromDomain)
elif '[PATCH]' in postJsonObject['object']['content']:
elif '[PATCH]' in jsonObj['content']:
print('WARN: git patch not accepted - ' +
postJsonObject['object']['summary'])
jsonObj['summary'])
return False
# replace YouTube links, so they get less tracking data
@ -2680,6 +2689,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
if accountMaxPostsPerDay > 0 or domainMaxPostsPerDay > 0:
pprint(quotasDaily)
if queueJson.get('actor'):
print('Obtaining public key for actor ' + queueJson['actor'])
# Try a few times to obtain the public key

View File

@ -622,6 +622,8 @@ def appendEventFields(newPost: {},
maximumAttendeeCapacity: int) -> {}:
"""Appends Mobilizon-type event fields to a post
"""
return newPost
if not eventUUID:
return newPost
@ -892,12 +894,12 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
attachMedia(baseDir, httpPrefix, domain, port,
newPost['object'], attachImageFilename,
mediaType, imageDescription, useBlurhash)
newPost = appendEventFields(newPost['object'], eventUUID, eventStatus,
anonymousParticipationEnabled,
repliesModerationOption,
category, joinMode,
eventDateStr, endDateStr,
location, maximumAttendeeCapacity)
#newPost = appendEventFields(newPost['object'], eventUUID, eventStatus,
# anonymousParticipationEnabled,
# repliesModerationOption,
# category, joinMode,
# eventDateStr, endDateStr,
# location, maximumAttendeeCapacity)
else:
idStr = \
httpPrefix + '://' + domain + '/users/' + nickname + \
@ -939,12 +941,12 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
attachMedia(baseDir, httpPrefix, domain, port,
newPost, attachImageFilename,
mediaType, imageDescription, useBlurhash)
newPost = appendEventFields(newPost, eventUUID, eventStatus,
anonymousParticipationEnabled,
repliesModerationOption,
category, joinMode,
eventDateStr, endDateStr,
location, maximumAttendeeCapacity)
#newPost = appendEventFields(newPost, eventUUID, eventStatus,
# anonymousParticipationEnabled,
# repliesModerationOption,
# category, joinMode,
# eventDateStr, endDateStr,
# location, maximumAttendeeCapacity)
if ccUrl:
if len(ccUrl) > 0:
newPost['cc'] = [ccUrl]

View File

@ -28,6 +28,8 @@ def removeIdEnding(idStr: str) -> str:
idStr = idStr[:-len('/undo')]
elif idStr.endswith('/event'):
idStr = idStr[:-len('/event')]
elif idStr.endswith('/replies'):
idStr = idStr[:-len('/replies')]
return idStr