fixing new jwt into a json

This commit is contained in:
Cayo Puigdefabregas 2021-07-05 12:31:16 +02:00
parent 4b4c0a1480
commit b8e9ed22f6

View file

@ -171,7 +171,11 @@ import jwt
import ereuse_utils import ereuse_utils
def decode_snapshot(data): def decode_snapshot(data):
p = '7KU4ZzsEfe' p = '7KU4ZzsEfe'
return jwt.decode(data, p, algorithms="HS256", json_encoder=ereuse_utils.JSONEncoder) try:
return jwt.decode(data['data'], p, algorithms="HS256", json_encoder=ereuse_utils.JSONEncoder)
except jwt.exceptions.InvalidSignatureError as err:
txt = 'Invalid snapshot'
raise ValidationError(txt)
class ActionView(View): class ActionView(View):
@ -180,16 +184,23 @@ class ActionView(View):
json = request.get_json(validate=False) json = request.get_json(validate=False)
if not type(json) == dict:
json = decode_snapshot(json)
if not json or 'type' not in json: if not json or 'type' not in json:
raise ValidationError('Post request needs a json.') raise ValidationError('Post request needs a json.')
# todo there should be a way to better get subclassess resource # todo there should be a way to better get subclassess resource
# defs # defs
resource_def = app.resources[json['type']] resource_def = app.resources[json['type']]
if json['type'] == Snapshot.t: if json['type'] == Snapshot.t:
snapshot = SnapshotView(json, resource_def, self.schema) if not 'data' in json:
txt = 'Invalid snapshot'
raise ValidationError(txt)
snapshot_data = decode_snapshot(json)
if not snapshot_data:
txt = 'Invalid snapshot'
raise ValidationError(txt)
snapshot = SnapshotView(snapshot_data, resource_def, self.schema)
return snapshot.post() return snapshot.post()
if json['type'] == VisualTest.t: if json['type'] == VisualTest.t: