mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-07 17:04:34 +01:00
Complete OpenID provider tests
This commit is contained in:
parent
922902c934
commit
306ff57616
@ -14,15 +14,15 @@ class OpenIdProviderStub extends OpenId
|
||||
*/
|
||||
public $http;
|
||||
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase('http://auth.url', $state);
|
||||
}
|
||||
// protected function getAuthUrl($state)
|
||||
// {
|
||||
// return $this->buildAuthUrlFromBase('http://auth.url', $state);
|
||||
// }
|
||||
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'http://token.url';
|
||||
}
|
||||
// protected function getTokenUrl()
|
||||
// {
|
||||
// return 'http://token.url';
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the access token response for the given code.
|
||||
|
@ -5,10 +5,12 @@
|
||||
use App\Providers\Socialite\OpenId;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Socialite\Two\Token;
|
||||
use Laravel\Socialite\Two\User;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use SocialiteProviders\Manager\Helpers\ConfigRetriever;
|
||||
use stdClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -77,4 +79,52 @@ public function test_it_can_map_a_user_from_an_access_token_with_missing_fields(
|
||||
$this->assertSame(null, $user->email_verified);
|
||||
$this->assertSame(null, $user->groups);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_it_fetches_token_url_from_config()
|
||||
{
|
||||
$tokenUrl = 'http://token.url';
|
||||
config(['services.openid.token_url' => $tokenUrl]);
|
||||
$request = Request::create('/');
|
||||
|
||||
$provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
|
||||
$provider->http = Mockery::mock(stdClass::class);
|
||||
|
||||
$config = (new ConfigRetriever)->fromServices('openid', $provider->additionalConfigKeys());
|
||||
$provider->setConfig($config);
|
||||
|
||||
$provider->http->expects('post')->with($tokenUrl, [
|
||||
RequestOptions::HEADERS => ['Accept' => 'application/json'],
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => 'refresh_token',
|
||||
'client_id' => null,
|
||||
'client_secret' => null,
|
||||
],
|
||||
])->andReturns($response = Mockery::mock(stdClass::class));
|
||||
|
||||
$response->expects('getBody')->andReturns('{ "access_token" : "access_token", "refresh_token" : "refresh_token", "expires_in" : 3600, "scope" : "scope1,scope2" }');
|
||||
$token = $provider->refreshToken('refresh_token');
|
||||
|
||||
$this->assertInstanceOf(Token::class, $token);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function test_it_redirects_to_url_from_config()
|
||||
{
|
||||
$authUrl = 'http://auth.url';
|
||||
config(['services.openid.authorize_url' => $authUrl]);
|
||||
$request = Request::create('/');
|
||||
|
||||
$provider = new OpenIdProviderStub($request, 'client_id', 'client_secret', 'redirect_uri');
|
||||
$provider->http = Mockery::mock(stdClass::class);
|
||||
$provider->stateless();
|
||||
|
||||
$config = (new ConfigRetriever)->fromServices('openid', $provider->additionalConfigKeys());
|
||||
$provider->setConfig($config);
|
||||
|
||||
$response = $provider->redirect();
|
||||
|
||||
$this->assertStringStartsWith($authUrl, $response->getTargetUrl());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user