You are here

public function RefreshFunctionalTest::testMissingRefreshGrant in Simple OAuth (OAuth2) & OpenID Connect 8.2

Same name and namespace in other branches
  1. 8.3 simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php \Drupal\Tests\simple_oauth_extras\Functional\RefreshFunctionalTest::testMissingRefreshGrant()

Test invalid Refresh grant.

File

simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php, line 98

Class

RefreshFunctionalTest
@group simple_oauth_extras

Namespace

Drupal\Tests\simple_oauth_extras\Functional

Code

public function testMissingRefreshGrant() {
  $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_request',
      'code' => 400,
    ],
    'client_secret' => [
      'error' => 'invalid_client',
      'code' => 401,
    ],
    'refresh_token' => [
      'error' => 'invalid_request',
      'code' => 400,
    ],
  ];
  foreach ($data as $key => $value) {
    $invalid_payload = $valid_payload;
    unset($invalid_payload[$key]);
    $response = $this
      ->request('POST', $this->url, [
      'form_params' => $invalid_payload,
    ]);
    $parsed_response = Json::decode($response
      ->getBody()
      ->getContents());
    $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));
  }
}