|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the HWIOAuthBundle package. |
| 5 | + * |
| 6 | + * (c) Hardware Info <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace HWI\Bundle\OAuthBundle\Tests\OAuth\ResourceOwner; |
| 13 | + |
| 14 | +use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\LinkedinOpenIdResourceOwner; |
| 15 | +use HWI\Bundle\OAuthBundle\OAuth\Response\AbstractUserResponse; |
| 16 | +use HWI\Bundle\OAuthBundle\Test\Fixtures\CustomUserResponse; |
| 17 | +use HWI\Bundle\OAuthBundle\Test\OAuth\ResourceOwner\GenericOAuth2ResourceOwnerTestCase; |
| 18 | + |
| 19 | +final class LinkedinOpenIdResourceOwnerTest extends GenericOAuth2ResourceOwnerTestCase |
| 20 | +{ |
| 21 | + protected string $resourceOwnerClass = LinkedinOpenIdResourceOwner::class; |
| 22 | + protected string $userResponse = <<<json |
| 23 | +{ |
| 24 | + "sub": "CM9X5BxxK8", |
| 25 | + "email_verified": true, |
| 26 | + "name": "John Smith", |
| 27 | + "locale": { |
| 28 | + "country": "US", |
| 29 | + "language": "en" |
| 30 | + }, |
| 31 | + "given_name": "John", |
| 32 | + "family_name": "Smith", |
| 33 | + |
| 34 | + "picture": "https://website.com/picture.jpg" |
| 35 | +} |
| 36 | +json; |
| 37 | + protected array $paths = [ |
| 38 | + 'identifier' => 'sub', |
| 39 | + 'nickname' => 'email', |
| 40 | + 'firstname' => 'given_name', |
| 41 | + 'lastname' => 'family_name', |
| 42 | + 'email' => 'email', |
| 43 | + 'profilepicture' => 'picture', |
| 44 | + ]; |
| 45 | + protected bool $csrf = true; |
| 46 | + |
| 47 | + protected string $authorizationUrlBasePart = 'http://user.auth/?test=2&response_type=code&client_id=clientid&scope=openid+profile+email'; |
| 48 | + |
| 49 | + protected int $httpClientCalls = 1; |
| 50 | + |
| 51 | + public function testCustomResponseClass(): void |
| 52 | + { |
| 53 | + $class = CustomUserResponse::class; |
| 54 | + |
| 55 | + $resourceOwner = $this->createResourceOwner( |
| 56 | + ['user_response_class' => $class], |
| 57 | + [], |
| 58 | + [ |
| 59 | + $this->createMockResponse($this->userResponse, 'application/json; charset=utf-8'), |
| 60 | + $this->createMockResponse($this->userResponse, 'application/json; charset=utf-8'), |
| 61 | + ] |
| 62 | + ); |
| 63 | + |
| 64 | + /** @var CustomUserResponse */ |
| 65 | + $userResponse = $resourceOwner->getUserInformation($this->tokenData); |
| 66 | + |
| 67 | + $this->assertInstanceOf($class, $userResponse); |
| 68 | + $this->assertEquals('foo666', $userResponse->getUserIdentifier()); |
| 69 | + $this->assertEquals('foo', $userResponse->getNickname()); |
| 70 | + $this->assertEquals('token', $userResponse->getAccessToken()); |
| 71 | + $this->assertNull($userResponse->getRefreshToken()); |
| 72 | + $this->assertNull($userResponse->getExpiresIn()); |
| 73 | + } |
| 74 | + |
| 75 | + public function testGetUserInformation(): void |
| 76 | + { |
| 77 | + $resourceOwner = $this->createResourceOwner( |
| 78 | + [], |
| 79 | + [], |
| 80 | + [ |
| 81 | + $this->createMockResponse($this->userResponse, 'application/json; charset=utf-8'), |
| 82 | + $this->createMockResponse($this->userResponse, 'application/json; charset=utf-8'), |
| 83 | + ] |
| 84 | + ); |
| 85 | + |
| 86 | + /** @var AbstractUserResponse $userResponse */ |
| 87 | + $userResponse = $resourceOwner->getUserInformation($this->tokenData); |
| 88 | + |
| 89 | + $this->assertEquals('CM9X5BxxK8', $userResponse->getUserIdentifier()); |
| 90 | + $this-> assertEquals( '[email protected]', $userResponse-> getNickname()); |
| 91 | + $this->assertEquals('John', $userResponse->getFirstName()); |
| 92 | + $this->assertEquals('Smith', $userResponse->getLastName()); |
| 93 | + $this->assertEquals('token', $userResponse->getAccessToken()); |
| 94 | + $this->assertNull($userResponse->getRefreshToken()); |
| 95 | + $this->assertNull($userResponse->getExpiresIn()); |
| 96 | + } |
| 97 | +} |
0 commit comments