public function RefreshFunctionalTest::testInvalidRefreshGrant in Simple OAuth (OAuth2) & OpenID Connect 8.4
Same name and namespace in other branches
- 5.x tests/src/Functional/RefreshFunctionalTest.php \Drupal\Tests\simple_oauth\Functional\RefreshFunctionalTest::testInvalidRefreshGrant()
Test invalid Refresh grant.
File
- tests/
src/ Functional/ RefreshFunctionalTest.php, line 129
Class
- RefreshFunctionalTest
- The refresh tests.
Namespace
Drupal\Tests\simple_oauth\FunctionalCode
public function testInvalidRefreshGrant() {
$valid_payload = [
'grant_type' => 'refresh_token',
'client_id' => $this->client
->uuid(),
'client_secret' => $this->clientSecret,
'refresh_token' => $this->refreshToken,
'scope' => $this->scope,
];
$data = [
'grant_type' => [
'error' => 'invalid_grant',
'code' => 400,
],
'client_id' => [
'error' => 'invalid_client',
'code' => 401,
],
'client_secret' => [
'error' => 'invalid_client',
'code' => 401,
],
'refresh_token' => [
'error' => 'invalid_request',
'code' => 401,
],
];
foreach ($data as $key => $value) {
$invalid_payload = $valid_payload;
$invalid_payload[$key] = $this
->getRandomGenerator()
->string();
$response = $this
->post($this->url, $invalid_payload);
$parsed_response = Json::decode((string) $response
->getBody());
$this
->assertSame($value['error'], $parsed_response['error'], sprintf('Correct error code %s for %s.', $value['error'], $key));
$this
->assertSame($value['code'], $response
->getStatusCode(), sprintf('Correct status code %d for %s.', $value['code'], $key));
}
}