forked from nextcloud/user_saml
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(login): fall through to normal login when no IdP is configured #2
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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec578ca
fix(login): fall through to normal login when no IdP is configured
matsaur 3fe80b0
Update lib/SAMLSettings.php
matsaur ca0ee07
Update lib/AppInfo/Application.php
matsaur 6c8ed9c
test(saml-settings): add unit tests for getListOfConfiguredIdps()
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\User_SAML\Tests; | ||
|
|
||
| use OCA\User_SAML\Db\ConfigurationsMapper; | ||
| use OCA\User_SAML\SAMLSettings; | ||
| use OCP\IConfig; | ||
| use OCP\ISession; | ||
| use OCP\IURLGenerator; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Test\TestCase; | ||
|
|
||
| class SAMLSettingsTest extends TestCase { | ||
| private IURLGenerator&MockObject $urlGenerator; | ||
| private IConfig&MockObject $config; | ||
| private ISession&MockObject $session; | ||
| private ConfigurationsMapper&MockObject $mapper; | ||
| private SAMLSettings $samlSettings; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->urlGenerator = $this->createMock(IURLGenerator::class); | ||
| $this->config = $this->createMock(IConfig::class); | ||
| $this->session = $this->createMock(ISession::class); | ||
| $this->mapper = $this->createMock(ConfigurationsMapper::class); | ||
|
|
||
| $this->samlSettings = new SAMLSettings( | ||
| $this->urlGenerator, | ||
| $this->config, | ||
| $this->session, | ||
| $this->mapper, | ||
| ); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsReturnsEmptyWhenNoIdpsExist(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([], $result); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsReturnsEmptyWhenEntityIdAndSsoUrlMissing(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([ | ||
| 1 => [ | ||
| 'general-idp0_display_name' => 'My IdP', | ||
| // no idp-entityId, no idp-singleSignOnService.url | ||
| ], | ||
| ]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([], $result); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsReturnsEmptyWhenValuesAreOnlyWhitespace(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([ | ||
| 1 => [ | ||
| 'general-idp0_display_name' => 'My IdP', | ||
| 'idp-entityId' => ' ', | ||
| 'idp-singleSignOnService.url' => "\t", | ||
| ], | ||
| ]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([], $result); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsReturnsIdpWhenFullyConfigured(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([ | ||
| 1 => [ | ||
| 'general-idp0_display_name' => 'My IdP', | ||
| 'idp-entityId' => 'https://idp.example.com', | ||
| 'idp-singleSignOnService.url' => 'https://idp.example.com/sso', | ||
| ], | ||
| ]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([1 => 'My IdP'], $result); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsFiltersOutPartiallyConfiguredIdps(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([ | ||
| 1 => [ | ||
| 'general-idp0_display_name' => 'Configured IdP', | ||
| 'idp-entityId' => 'https://idp.example.com', | ||
| 'idp-singleSignOnService.url' => 'https://idp.example.com/sso', | ||
| ], | ||
| 2 => [ | ||
| 'general-idp0_display_name' => 'Missing SSO URL', | ||
| 'idp-entityId' => 'https://idp2.example.com', | ||
| // missing idp-singleSignOnService.url | ||
| ], | ||
| 3 => [ | ||
| 'general-idp0_display_name' => 'Missing Entity ID', | ||
| // missing idp-entityId | ||
| 'idp-singleSignOnService.url' => 'https://idp3.example.com/sso', | ||
| ], | ||
| ]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([1 => 'Configured IdP'], $result); | ||
| } | ||
|
|
||
| public function testGetListOfConfiguredIdpsUsesDisplayNameAsValue(): void { | ||
| $this->mapper->expects($this->once()) | ||
| ->method('getAll') | ||
| ->willReturn([ | ||
| 1 => [ | ||
| 'idp-entityId' => 'https://idp.example.com', | ||
| 'idp-singleSignOnService.url' => 'https://idp.example.com/sso', | ||
| // no display name set | ||
| ], | ||
| ]); | ||
|
|
||
| $result = $this->samlSettings->getListOfConfiguredIdps(); | ||
|
|
||
| $this->assertSame([1 => ''], $result); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new login-flow behavior (falling through to core login when SAML is enabled but no IdP is minimally configured) is security/availability sensitive and currently isn’t covered by automated tests. Please add a unit/integration test that asserts
/loginis redirected to the SAML endpoint when an IdP is configured, and is not redirected when no IdP has entityId+SSO URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unit tests for
SAMLSettings::getListOfConfiguredIdps()intests/unit/SAMLSettingsTest.php(commit6c8ed9c). The tests cover:idp-entityId+idp-singleSignOnService.url→ returned (SAML redirect applies)Since
Application::boot()usesheader()+exit()which can't be unit-tested in isolation, the tests are placed ongetListOfConfiguredIdps()— the method that drives the redirect decision.