11 |
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
13 |
# GNU Affero General Public License for more details.
|
14 |
14 |
#
|
15 |
15 |
# You should have received a copy of the GNU Affero General Public License
|
16 |
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
17 |
|
18 |
18 |
import datetime
|
|
19 |
import json
|
19 |
20 |
import mock
|
20 |
21 |
|
21 |
22 |
import requests
|
22 |
23 |
|
23 |
24 |
from django.contrib.auth import get_user_model
|
24 |
25 |
from django.urls import reverse
|
25 |
26 |
from django.utils.six.moves.urllib import parse as urlparse
|
26 |
27 |
from django.utils.timezone import now
|
... | ... | |
394 |
395 |
assert deleted_user.old_data.get('fc_accounts') == [
|
395 |
396 |
{
|
396 |
397 |
'sub': '1234',
|
397 |
398 |
},
|
398 |
399 |
{
|
399 |
400 |
'sub': '4567',
|
400 |
401 |
}
|
401 |
402 |
]
|
|
403 |
|
|
404 |
|
|
405 |
def test_update_user_with_redondant_email(app, franceconnect, settings):
|
|
406 |
settings.A2_email_IS_UNIQUE = True
|
|
407 |
|
|
408 |
# account1 is linked to FC
|
|
409 |
email1 = 'fred@example.com'
|
|
410 |
user = User.objects.create(email=email1, first_name='Frédérique', last_name='Ÿuñe')
|
|
411 |
user.set_password('toto')
|
|
412 |
user.save()
|
|
413 |
models.FcAccount.objects.create(user=user, sub='1234', token='xxx')
|
|
414 |
|
|
415 |
# FC account linked to account1's provides account2 email
|
|
416 |
email2 = 'john.doe@example.com'
|
|
417 |
User.objects.create(email=email2, first_name='John', last_name='Doe')
|
|
418 |
franceconnect.user_info['email'] = email2
|
|
419 |
|
|
420 |
franceconnect.login_with_fc_fixed_params(app)
|
|
421 |
assert User.objects.get(first_name='Ÿuñe').email == email1
|
|
422 |
|
|
423 |
|
|
424 |
def test_create_user_with_redondant_email(settings, app, franceconnect):
|
|
425 |
settings.A2_FC_CREATE = True
|
|
426 |
settings.A2_EMAIL_IS_UNIQUE = True
|
|
427 |
|
|
428 |
# A2 accounts not linked to FC
|
|
429 |
mail = franceconnect.user_info['email']
|
|
430 |
User.objects.create(email=mail, first_name='John', last_name='Doe')
|
|
431 |
|
|
432 |
# connect with an unrelated FC account providing an email already used
|
|
433 |
response = app.get('/login/?service=portail&next=/idp/')
|
|
434 |
response = response.click(href='callback')
|
|
435 |
|
|
436 |
assert User.objects.count() == 1
|
|
437 |
response = franceconnect.handle_authorization(app, response.location, status=302)
|
|
438 |
assert User.objects.count() == 2
|
|
439 |
assert User.objects.get(first_name='Ÿuñe').email == mail # Should be "!="
|
402 |
|
-
|