Download tasks/24e526c2de68b636/levels/level3/patch.diff from FuCY/php: direct link, hf CLI and curl.
- Browser
- Download file 7.96 kB
-
https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/24e526c2de68b636/levels/level3/patch.diff
- Command line
-
hf download hf://datasets/FuCY/php/tasks/24e526c2de68b636/levels/level3/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/24e526c2de68b636/levels/level3/patch.diff
7.96 kB
| diff --git a/config/packages/security.yaml b/config/packages/security.yaml | |
| index be39e46f5cc..ae669245ccd 100644 | |
| --- a/config/packages/security.yaml | |
| +++ b/config/packages/security.yaml | |
| security: | |
| - { path: ^/admin/reset, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/security/reset, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/login$, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/2fa, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/_wdt, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/_profiler, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/translations, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin$, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/$, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/p/, roles: PUBLIC_ACCESS } | |
| - - { path: ^/admin/logout, role: PUBLIC_ACCESS } | |
| - - { path: ^/admin/_profiler, role: PUBLIC_ACCESS } | |
| - - { path: ^/admin/2fa, role: PUBLIC_ACCESS } | |
| - { path: ^/admin, roles: ROLE_USER } | |
| firewalls: | |
| diff --git a/src/Sulu/Bundle/SecurityBundle/Security/AuthenticationHandler.php b/src/Sulu/Bundle/SecurityBundle/Security/AuthenticationHandler.php | |
| index 6054a2a4881..8d4efb8f70c 100644 | |
| --- a/src/Sulu/Bundle/SecurityBundle/Security/AuthenticationHandler.php | |
| +++ b/src/Sulu/Bundle/SecurityBundle/Security/AuthenticationHandler.php | |
| public function onAuthenticationFailure(Request $request, AuthenticationExceptio | |
| { | |
| if ($request->isXmlHttpRequest()) { | |
| // if AJAX login | |
| - $array = ['message' => $exception->getMessage()]; | |
| + $array = ['message' => $exception->getMessageKey()]; | |
| $response = new JsonResponse($array, 401); | |
| } else { | |
| // if form login | |
| diff --git a/src/Sulu/Bundle/SecurityBundle/Tests/Application/config/config.yml b/src/Sulu/Bundle/SecurityBundle/Tests/Application/config/config.yml | |
| index a9a3cd20d52..6b9b5efbba4 100644 | |
| --- a/src/Sulu/Bundle/SecurityBundle/Tests/Application/config/config.yml | |
| +++ b/src/Sulu/Bundle/SecurityBundle/Tests/Application/config/config.yml | |
| security: | |
| access_control: | |
| - { path: ^/admin/reset, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin/security/reset, roles: PUBLIC_ACCESS } | |
| - - { path: ^/admin/login, roles: PUBLIC_ACCESS } | |
| - - { path: ^/admin/2fa, role: PUBLIC_ACCESS } | |
| + - { path: ^/admin/login$, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/2fa, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/_wdt, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/_profiler, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/translations, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin$, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/$, roles: PUBLIC_ACCESS } | |
| + - { path: ^/admin/p/, roles: PUBLIC_ACCESS } | |
| - { path: ^/admin, roles: ROLE_USER } | |
| firewalls: | |
| security: | |
| pattern: ^/ | |
| lazy: true | |
| entry_point: sulu_security.authentication_entry_point | |
| - form_login: | |
| + json_login: | |
| check_path: sulu_admin.login_check | |
| success_handler: sulu_security.authentication_handler | |
| failure_handler: sulu_security.authentication_handler | |
| logout: | |
| - path: /admin/logout | |
| - target: /admin/ | |
| + path: sulu_admin.logout | |
| two_factor: | |
| prepare_on_login: true | |
| prepare_on_access_denied: true | |
| diff --git a/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Controller/LoginControllerTest.php b/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Controller/LoginControllerTest.php | |
| deleted file mode 100644 | |
| index dbcfbe26f31..00000000000 | |
| --- a/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Controller/LoginControllerTest.php | |
| +++ /dev/null | |
| -<?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\AdminBundle\Tests\Functional\Controller; | |
| - | |
| -use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | |
| - | |
| -class LoginControllerTest extends SuluTestCase | |
| -{ | |
| - public function testFalseLoginRedirect(): void | |
| - { | |
| - $client = $this->createClient(); | |
| - $client->request('POST', '/admin/login', [ | |
| - '_username' => 'FalseUser', | |
| - '_password' => 'FalsePassword', | |
| - ]); | |
| - $response = $client->getResponse(); | |
| - $this->assertHttpStatusCode(302, $response); | |
| - $this->assertSame('/admin/', $response->getTargetUrl()); | |
| - } | |
| -} | |
| diff --git a/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Security/AuthenticationHandlerTest.php b/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Security/AuthenticationHandlerTest.php | |
| new file mode 100644 | |
| index 00000000000..5d3f3598571 | |
| --- /dev/null | |
| +++ b/src/Sulu/Bundle/SecurityBundle/Tests/Functional/Security/AuthenticationHandlerTest.php | |
| +<?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); | |
| + } | |
| +} | |