-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct issue with GoogleProvider getUserByToken() method (#689)
* fix(google provider): check if response body of GoogleProvider's getUserByToken method is a GuzzleHttp\Psr7\Stream instance * feat(google provider): add test for GoogleProvider's getUserByToken method last change --------- Co-authored-by: Axel Libori Roch <[email protected]>
- Loading branch information
1 parent
d2a8113
commit ffeeb2c
Showing
2 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Laravel\Socialite\Tests; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\RequestOptions; | ||
use Illuminate\Http\Request; | ||
use Laravel\Socialite\Tests\Fixtures\GoogleTestProviderStub; | ||
use Laravel\Socialite\Two\User; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
class GoogleProviderTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
m::close(); | ||
} | ||
|
||
public function test_it_can_map_a_user_from_an_access_token() | ||
{ | ||
$request = Request::create('/'); | ||
|
||
$provider = new GoogleTestProviderStub($request, 'client_id', 'client_secret', 'redirect_uri'); | ||
|
||
$provider->http = m::mock(Client::class); | ||
|
||
$provider->http->allows('get')->with('https://www.googleapis.com/oauth2/v3/userinfo', [ | ||
RequestOptions::QUERY => [ | ||
'prettyPrint' => 'false', | ||
], | ||
RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer fake-token', | ||
], | ||
])->andReturns($response = m::mock(ResponseInterface::class)); | ||
|
||
$response->allows('getBody')->andReturns(m::mock(StreamInterface::class)); | ||
|
||
$user = $provider->userFromToken('fake-token'); | ||
|
||
$this->assertInstanceOf(User::class, $user); | ||
} | ||
} |