-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-wmwf-49vv-p3mr
* Fix AuthenticationHandler return inner exception message * Add funcctional test case for AuthenticationHandlerTest * Sync security bundle and sulu skeleton security config * Remove not longer used LoginControllerTest via form_login * Add test for success and fail login
- Loading branch information
1 parent
7c58c06
commit 5f6c98b
Showing
5 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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
29 changes: 0 additions & 29 deletions
29
src/Sulu/Bundle/SecurityBundle/Tests/Functional/Controller/LoginControllerTest.php
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
src/Sulu/Bundle/SecurityBundle/Tests/Functional/Security/AuthenticationHandlerTest.php
This file contains 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,82 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of Sulu. | ||
| * | ||
| * (c) Sulu GmbH | ||
| * | ||
| * This source file is subject to the MIT license that is bundled | ||
| * with this source code in the file LICENSE. | ||
| */ | ||
|
|
||
| namespace Sulu\Bundle\SecurityBundle\Tests\Functional\Security; | ||
|
|
||
| use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
|
|
||
| class AuthenticationHandlerTest extends SuluTestCase | ||
| { | ||
| public function testLoginFail(): void | ||
| { | ||
| $client = $this->createClient([], [ | ||
| 'CONTENT_TYPE' => 'application/json', | ||
| 'HTTP_ACCEPT' => 'application/json', | ||
| 'HTTP_X-Requested-With' => 'XMLHttpRequest', | ||
| ]); | ||
|
|
||
| $client->request('POST', '/admin/login', [], [], [], '{"username": "not-existing-user", "password": "wrong"}'); | ||
|
|
||
| $response = $client->getResponse(); | ||
| $this->assertHttpStatusCode(401, $response); | ||
| $notExistUserContent = $response->getContent(); | ||
|
|
||
| $this->assertSame('{"message":"Invalid credentials."}', $notExistUserContent); | ||
| } | ||
|
|
||
| public function testLoginSuccess(): void | ||
| { | ||
| $client = $this->createClient([], [ | ||
| 'CONTENT_TYPE' => 'application/json', | ||
| 'HTTP_ACCEPT' => 'application/json', | ||
| 'HTTP_X-Requested-With' => 'XMLHttpRequest', | ||
| ]); | ||
|
|
||
| $testUser = $this->getTestUser(); | ||
|
|
||
| $client->request('POST', '/admin/login', [], [], [], '{"username": "' . $testUser->getUsername() . '", "password": "test"}'); | ||
|
|
||
| $response = $client->getResponse(); | ||
| $this->assertHttpStatusCode(200, $response); | ||
| $notExistUserContent = $response->getContent(); | ||
|
|
||
| $this->assertSame( | ||
| '{"url":"\/admin\/","username":"test","completed":true,"twoFactorMethods":["trusted_devices"]}', | ||
| $notExistUserContent | ||
| ); | ||
| } | ||
|
|
||
| public function testLoginFailExistUserHasSameMessageAsNotExist(): void | ||
| { | ||
| $client = $this->createClient([], [ | ||
| 'CONTENT_TYPE' => 'application/json', | ||
| 'HTTP_ACCEPT' => 'application/json', | ||
| 'HTTP_X-Requested-With' => 'XMLHttpRequest', | ||
| ]); | ||
|
|
||
| $testUser = $this->getTestUser(); | ||
|
|
||
| $client->request('POST', '/admin/login', [], [], [], '{"username": "not-existing-user", "password": "wrong"}'); | ||
|
|
||
| $response = $client->getResponse(); | ||
| $this->assertHttpStatusCode(401, $response); | ||
| $notExistUserContent = $response->getContent(); | ||
|
|
||
| $client->request('POST', '/admin/login', [], [], [], '{"username": "' . $testUser->getUsername() . '", "password": "wrong"}'); | ||
|
|
||
| $response = $client->getResponse(); | ||
| $this->assertHttpStatusCode(401, $response); | ||
| $existUserContent = $response->getContent(); | ||
|
|
||
| $this->assertSame($notExistUserContent, $existUserContent); | ||
| $this->assertSame('{"message":"Invalid credentials."}', $notExistUserContent); | ||
| } | ||
| } |