Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix source_flow_manager throwing error when authenticated user attempts to re-authenticate with existing link #12080

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions authentik/core/sources/flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
)
new_connection.user = self.request.user
new_connection = self.update_user_connection(new_connection, **kwargs)
if existing := self.user_connection_type.objects.filter(
source=self.source, identifier=self.identifier
).first():
existing = self.update_user_connection(existing)
return Action.AUTH, existing

Check warning on line 136 in authentik/core/sources/flow_manager.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/sources/flow_manager.py#L135-L136

Added lines #L135 - L136 were not covered by tests
return Action.LINK, new_connection

action, connection = self.matcher.get_user_action(self.identifier, self.user_properties)
Expand Down
16 changes: 16 additions & 0 deletions authentik/core/tests/test_source_flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@
reverse("authentik_core:if-user") + "#/settings;page-sources",
)

def test_authenticated_auth(self):

Check warning on line 84 in authentik/core/tests/test_source_flow_manager.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_source_flow_manager.py#L84

Added line #L84 was not covered by tests
"""Test authenticated user linking"""
user = User.objects.create(username="foo", email="foo@bar.baz")
UserOAuthSourceConnection.objects.create(

Check warning on line 87 in authentik/core/tests/test_source_flow_manager.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_source_flow_manager.py#L86-L87

Added lines #L86 - L87 were not covered by tests
user=user, source=self.source, identifier=self.identifier
)
request = get_request("/", user=user)
flow_manager = OAuthSourceFlowManager(

Check warning on line 91 in authentik/core/tests/test_source_flow_manager.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_source_flow_manager.py#L90-L91

Added lines #L90 - L91 were not covered by tests
self.source, request, self.identifier, {"info": {}}, {}
)
action, connection = flow_manager.get_action()
self.assertEqual(action, Action.AUTH)
self.assertIsNotNone(connection.pk)
response = flow_manager.get_flow()
self.assertEqual(response.status_code, 302)

Check warning on line 98 in authentik/core/tests/test_source_flow_manager.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_source_flow_manager.py#L94-L98

Added lines #L94 - L98 were not covered by tests

def test_unauthenticated_link(self):
"""Test un-authenticated user linking"""
flow_manager = OAuthSourceFlowManager(
Expand Down
Loading