do nothing and return 202 on deleted actor

This commit is contained in:
Izalia Mae 2021-09-24 13:37:28 -04:00
parent bb37740096
commit 49fb39139b
5 changed files with 45 additions and 26 deletions

View file

@ -30,6 +30,9 @@ def fetch_actor(url):
data = fetch(url, sign=True, cache=False)
if data == False:
return False
try:
error = data.get('error')
@ -65,6 +68,9 @@ def fetch(url, sign=False, headers={}, cache=True):
else:
response = client.request(url)
if response.status == 410:
return False
try:
data = response.dict
@ -105,19 +111,19 @@ def push_message(inbox, message, headers={}):
keyid = f'https://{config.host}/actor#main-key'
)
if response.status not in [200, 202]:
try:
body = response.dict
except:
body = response.text
logging.debug(f'Error from {inbox}: {body}')
return response
## this exception catching will be used later
except Exception as s:
pass
except MaxRetryError:
pass
return
except Exception as e:
logging.debug(f'push_message: {e.__class__.__name__}: {e}')
return
if response.status not in [200, 202]:
try:
body = response.dict
except:
body = response.text
logging.debug(f'Error from {inbox}: {body}')
return response

View file

@ -497,8 +497,11 @@ python3 -m uncia.manage convert [pleroma or uncia]:
handle = data[1]
domain = data[2]
if domain.lower() == 'none':
domain = None
reason = None if not args else ' '.join(args)
data = f'{user}@{domain}' if handle else domain
data = f'{handle}@{domain}' if handle else domain
with db.session as s:
if action == 'ban':

View file

@ -79,8 +79,12 @@ class AuthCheck(MiddlewareBase):
return response.text('no', status=403)
if request.path in ['/inbox', '/actor'] and request.method.lower() == 'post':
## The actor was deleted, so return a 202 to not get the same message over and over again
if request.actor == False:
return response.json({'error': 'Could not fetch deleted actor'}, status=202)
if not request.actor:
return response.json({'error': 'Could not get actor'}, status=400)
return response.json({'error': 'Could not get actor'}, status=401)
try:
data = request.data.json
@ -94,13 +98,13 @@ class AuthCheck(MiddlewareBase):
return response.error({'error': f'An unknown error happened'}, status=500)
if not request.instance and data.get('type', '').lower() != 'follow':
return response.text({'error': f'Follow the relay first'}, status=401)
return response.json({'error': f'Follow the relay first'}, status=401)
validated = verify_request(request, request.actor)
if not validated:
logging.debug(f'Not validated: {request.signature.actor}')
return response.text({'error': f'Failed signature check'}, status=401)
return response.json({'error': f'Failed signature check'}, status=401)
if any(map(request.path.startswith, auth_paths)) and not request.user:
return response.redir('/login')

View file

@ -24,7 +24,6 @@ class ProcessData:
async def __call__(self):
logging.verbose(f'Handling object of type "{self.type}"')
return getattr(self, f'cmd_{self.type}')()
@ -122,14 +121,20 @@ class ProcessData:
for instance in [row for row in s.get.instance_list() if row.domain not in [obj_domain, self.instance.domain]]:
response = msg.send(instance.inbox)
if response.status not in [200, 202]:
if not response or response.status not in [200, 202]:
logging.verbose(f'Failed to send object announce to {instance.domain}: {object.id}')
logging.debug(f'Server error {response.status}: {response.text}')
if response:
logging.debug(f'Server error {response.status}: {response.text}')
def cmd_create(self):
return self.cmd_announce()
#def cmd_delete(self):
#pass
def cmd_delete(self):
logging.verbose('Deletes not implemented yet')
def cmd_update(self):
logging.verbose('Updates not implemented yet')

View file

@ -140,9 +140,10 @@ class UnciaActor(View):
loop.create_task(processor())
else:
headers = {k: request.headers.getone(k) for k in request.headers}
logging.verbose('Message type not handled:', processor.type)
logging.debug(f'Headers: {json.dumps(request.headers)}')
logging.debug(f'Body: {json.dumps(request.body)}')
logging.debug(f'Headers: {json.dumps(headers)}')
logging.debug(f'Body: {request.text}')
#return response.json({'error': f'Message type unhandled: {processor.type}'}, status=401)
return response.text('UvU', status=202)