From 2114ac90483f83f2f02704f0fa07e28514ec0c51 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Mon, 10 Jan 2022 15:28:51 +0100 Subject: [PATCH] add custom resource owner service to functional tests --- .../App/ResourceOwner/CustomResourceOwner.php | 18 ++++++++++++++++++ tests/App/config/config.yaml | 15 +++++++++++++++ tests/App/config/routing.yaml | 3 +++ tests/App/config/security_v4.yaml | 1 + tests/App/config/security_v5.yaml | 1 + tests/App/config/security_v5_bc.yaml | 1 + tests/App/config/security_v6.yaml | 1 + .../Controller/LoginControllerTest.php | 4 +++- 8 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/App/ResourceOwner/CustomResourceOwner.php diff --git a/tests/App/ResourceOwner/CustomResourceOwner.php b/tests/App/ResourceOwner/CustomResourceOwner.php new file mode 100644 index 000000000..102b4ed62 --- /dev/null +++ b/tests/App/ResourceOwner/CustomResourceOwner.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace HWI\Bundle\OAuthBundle\Tests\App\ResourceOwner; + +use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\GenericOAuth2ResourceOwner; + +class CustomResourceOwner extends GenericOAuth2ResourceOwner +{ +} diff --git a/tests/App/config/config.yaml b/tests/App/config/config.yaml index 7952d177e..938461fc2 100644 --- a/tests/App/config/config.yaml +++ b/tests/App/config/config.yaml @@ -34,6 +34,19 @@ services: class: Symfony\Contracts\HttpClient\HttpClientInterface public: true + app.custom_resource_owner: + class: HWI\Bundle\OAuthBundle\Tests\App\ResourceOwner\CustomResourceOwner + arguments: + $options: { + access_token_url: 'http://custom/token', + authorization_url: 'http://custom/auth', + infos_url: 'http://custom/info', + client_id: 'client_id', + client_secret: 'client_secret', + } + $name: 'custom' + $storage: '@hwi_oauth.storage.session' + doctrine: dbal: driver: pdo_sqlite @@ -61,6 +74,8 @@ hwi_oauth: scope: 'scope=mail-r sdct-r' options: refresh_on_expire: true + custom: + service: 'app.custom_resource_owner' twig: strict_variables: '%kernel.debug%' diff --git a/tests/App/config/routing.yaml b/tests/App/config/routing.yaml index 21cf03993..a944c1aa0 100644 --- a/tests/App/config/routing.yaml +++ b/tests/App/config/routing.yaml @@ -27,3 +27,6 @@ google_login: yahoo_login: path: /check-login/yahoo + +custom_login: + path: /check-login/custom diff --git a/tests/App/config/security_v4.yaml b/tests/App/config/security_v4.yaml index ed6be36ab..31989da5d 100644 --- a/tests/App/config/security_v4.yaml +++ b/tests/App/config/security_v4.yaml @@ -18,6 +18,7 @@ security: resource_owners: google: '/check-login/google' yahoo: '/check-login/yahoo' + custom: '/check-login/custom' login_path: /login use_forward: false failure_path: /login diff --git a/tests/App/config/security_v5.yaml b/tests/App/config/security_v5.yaml index 70ddea655..15e35a5a4 100644 --- a/tests/App/config/security_v5.yaml +++ b/tests/App/config/security_v5.yaml @@ -16,6 +16,7 @@ security: resource_owners: google: '/check-login/google' yahoo: '/check-login/yahoo' + custom: '/check-login/custom' login_path: /login use_forward: false failure_path: /login diff --git a/tests/App/config/security_v5_bc.yaml b/tests/App/config/security_v5_bc.yaml index 9bcad1fa1..c80b09880 100644 --- a/tests/App/config/security_v5_bc.yaml +++ b/tests/App/config/security_v5_bc.yaml @@ -20,6 +20,7 @@ security: resource_owners: google: '/check-login/google' yahoo: '/check-login/yahoo' + custom: '/check-login/custom' login_path: /login use_forward: false failure_path: /login diff --git a/tests/App/config/security_v6.yaml b/tests/App/config/security_v6.yaml index 068f0fd96..94a47bebe 100644 --- a/tests/App/config/security_v6.yaml +++ b/tests/App/config/security_v6.yaml @@ -16,6 +16,7 @@ security: resource_owners: google: '/check-login/google' yahoo: '/check-login/yahoo' + custom: '/check-login/custom' login_path: /login use_forward: false failure_path: /login diff --git a/tests/Functional/Controller/LoginControllerTest.php b/tests/Functional/Controller/LoginControllerTest.php index 8a0d5ca6b..cdab62af3 100644 --- a/tests/Functional/Controller/LoginControllerTest.php +++ b/tests/Functional/Controller/LoginControllerTest.php @@ -36,7 +36,9 @@ public function testLoginPage(): void $response = $client->getResponse(); $this->assertSame(200, $response->getStatusCode(), $response->getContent()); - $this->assertSame('google', $crawler->filter('a')->text(), $response->getContent()); + $this->assertSame('google', $crawler->filter('a:nth-child(1)')->text(), $response->getContent()); + $this->assertSame('yahoo', $crawler->filter('a:nth-child(3)')->text(), $response->getContent()); + $this->assertSame('custom', $crawler->filter('a:nth-child(5)')->text(), $response->getContent()); } public function testRedirectingToRegistrationFormWithError(): void