Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
f3ae0542
Commit
f3ae0542
authored
3 years ago
by
Stein Elgethun
Browse files
Options
Downloads
Patches
Plain Diff
Test that existing user overwrites invite properly
Issue: greg-105
parent
0b75f3b7
No related branches found
No related tags found
1 merge request
!225
Login with existing user and invite
Pipeline
#109315
passed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gregui/tests/authentication/test_user_profile.py
+54
-1
54 additions, 1 deletion
gregui/tests/authentication/test_user_profile.py
with
54 additions
and
1 deletion
gregui/tests/authentication/test_user_profile.py
+
54
−
1
View file @
f3ae0542
...
...
@@ -4,7 +4,7 @@ from django.test.client import RequestFactory
from
greg.models
import
Identity
from
gregui.authentication.auth_backends
import
GregOIDCBackend
from
gregui.models
import
GregUserProfile
from
gregui.models
import
GregUserProfile
,
Person
@pytest.mark.django_db
...
...
@@ -265,3 +265,56 @@ def test_invited_user_no_id(invited_person_no_ids):
assert
len
(
person_feide_email
)
==
1
assert
person_feide_email
[
0
].
value
==
feide_id
assert
person_feide_email
[
0
].
verified
==
Identity
.
Verified
.
AUTOMATIC
@pytest.mark.django_db
def
test_invited_existing_user
(
invited_person
,
user_person
):
"""
Invitation login, user with existing person and GregUserProfile
Expect the person connected to the invite to be deleted and replaced by
the existing person
"""
old_user
=
user_person
old_person
=
GregUserProfile
.
objects
.
get
(
user
=
old_user
).
person
feide_id
=
(
old_person
.
identities
.
filter
(
type
=
Identity
.
IdentityType
.
FEIDE_ID
).
first
().
value
)
person
,
invitation_link
=
invited_person
auth_request
=
RequestFactory
().
get
(
"
/foo
"
,
{
"
code
"
:
"
foo
"
,
"
state
"
:
"
bar
"
})
auth_request
.
session
=
{
"
invite_id
"
:
invitation_link
.
uuid
}
backend
=
GregOIDCBackend
()
backend
.
request
=
auth_request
with
pytest
.
raises
(
GregUserProfile
.
DoesNotExist
):
GregUserProfile
.
objects
.
get
(
person
=
person
)
claims
=
{
"
sub
"
:
f
"
{
old_user
.
username
}
"
,
"
connect-userid_sec
"
:
[
f
"
feide:
{
feide_id
}
"
],
"
dataporten-userid_sec
"
:
[
f
"
feide:
{
feide_id
}
"
,
f
"
nin:
{
old_person
.
fnr
.
value
}
"
],
"
name
"
:
f
"
{
old_person
.
first_name
}
{
old_person
.
last_name
}
"
,
"
email
"
:
f
"
{
feide_id
}
"
,
"
email_verified
"
:
True
,
"
picture
"
:
"
https://foo.org/p:2192dff7-6989-4244-83cc-ae5e78875bdd
"
,
}
# set username like this user was created by logging in
old_user
.
username
=
backend
.
get_username
(
old_user
.
username
)
old_user
.
save
()
assert
invitation_link
.
invitation
.
role
.
person
==
person
user
=
backend
.
update_user
(
old_user
,
claims
)
invitation_link
.
refresh_from_db
()
assert
invitation_link
.
invitation
.
role
.
person
==
old_person
old_person
.
refresh_from_db
()
with
pytest
.
raises
(
Person
.
DoesNotExist
):
person
.
refresh_from_db
()
user_profile
=
GregUserProfile
.
objects
.
get
(
user
=
user
)
assert
user_profile
.
person
==
old_person
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment