You are here

public function OAuth2ServerStorageTest::testCheckClientCredentials in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/OAuth2ServerStorageTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerStorageTest::testCheckClientCredentials()

Check client credentials.

File

tests/src/Functional/OAuth2ServerStorageTest.php, line 105

Class

OAuth2ServerStorageTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

public function testCheckClientCredentials() {

  // Nonexistent client_id.
  $result = $this->storage
    ->checkClientCredentials('fakeclient', 'testpass');
  $this
    ->assertFalse($result, 'Invalid client credentials correctly detected.');

  // Invalid client_secret.
  $result = $this->storage
    ->checkClientCredentials($this->clientId, 'invalidcredentials');
  $this
    ->assertFalse($result, 'Invalid client_secret correctly detected.');

  // Valid credentials.
  $result = $this->storage
    ->checkClientCredentials($this->clientId, $this->clientSecret);
  $this
    ->assertTrue($result, 'Valid client credentials correctly detected.');

  // No client secret.
  $result = $this->storage
    ->checkClientCredentials($this->clientId, '');
  $this
    ->assertFalse($result, 'Empty client secret not accepted.');

  // Allow empty client secret, try again.
  $this->client->client_secret = '';
  $this->client
    ->save();
  $result = $this->storage
    ->checkClientCredentials($this->clientId, '');
  $this
    ->assertTrue($result, 'Empty client secret accepted if none required.');

  // Try again with a NULL client secret. This should be accepted too.
  $result = $this->storage
    ->checkClientCredentials($this->clientId, NULL);
  $this
    ->assertTrue($result, 'Null client secret accepted if none required.');
}