merge-requests/26/head
Bob Mottram 2021-10-13 11:37:52 +01:00
parent 614e274e24
commit b8fbc8057b
7 changed files with 34 additions and 47 deletions

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "ActivityPub"
import os
from utils import hasObjectStringObject
from utils import hasUsersPath
from utils import getFullDomain
from utils import urlPermitted
@ -89,8 +90,7 @@ def _acceptFollow(baseDir: str, domain: str, messageJson: {},
print('DEBUG: no actor in Follow activity')
return
# no, this isn't a mistake
if not messageJson['object'].get('object'):
print('DEBUG: no object within Follow activity')
if not hasObjectStringObject(messageJson, debug):
return
if not messageJson.get('to'):
if debug:

View File

@ -7,6 +7,7 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
from utils import hasObjectStringObject
from utils import hasGroupType
from utils import removeDomainPort
from utils import removeIdEnding
@ -401,13 +402,7 @@ def outboxUndoAnnounce(recentPostsCache: {},
if debug:
print('DEBUG: not a undo announce')
return
if not messageJson['object'].get('object'):
if debug:
print('DEBUG: no object in undo announce')
return
if not isinstance(messageJson['object']['object'], str):
if debug:
print('DEBUG: undo announce object is not string')
if not hasObjectStringObject(messageJson, debug):
return
if debug:
print('DEBUG: c2s undo announce request arrived in outbox')

View File

@ -11,6 +11,7 @@ import os
import json
import time
from datetime import datetime
from utils import hasObjectStringObject
from utils import hasObjectStringType
from utils import removeDomainPort
from utils import hasObjectDict
@ -410,13 +411,7 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
if debug:
print('DEBUG: not an undo block')
return
if not messageJson['object'].get('object'):
if debug:
print('DEBUG: no object in undo block')
return
if not isinstance(messageJson['object']['object'], str):
if debug:
print('DEBUG: undo block object is not string')
if not hasObjectStringObject(messageJson, debug):
return
if debug:
print('DEBUG: c2s undo block request arrived in outbox')

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
from pprint import pprint
import os
from utils import hasObjectStringObject
from utils import hasObjectStringType
from utils import hasActor
from utils import removeDomainPort
@ -1493,12 +1494,10 @@ def outboxUndoFollow(baseDir: str, messageJson: {}, debug: bool) -> None:
if not messageJson['object']['type'] == 'Follow':
if not messageJson['object']['type'] == 'Join':
return
if not messageJson['object'].get('object'):
if not hasObjectStringObject(messageJson, debug):
return
if not messageJson['object'].get('actor'):
return
if not isinstance(messageJson['object']['object'], str):
return
if debug:
print('DEBUG: undo follow arrived in outbox')

View File

@ -15,6 +15,7 @@ import random
from linked_data_sig import verifyJsonSignature
from languages import understoodPostLanguage
from like import updateLikesCollection
from utils import hasObjectStringObject
from utils import getReplyIntervalHours
from utils import canReplyTo
from utils import getUserPaths
@ -695,15 +696,7 @@ def _receiveUndo(session, baseDir: str, httpPrefix: str,
return False
if not hasObjectStringType(messageJson, debug):
return False
if not messageJson['object'].get('object'):
if debug:
print('DEBUG: ' + messageJson['type'] +
' has no object within object')
return False
if not isinstance(messageJson['object']['object'], str):
if debug:
print('DEBUG: ' + messageJson['type'] +
' object within object is not a string')
if not hasObjectStringObject(messageJson, debug):
return False
if messageJson['object']['type'] == 'Follow' or \
messageJson['object']['type'] == 'Join':
@ -1014,14 +1007,7 @@ def _receiveUndoLike(recentPostsCache: {},
return False
if messageJson['object']['type'] != 'Like':
return False
if not messageJson['object'].get('object'):
if debug:
print('DEBUG: ' + messageJson['type'] + ' like has no object')
return False
if not isinstance(messageJson['object']['object'], str):
if debug:
print('DEBUG: ' + messageJson['type'] +
' like object is not a string')
if not hasObjectStringObject(messageJson, debug):
return False
if not hasUsersPath(messageJson['actor']):
if debug:
@ -1625,9 +1611,7 @@ def _receiveUndoAnnounce(recentPostsCache: {},
return False
if not hasObjectDict(messageJson):
return False
if not messageJson['object'].get('object'):
return False
if not isinstance(messageJson['object']['object'], str):
if not hasObjectStringObject(messageJson, debug):
return False
if messageJson['object']['type'] != 'Announce':
return False

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os
from pprint import pprint
from utils import hasObjectStringObject
from utils import hasObjectStringType
from utils import removeDomainPort
from utils import hasObjectDict
@ -387,13 +388,7 @@ def outboxUndoLike(recentPostsCache: {},
if debug:
print('DEBUG: not a undo like')
return
if not messageJson['object'].get('object'):
if debug:
print('DEBUG: no object in undo like')
return
if not isinstance(messageJson['object']['object'], str):
if debug:
print('DEBUG: undo like object is not string')
if not hasObjectStringObject(messageJson, debug):
return
if debug:
print('DEBUG: c2s undo like request arrived in outbox')

View File

@ -3037,7 +3037,7 @@ def hasActor(postJsonObject: {}, debug: bool) -> bool:
def hasObjectStringType(postJsonObject: {}, debug: bool) -> bool:
"""Dies the given post have a type field within an object dict?
"""Does the given post have a type field within an object dict?
"""
if not hasObjectDict(postJsonObject):
if debug:
@ -3053,3 +3053,22 @@ def hasObjectStringType(postJsonObject: {}, debug: bool) -> bool:
if debug:
print('No type field within object ' + postJsonObject['id'])
return False
def hasObjectStringObject(postJsonObject: {}, debug: bool) -> bool:
"""Does the given post have an object string field within an object dict?
"""
if not hasObjectDict(postJsonObject):
if debug:
print('hasObjectStringType no object found')
return False
if postJsonObject['object'].get('object'):
if isinstance(postJsonObject['object']['object'], str):
return True
elif debug:
if postJsonObject.get('type'):
print('DEBUG: ' + postJsonObject['type'] +
' object within dict is not a string')
if debug:
print('No object field within dict ' + postJsonObject['id'])
return False