franceconnect: fix data_source endpoint with bad id in param (#71456)

This commit is contained in:
Lauréline Guérin 2022-11-18 16:42:43 +01:00
parent 9b889430d1
commit d0bdb9b618
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 13 additions and 5 deletions

View File

@ -222,11 +222,13 @@ class Resource(BaseResource):
)
def data_source(self, request, id=None, test=None, mode=None, **kwargs):
if id:
return {
'data': [
dict(self.retrieve(id), id=id),
]
}
token = self.retrieve(id)
if token:
return {
'data': [
dict(token, id=id),
]
}
url = request.build_absolute_uri(
reverse(
'generic-endpoint',
@ -262,6 +264,10 @@ class Resource(BaseResource):
return token.guid.hex
def retrieve(self, ref):
try:
ref = uuid.UUID(str(ref))
except ValueError:
return None
token = Token.objects.filter(guid=ref).first()
return token and token.content

View File

@ -95,6 +95,8 @@ def test_callback(app, fc):
'text': 'John Doe né le April 28, 2001',
}
app.get('/franceconnect-data/test/data_source?id=bad') # no error
@mock_response(
['/api/v1/token', ''],