0001-solis-allow-dateNaissance-in-rsa_token-payload-39285.patch
passerelle/apps/solis/migrations/0007_solisrsalink_dob.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-01-27 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations, models |
|
6 | ||
7 | ||
8 |
class Migration(migrations.Migration): |
|
9 | ||
10 |
dependencies = [ |
|
11 |
('solis', '0006_solisrsalink'), |
|
12 |
] |
|
13 | ||
14 |
operations = [ |
|
15 |
migrations.AddField( |
|
16 |
model_name='solisrsalink', |
|
17 |
name='dob', |
|
18 |
field=models.CharField(blank=True, max_length=64, null=True), |
|
19 |
), |
|
20 |
] |
passerelle/apps/solis/models.py | ||
---|---|---|
459 | 459 |
# RSA endpoints |
460 | 460 |
# |
461 | 461 | |
462 |
def rsa_token(self, user_id, code): |
|
463 |
response = self.request('referentiels/grsa/token', data={
|
|
464 |
'indexIndividu': user_id,
|
|
465 |
'codeConfidentiel': code,
|
|
466 |
})
|
|
462 |
def rsa_token(self, user_id, code, dob=None):
|
|
463 |
data = {'indexIndividu': user_id, 'codeConfidentiel': code}
|
|
464 |
if dob:
|
|
465 |
data['dateNaissance'] = dob
|
|
466 |
response = self.request('referentiels/grsa/token', data=data)
|
|
467 | 467 |
return response.get('token') |
468 | 468 | |
469 | 469 |
def rsa_fill_with_link_content(self, link): |
... | ... | |
491 | 491 |
} |
492 | 492 |
link['content'] = value |
493 | 493 | |
494 |
def rsa_get_information(self, information, user_id=None, code=None, token=None, |
|
494 |
def rsa_get_information(self, information, user_id=None, code=None, dob=None, token=None,
|
|
495 | 495 |
index='search', links=None): |
496 | 496 |
# simulate "individu" referential: get user details from civi/individu/user_id |
497 | 497 |
if information == 'individu': |
... | ... | |
504 | 504 |
data={'json_content': content}) |
505 | 505 |
return content |
506 | 506 |
if token is None: |
507 |
token = self.rsa_token(user_id, code) |
|
507 |
token = self.rsa_token(user_id, code, dob)
|
|
508 | 508 |
endpoint = 'referentiels/grsa/' + information + '/' + index + '/' |
509 | 509 |
args = [('token', token)] |
510 | 510 |
if index.startswith('search'): # it can be "search/next" in rdvs referential |
... | ... | |
530 | 530 | |
531 | 531 |
@endpoint(name='rsa-link', methods=['post'], perm='can_access', |
532 | 532 |
description=_('Create link between name_id and ' |
533 |
'Solis RSA. Payload: name_id, user_id, code')) |
|
533 |
'Solis RSA. Payload: name_id, user_id, code, dob (optionnal)'))
|
|
534 | 534 |
def rsa_link(self, request): |
535 | 535 |
try: |
536 | 536 |
data = json.loads(request.body) |
... | ... | |
543 | 543 |
if not data.get('user_id') or not data.get('code'): |
544 | 544 |
raise APIError('missing user_id/code credentials') |
545 | 545 |
name_id, user_id, code = data['name_id'], data['user_id'], data['code'] |
546 |
self.rsa_token(user_id, code) # invalid credentials raise APIError here |
|
547 |
information = self.rsa_get_information('individu', user_id, code) |
|
546 |
dob = data.get('dob') |
|
547 |
self.rsa_token(user_id, code, dob) # invalid credentials raise APIError here |
|
548 |
information = self.rsa_get_information('individu', user_id, code, dob) |
|
548 | 549 |
text = get_template(self.text_template_name_rsa).render(information).strip() |
549 | 550 |
link, created = SolisRSALink.objects.update_or_create(resource=self, name_id=name_id, |
550 | 551 |
user_id=user_id, |
551 | 552 |
defaults={'code': code, |
553 |
'dob': dob, |
|
552 | 554 |
'text': text}) |
553 | 555 |
return {'data': {'user_id': user_id, |
554 | 556 |
'text': text, |
... | ... | |
619 | 621 |
except SolisRSALink.DoesNotExist: |
620 | 622 |
raise APIError('unknown link') |
621 | 623 |
response = self.rsa_get_information(information=information, |
622 |
user_id=user_id, code=link.code, |
|
624 |
user_id=user_id, code=link.code, dob=link.dob,
|
|
623 | 625 |
index=index, links=links) |
624 | 626 |
if information == 'individu': |
625 | 627 |
text = get_template(self.text_template_name_rsa).render(response).strip() |
... | ... | |
651 | 653 |
name_id = models.CharField(blank=False, max_length=256) |
652 | 654 |
user_id = models.CharField(blank=False, max_length=64) |
653 | 655 |
code = models.CharField(blank=False, max_length=64) |
656 |
dob = models.CharField(blank=True, max_length=64, null=True) |
|
654 | 657 |
text = models.CharField(blank=False, max_length=256) |
tests/test_solis.py | ||
---|---|---|
761 | 761 |
assert SolisRSALink.objects.first().user_id == '4273' |
762 | 762 |
assert SolisRSALink.objects.first().code == 'foo' |
763 | 763 |
assert SolisRSALink.objects.first().text == 'MME Prenom NOM' |
764 |
assert SolisRSALink.objects.first().dob is None |
|
764 | 765 | |
765 |
# change code |
|
766 |
# change code, add dob
|
|
766 | 767 |
resp = app.post_json(endpoint, |
767 |
params={'name_id': NAMEID, 'user_id': '4273', 'code': 'bar'}, |
|
768 |
params={'name_id': NAMEID, 'user_id': '4273', 'code': 'bar', 'dob': '01/01/1950'},
|
|
768 | 769 |
status=200) |
769 | 770 |
assert requests_post.call_count == 3 |
770 | 771 |
assert requests_get.call_count == 2 |
... | ... | |
777 | 778 |
assert SolisRSALink.objects.first().user_id == '4273' |
778 | 779 |
assert SolisRSALink.objects.first().code == 'bar' |
779 | 780 |
assert SolisRSALink.objects.first().text == 'MME Prenom NOM' |
781 |
assert SolisRSALink.objects.first().dob == '01/01/1950' |
|
780 | 782 | |
781 | 783 |
# second link |
784 |
requests_post.reset_mock() |
|
785 |
requests_get.reset_mock() |
|
782 | 786 |
resp = app.post_json(endpoint, |
783 |
params={'name_id': NAMEID, 'user_id': '4242', 'code': 'bar'}, |
|
787 |
params={'name_id': NAMEID, 'user_id': '4242', 'code': 'bar', 'dob': '10/10/1960'},
|
|
784 | 788 |
status=200) |
785 |
assert requests_post.call_count == 4 |
|
786 |
assert requests_get.call_count == 3 |
|
789 |
assert requests_post.call_count == 1 |
|
790 |
assert requests_get.call_count == 1 |
|
791 |
assert requests_post.call_args[1]['json'] == {'codeConfidentiel': 'bar', |
|
792 |
'dateNaissance': '10/10/1960', |
|
793 |
'indexIndividu': '4242'} |
|
787 | 794 |
assert resp.json['err'] == 0 |
788 | 795 |
assert resp.json['data']['user_id'] == '4242' |
789 | 796 |
assert resp.json['data']['created'] |
790 |
- |