public function ConsumerClientIdTest::testInvalidClientId in farmOS 2.x
Test invalid Password grant using the consumer.client_id field.
File
- modules/
core/ api/ tests/ src/ Functional/ ConsumerClientIdTest.php, line 69
Class
- ConsumerClientIdTest
- Tests using the consumer.client_id field.
Namespace
Drupal\Tests\farm_api\FunctionalCode
public function testInvalidClientId() {
// Build a valid payload.
$valid_payload = [
'grant_type' => 'password',
'client_id' => $this->client
->get('client_id')->value,
'username' => $this->user
->getAccountName(),
'password' => $this->user->pass_raw,
'scope' => $this->scope,
];
// 1. Test an incorrect client_id.
$invalid_payload = $valid_payload;
$invalid_payload['client_id'] = $this
->getRandomGenerator()
->string();
$response = $this
->post($this->url, $invalid_payload);
$parsed_response = Json::decode((string) $response
->getBody());
$this
->assertSame('invalid_client', $parsed_response['error']);
$this
->assertSame(401, $response
->getStatusCode());
// 2. Test a missing client_id.
$invalid_payload = $valid_payload;
unset($invalid_payload['client_id']);
$response = $this
->post($this->url, $invalid_payload);
$parsed_response = Json::decode((string) $response
->getBody());
$this
->assertSame('invalid_request', $parsed_response['error']);
$this
->assertSame(400, $response
->getStatusCode());
}