gdc: raise APIError on unloadable content (#61254)
This commit is contained in:
parent
4baad9742b
commit
7472aba9c6
|
@ -27,6 +27,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
||||
def deep_bytes2str(obj):
|
||||
|
@ -48,7 +49,11 @@ def deep_bytes2str(obj):
|
|||
|
||||
|
||||
def phpserialize_loads(s):
|
||||
return deep_bytes2str(phpserialize.loads(s.encode('utf-8')))
|
||||
try:
|
||||
return deep_bytes2str(phpserialize.loads(s.encode('utf-8')))
|
||||
except ValueError:
|
||||
truncated = s[:128] if isinstance(s, str) else s
|
||||
raise APIError(f'Could not deserialize GDC response {truncated!r}', data={'content': s})
|
||||
|
||||
|
||||
class Gdc(BaseResource):
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
import pytest
|
||||
|
||||
from passerelle.apps.gdc import models
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
||||
def test_phpserialize_loads():
|
||||
with pytest.raises(APIError, match='Could not deserialize GDC response'):
|
||||
models.phpserialize_loads('aaa')
|
Loading…
Reference in New Issue