0002-franceconnect-maps-FC-gender-to-Publik-title-32876.patch
hobo/franceconnect/views.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
18 | ||
17 | 19 |
from django.core.urlresolvers import reverse_lazy |
18 | 20 |
from django.views.generic import RedirectView, FormView |
19 | 21 | |
... | ... | |
30 | 32 |
}) |
31 | 33 |
return variable |
32 | 34 | |
35 |
PLATFORMS = { |
|
36 |
'test': { |
|
37 |
'A2_FC_AUTHORIZE_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize', |
|
38 |
'A2_FC_TOKEN_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token', |
|
39 |
'A2_FC_USERINFO_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo', |
|
40 |
'A2_FC_LOGOUT_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout', |
|
41 |
}, |
|
42 |
'prod': { |
|
43 |
'A2_FC_AUTHORIZE_URL': 'https://app.franceconnect.gouv.fr/api/v1/authorize', |
|
44 |
'A2_FC_TOKEN_URL': 'https://app.franceconnect.gouv.fr/api/v1/token', |
|
45 |
'A2_FC_USERINFO_URL': 'https://app.franceconnect.gouv.fr/api/v1/userinfo', |
|
46 |
'A2_FC_LOGOUT_URL': 'https://app.franceconnect.gouv.fr/api/v1/logout', |
|
47 |
} |
|
48 |
} |
|
49 | ||
33 | 50 | |
34 | 51 |
class HomeView(FormView): |
35 | 52 |
template_name = 'hobo/franceconnect_home.html' |
... | ... | |
50 | 67 |
return initial |
51 | 68 | |
52 | 69 |
def form_valid(self, form): |
53 |
platforms = { |
|
54 |
'test': { |
|
55 |
'A2_FC_AUTHORIZE_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize', |
|
56 |
'A2_FC_TOKEN_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token', |
|
57 |
'A2_FC_USERINFO_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo', |
|
58 |
'A2_FC_LOGOUT_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout', |
|
59 |
}, |
|
60 |
'prod': { |
|
61 |
'A2_FC_AUTHORIZE_URL': 'https://app.franceconnect.gouv.fr/api/v1/authorize', |
|
62 |
'A2_FC_TOKEN_URL': 'https://app.franceconnect.gouv.fr/api/v1/token', |
|
63 |
'A2_FC_USERINFO_URL': 'https://app.franceconnect.gouv.fr/api/v1/userinfo', |
|
64 |
'A2_FC_LOGOUT_URL': 'https://app.franceconnect.gouv.fr/api/v1/logout', |
|
65 |
} |
|
66 |
} |
|
67 | ||
68 |
for key, value in platforms[form.cleaned_data['platform']].items(): |
|
70 |
for key, value in PLATFORMS[form.cleaned_data['platform']].items(): |
|
69 | 71 |
variable = get_variable(key) |
70 | 72 |
variable.value = value |
71 | 73 |
variable.save() |
... | ... | |
82 | 84 |
variable.value = 'true' |
83 | 85 |
variable.save() |
84 | 86 | |
87 |
variable = get_variable('A2_FC_USER_INFO_MAPPINGS') |
|
88 |
variable.value = json.dumps({ |
|
89 |
'last_name': { |
|
90 |
'ref': 'family_name', |
|
91 |
'verified': True, |
|
92 |
}, |
|
93 |
'first_name': { |
|
94 |
'ref': 'given_name', |
|
95 |
'verified': True, |
|
96 |
}, |
|
97 |
'title': { |
|
98 |
'ref': 'gender', |
|
99 |
'translation': 'simple', |
|
100 |
'translation_simple': { |
|
101 |
'male': 'Monsieur', |
|
102 |
'female': 'Madame', |
|
103 |
}, |
|
104 |
'verified': True, |
|
105 |
}, |
|
106 |
'email': 'email', |
|
107 |
}) |
|
108 |
variable.save() |
|
109 | ||
85 | 110 |
return super(HomeView, self).form_valid(form) |
86 | 111 | |
87 | 112 |
def get_context_data(self, **kwargs): |
tests/test_franceconnect.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from test_manager import login |
|
18 | ||
19 |
from hobo.environment.models import Variable, Authentic |
|
20 |
from hobo.franceconnect.views import PLATFORMS |
|
21 | ||
22 | ||
23 |
def test_franceconnect(app, admin_user): |
|
24 |
Authentic.objects.create(title='bar', slug='bar', base_url='http://bar.example.net') |
|
25 |
login(app) |
|
26 | ||
27 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 0 |
|
28 | ||
29 |
response = app.get('/franceconnect/') |
|
30 | ||
31 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4 |
|
32 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0 |
|
33 | ||
34 |
response = response.click('Enable') |
|
35 | ||
36 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4 |
|
37 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0 |
|
38 | ||
39 |
response = response.form.submit().follow() |
|
40 | ||
41 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4 |
|
42 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 1 |
|
43 | ||
44 |
response.form.set('platform', 'prod') |
|
45 |
response.form.set('client_id', 'xyz') |
|
46 |
response.form.set('client_secret', '1234') |
|
47 |
response = response.form.submit().follow() |
|
48 | ||
49 |
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 9 |
|
50 | ||
51 |
for key, value in PLATFORMS['prod'].items(): |
|
52 |
assert Variable.objects.filter(name='SETTING_' + key, value=value).count() == 1 |
|
53 | ||
54 |
assert Variable.objects.get(name='SETTING_A2_FC_USER_INFO_MAPPINGS').json == { |
|
55 |
"last_name": { |
|
56 |
"ref": "family_name", |
|
57 |
"verified": True |
|
58 |
}, |
|
59 |
"first_name": { |
|
60 |
"ref": "given_name", |
|
61 |
"verified": True, |
|
62 |
}, |
|
63 |
"title": { |
|
64 |
"ref": "gender", |
|
65 |
"translation": "simple", |
|
66 |
"translation_simple": { |
|
67 |
"male": "Monsieur", |
|
68 |
"female": "Madame" |
|
69 |
}, |
|
70 |
"verified": True |
|
71 |
}, |
|
72 |
"email": "email" |
|
73 |
} |
|
0 |
- |