Project

General

Profile

0001-franceconnect-fix-data_source-endpoint-with-bad-id-i.patch

Lauréline Guérin, 18 November 2022 04:43 PM

Download (1.99 KB)

View differences:

Subject: [PATCH] franceconnect: fix data_source endpoint with bad id in param
 (#71456)

 passerelle/apps/franceconnect_data/models.py | 16 +++++++++++-----
 tests/test_franceconnect_data.py             |  2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)
passerelle/apps/franceconnect_data/models.py
222 222
    )
223 223
    def data_source(self, request, id=None, test=None, mode=None, **kwargs):
224 224
        if id:
225
            return {
226
                'data': [
227
                    dict(self.retrieve(id), id=id),
228
                ]
229
            }
225
            token = self.retrieve(id)
226
            if token:
227
                return {
228
                    'data': [
229
                        dict(token, id=id),
230
                    ]
231
                }
230 232
        url = request.build_absolute_uri(
231 233
            reverse(
232 234
                'generic-endpoint',
......
262 264
        return token.guid.hex
263 265

  
264 266
    def retrieve(self, ref):
267
        try:
268
            ref = uuid.UUID(str(ref))
269
        except ValueError:
270
            return None
265 271
        token = Token.objects.filter(guid=ref).first()
266 272
        return token and token.content
267 273

  
tests/test_franceconnect_data.py
95 95
        'text': 'John Doe né le April 28, 2001',
96 96
    }
97 97

  
98
    app.get('/franceconnect-data/test/data_source?id=bad')  # no error
99

  
98 100

  
99 101
@mock_response(
100 102
    ['/api/v1/token', ''],
101
-