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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
from pprint import pprint from pprint import pprint
import os import os
from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import hasActor from utils import hasActor
from utils import removeDomainPort 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'] == 'Follow':
if not messageJson['object']['type'] == 'Join': if not messageJson['object']['type'] == 'Join':
return return
if not messageJson['object'].get('object'): if not hasObjectStringObject(messageJson, debug):
return return
if not messageJson['object'].get('actor'): if not messageJson['object'].get('actor'):
return return
if not isinstance(messageJson['object']['object'], str):
return
if debug: if debug:
print('DEBUG: undo follow arrived in outbox') print('DEBUG: undo follow arrived in outbox')

View File

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

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os import os
from pprint import pprint from pprint import pprint
from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
from utils import hasObjectDict from utils import hasObjectDict
@ -387,13 +388,7 @@ def outboxUndoLike(recentPostsCache: {},
if debug: if debug:
print('DEBUG: not a undo like') print('DEBUG: not a undo like')
return return
if not messageJson['object'].get('object'): if not hasObjectStringObject(messageJson, debug):
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')
return return
if debug: if debug:
print('DEBUG: c2s undo like request arrived in outbox') 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: 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 not hasObjectDict(postJsonObject):
if debug: if debug:
@ -3053,3 +3053,22 @@ def hasObjectStringType(postJsonObject: {}, debug: bool) -> bool:
if debug: if debug:
print('No type field within object ' + postJsonObject['id']) print('No type field within object ' + postJsonObject['id'])
return False 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