-
Notifications
You must be signed in to change notification settings - Fork 284
N°8543 #835
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
Open
jf-cbd
wants to merge
23
commits into
support/3.2
Choose a base branch
from
issue/8543
base: support/3.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
N°8543 #835
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
685373c
Set GetModuleInfo public so it can be called from outside
jf-cbd 2067940
WIP
jf-cbd 38d725c
WIP
jf-cbd 6780543
WIP
jf-cbd 6f5eb69
WIP
jf-cbd 06be85e
WIP
jf-cbd fea51d7
Update test
jf-cbd a02db83
WIP
jf-cbd 69006c1
WIP
jf-cbd b813887
WIP
jf-cbd f5077f3
Update tests/php-unit-tests/integration-tests/login-tests/extension-w…
jf-cbd 3c52e06
WIP
jf-cbd 1b71932
Merge remote-tracking branch 'origin/issue/8543' into issue/8543
jf-cbd 8b4de6a
Add conf persistence
jf-cbd a68b165
Remove unecessary case
jf-cbd ebc238a
Do not require startup when not necessary + refacto
jf-cbd 5a87a50
WIP
jf-cbd a877acb
Rephrase log message
jf-cbd 5a82268
Log when debugging only, to avoid flooding
jf-cbd 9d554d2
Change param to avoid non-changeable value when upgrading iTop
jf-cbd 4cb3a5c
Better naming
jf-cbd c8f5ec4
Exclude specific itop modules from being executed through exec.php
jf-cbd 5d75842
Removed MetaModel to write in conf file
jf-cbd 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
177 changes: 177 additions & 0 deletions
177
tests/php-unit-tests/integration-tests/login-tests/LoginWebPageTest.php
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,177 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Combodo\iTop\Test\UnitTest\Application; | ||
|
|
||
| use Combodo\iTop\Test\UnitTest\ItopDataTestCase; | ||
| use Config; | ||
| use Exception; | ||
| use MetaModel; | ||
|
|
||
| class LoginWebPageTest extends ItopDataTestCase | ||
| { | ||
| public const USE_TRANSACTION = false; | ||
|
|
||
| public const PASSWORD = 'a209320P!ù;ralùqpi,pàcqi"nr'; | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $sConfigPath = MetaModel::GetConfig()->GetLoadedFile(); | ||
| $this->oConfig = new Config($sConfigPath); | ||
|
|
||
| $this->BackupConfiguration(); | ||
| $sFolderPath = APPROOT.'env-production/extension-with-delegated-authentication-endpoints-list'; | ||
| if (file_exists($sFolderPath)) { | ||
| throw new Exception("Folder $sFolderPath already exists, please remove it before running the test"); | ||
| } | ||
| mkdir($sFolderPath); | ||
| $this->RecurseCopy(__DIR__.'/extension-with-delegated-authentication-endpoints-list', $sFolderPath); | ||
|
|
||
| $sFolderPath = APPROOT.'env-production/extension-without-delegated-authentication-endpoints-list'; | ||
| if (file_exists($sFolderPath)) { | ||
| throw new Exception("Folder $sFolderPath already exists, please remove it before running the test"); | ||
| } | ||
| mkdir($sFolderPath); | ||
| $this->RecurseCopy(__DIR__.'/extension-without-delegated-authentication-endpoints-list', $sFolderPath); | ||
| } | ||
| public function tearDown(): void | ||
| { | ||
| parent::tearDown(); | ||
| $sFolderPath = APPROOT.'env-production/extension-with-delegated-authentication-endpoints-list'; | ||
| if (file_exists($sFolderPath)) { | ||
| $this->RecurseRmdir($sFolderPath); | ||
| } else { | ||
| throw new Exception("Folder $sFolderPath does not exist, it should have been created in setUp"); | ||
| } | ||
| $sFolderPath = APPROOT.'env-production/extension-without-delegated-authentication-endpoints-list'; | ||
| if (file_exists($sFolderPath)) { | ||
| $this->RecurseRmdir($sFolderPath); | ||
| } else { | ||
| throw new Exception("Folder $sFolderPath does not exist, it should have been created in setUp"); | ||
| } | ||
| } | ||
|
|
||
| protected function GivenConfigFileAllowedLoginTypes($aAllowedLoginTypes): void | ||
| { | ||
| @chmod($this->oConfig->GetLoadedFile(), 0770); | ||
| $this->oConfig->SetAllowedLoginTypes($aAllowedLoginTypes); | ||
| $this->oConfig->WriteToFile($this->oConfig->GetLoadedFile()); | ||
| @chmod($this->oConfig->GetLoadedFile(), 0444); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function testInDelegatedAuthenticationEndpoints() | ||
| { | ||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-with-delegated-authentication-endpoints-list&exec_page=src/Controller/FileInDelegatedAuthenticationEndpointsList.php", | ||
| [], | ||
| [], | ||
| true | ||
| ); | ||
|
|
||
| $this->assertStringNotContainsString('<title>iTop login</title>', $sPageContent, 'File listed in delegated authentication endpoints list (in the module), login should not be requested by exec.'); | ||
| } | ||
|
|
||
| public function testUserCanAccessAnyFile() | ||
| { | ||
| // generate random login | ||
| $sUserLogin = 'user-'.date('YmdHis'); | ||
| $this->CreateUser($sUserLogin, self::$aURP_Profiles['Service Desk Agent'], self::PASSWORD); | ||
| $this->GivenConfigFileAllowedLoginTypes(explode('|', 'form')); | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-with-delegated-authentication-endpoints-list&exec_page=src/Controller/FileNotInDelegatedAuthenticationEndpointsList.php", | ||
| [ | ||
| 'auth_user' => $sUserLogin, | ||
| 'auth_pwd' => self::PASSWORD, | ||
| ], | ||
| [], | ||
| true | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('Yo', $sPageContent, 'Logged in user should access any file via exec.php even if the page isn\'t listed in delegated authentication endpoints list'); | ||
| } | ||
|
|
||
| public function testWithoutDelegatedAuthenticationEndpointsListWithForceLoginConf() | ||
| { | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @chmod($this->oConfig->GetLoadedFile(), 0770); | ||
| $this->oConfig->Set('security.force_login_when_no_delegated_authentication_endpoints_list', true); | ||
| $this->oConfig->WriteToFile(); | ||
| @chmod($this->oConfig->GetLoadedFile(), 0444); | ||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-without-delegated-authentication-endpoints-list&exec_page=src/Controller/File.php", | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('<title>iTop login</title>', $sPageContent, 'if itop is configured to force login when no there is no delegated authentication endpoints list, then login should be required.'); | ||
| } | ||
|
|
||
| public function testWithoutDelegatedAuthenticationEndpointsListWithDefaultConfiguration() | ||
| { | ||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-without-delegated-authentication-endpoints-list&exec_page=src/Controller/File.php", | ||
| [], | ||
| [], | ||
| true | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('Yo', $sPageContent, 'by default (until N°9343) if no delegated authentication endpoints list is defined, not logged in persons should access pages'); | ||
| } | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public function testNotInDelegatedAuthenticationEndpointsList() | ||
| { | ||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-with-delegated-authentication-endpoints-list&exec_page=src/Controller/FileNotInDelegatedAuthenticationEndpointsList.php", | ||
| [], | ||
| [], | ||
| true | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('<title>iTop login</title>', $sPageContent, 'Since an delegated authentication endpoints list is defined and file isn\'t listed in it, login should be required'); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider InDelegatedAuthenticationEndpointsWithAdminRequiredProvider | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function testInDelegatedAuthenticationEndpointsWithAdminRequired($iProfileId, $bShouldSeeForbiddenAdminPage) | ||
| { | ||
| // generate random login | ||
| $sUserLogin = 'user-'.date('YmdHis'); | ||
| $this->CreateUser($sUserLogin, $iProfileId, self::PASSWORD); | ||
| $this->GivenConfigFileAllowedLoginTypes(explode('|', 'form')); | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $sPageContent = $this->CallItopUri( | ||
| "pages/exec.php?exec_module=extension-with-delegated-authentication-endpoints-list&exec_page=src/Controller/FileInDelegatedAuthenticationEndpointsListAndAdminRequired.php", | ||
| [ | ||
| 'auth_user' => $sUserLogin, | ||
| 'auth_pwd' => self::PASSWORD, | ||
| ], | ||
| [], | ||
| true | ||
| ); | ||
| $bShouldSeeForbiddenAdminPage ? | ||
| $this->assertStringContainsString('Access restricted to people having administrator privileges', $sPageContent, 'Should prevent non admin user to access this page') : // in delegated authentication endpoints list (in the module), login should not be required | ||
| $this->assertStringContainsString('Yo !', $sPageContent, 'Should execute the file and see its content since user has admin profile'); | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public function InDelegatedAuthenticationEndpointsWithAdminRequiredProvider() | ||
| { | ||
| return [ | ||
| 'Administrator profile' => [ | ||
| self::$aURP_Profiles['Administrator'], | ||
| 'Should see forbidden admin page' => false, | ||
| ], | ||
| 'ReadOnly profile' => [ | ||
| self::$aURP_Profiles['Service Desk Agent'], | ||
| 'Should see forbidden admin page' => true, | ||
| ], | ||
| ]; | ||
| } | ||
| } | ||
51 changes: 51 additions & 0 deletions
51
...tication-endpoints-list/module.extension-with-delegated-authentication-endpoints-list.php
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,51 @@ | ||
| <?php | ||
|
|
||
| SetupWebPage::AddModule( | ||
| __FILE__, // Path to the current file, all other file names are relative to the directory containing this file | ||
| 'extension-with-delegated-authentication-endpoints-list/0.0.1', | ||
| [ | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Identification | ||
| // | ||
| 'label' => 'Templates foundation', | ||
| 'category' => 'business', | ||
|
|
||
| // Setup | ||
| // | ||
| 'dependencies' => [], | ||
| 'mandatory' => true, | ||
| 'visible' => false, | ||
| 'installer' => 'TemplatesBaseInstaller', | ||
|
|
||
| // Security | ||
| 'delegated_authentication_endpoints' => [ | ||
| 'src/Controller/FileInDelegatedAuthenticationEndpointsList.php', | ||
| 'src/Controller/FileInDelegatedAuthenticationEndpointsListAndAdminRequired.php', | ||
| ], | ||
|
|
||
| // Components | ||
| // | ||
| 'datamodel' => [ | ||
| 'model.templates-base.php', | ||
| ], | ||
| 'webservice' => [], | ||
| 'data.struct' => [// add your 'structure' definition XML files here, | ||
| ], | ||
| 'data.sample' => [// add your sample data XML files here, | ||
| ], | ||
|
|
||
| // Documentation | ||
| // | ||
| 'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any | ||
| 'doc.more_information' => '', // hyperlink to more information, if any | ||
|
|
||
| // Default settings | ||
| // | ||
| 'settings' => [ | ||
| // Select where, in the main UI, the extra data should be displayed: | ||
| // tab (dedicated tab) | ||
| // properties (right after the properties, but before the log if any) | ||
| // none (extra data accessed only by programs) | ||
| 'view_extra_data' => 'relations', | ||
| ], | ||
| ] | ||
| ); | ||
3 changes: 3 additions & 0 deletions
3
...thentication-endpoints-list/src/Controller/FileInDelegatedAuthenticationEndpointsList.php
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,3 @@ | ||
| <?php | ||
|
|
||
| echo 'Yo !'; |
10 changes: 10 additions & 0 deletions
10
...points-list/src/Controller/FileInDelegatedAuthenticationEndpointsListAndAdminRequired.php
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,10 @@ | ||
| <?php | ||
|
|
||
| if (UserRights::IsLoggedIn()) { | ||
| throw new Exception("User should not be authenticated at this point"); | ||
| } | ||
| require_once(APPROOT.'/application/startup.inc.php'); | ||
|
|
||
| LoginWebPage::DoLogin(true); | ||
|
|
||
| echo 'Yo !'; |
3 changes: 3 additions & 0 deletions
3
...ntication-endpoints-list/src/Controller/FileNotInDelegatedAuthenticationEndpointsList.php
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,3 @@ | ||
| <?php | ||
|
|
||
| echo 'Yo !'; |
45 changes: 45 additions & 0 deletions
45
...ation-endpoints-list/module.extension-without-delegated-authentication-endpoints-list.php
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,45 @@ | ||
| <?php | ||
|
|
||
| SetupWebPage::AddModule( | ||
| __FILE__, // Path to the current file, all other file names are relative to the directory containing this file | ||
| 'extension-without-delegated-authentication-endpoints-list/0.0.1', | ||
| [ | ||
jf-cbd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Identification | ||
| // | ||
| 'label' => 'Templates foundation', | ||
| 'category' => 'business', | ||
|
|
||
| // Setup | ||
| // | ||
| 'dependencies' => [], | ||
| 'mandatory' => true, | ||
| 'visible' => false, | ||
| 'installer' => 'TemplatesBaseInstaller', | ||
|
|
||
| // Components | ||
| // | ||
| 'datamodel' => [ | ||
| 'model.templates-base.php', | ||
| ], | ||
| 'webservice' => [], | ||
| 'data.struct' => [// add your 'structure' definition XML files here, | ||
| ], | ||
| 'data.sample' => [// add your sample data XML files here, | ||
| ], | ||
|
|
||
| // Documentation | ||
| // | ||
| 'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any | ||
| 'doc.more_information' => '', // hyperlink to more information, if any | ||
|
|
||
| // Default settings | ||
| // | ||
| 'settings' => [ | ||
| // Select where, in the main UI, the extra data should be displayed: | ||
| // tab (dedicated tab) | ||
| // properties (right after the properties, but before the log if any) | ||
| // none (extra data accessed only by programs) | ||
| 'view_extra_data' => 'relations', | ||
| ], | ||
| ] | ||
| ); | ||
3 changes: 3 additions & 0 deletions
3
...n-tests/extension-without-delegated-authentication-endpoints-list/src/Controller/File.php
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,3 @@ | ||
| <?php | ||
|
|
||
| echo 'Yo !'; |
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.
Uh oh!
There was an error while loading. Please reload this page.