public function StatusReportTest::testInvalidCredentials in Apigee Edge 8
Tests invalid credentials.
File
- tests/
src/ Functional/ StatusReportTest.php, line 52
Class
- StatusReportTest
- Status report test.
Namespace
Drupal\Tests\apigee_edge\FunctionalCode
public function testInvalidCredentials() {
$orgName = $this->sdkConnector
->getOrganization();
$this
->drupalLogin($this->rootUser);
$status_report_path = Url::fromRoute('system.status');
// Ensure that pre-defined credentials are correctly set.
$this->stack
->queueMockResponse([
'org' => [
'org_name' => $orgName,
],
]);
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextNotContains(self::CANNOT_CONNECT_SHORT);
// Delete authentication key.
$this
->invalidateKey();
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextContains(self::KEY_NOT_SET);
$this
->assertSession()
->pageTextContains(self::CANNOT_CONNECT_LONG);
// Set invalid authentication key id.
$this
->setKey('default');
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextContains(self::KEY_NOT_FOUND);
$this
->assertSession()
->pageTextContains(self::CANNOT_CONNECT_LONG);
// Create new Apigee Edge basic auth key with private file provider.
$key = Key::create([
'id' => 'private_file',
'label' => 'Private file',
'key_type' => 'apigee_auth',
'key_provider' => 'apigee_edge_private_file',
'key_input' => 'apigee_auth_input',
]);
$key
->setKeyValue(Json::encode([
'auth_type' => getenv('APIGEE_EDGE_AUTH_TYPE'),
'endpoint' => getenv('APIGEE_EDGE_ENDPOINT'),
'organization' => getenv('APIGEE_EDGE_ORGANIZATION'),
'username' => getenv('APIGEE_EDGE_USERNAME'),
'password' => getenv('APIGEE_EDGE_PASSWORD'),
]));
$key
->save();
$this
->setKey('private_file');
$this->stack
->queueMockResponse([
'org' => [
'org_name' => $orgName,
],
]);
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextNotContains(self::CANNOT_CONNECT_SHORT);
// Use wrong credentials.
$key
->setKeyValue(Json::encode([
'auth_type' => getenv('APIGEE_EDGE_AUTH_TYPE'),
'endpoint' => getenv('APIGEE_EDGE_ENDPOINT'),
'organization' => getenv('APIGEE_EDGE_ORGANIZATION'),
'username' => getenv('APIGEE_EDGE_USERNAME'),
'password' => $this
->getRandomGenerator()
->string(),
]));
$key
->save();
$this->stack
->queueMockResponse([
'get_not_found' => [
'status_code' => 401,
],
]);
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextContains(self::CANNOT_CONNECT_LONG);
// Create new Apigee Edge OAuth key with private file provider.
$key = Key::create([
'id' => 'private_file_oauth',
'label' => 'Private file oauth',
'key_type' => 'apigee_auth',
'key_provider' => 'apigee_edge_private_file',
'key_input' => 'apigee_auth_input',
]);
$key
->setKeyValue(Json::encode([
'auth_type' => EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH,
'endpoint' => getenv('APIGEE_EDGE_ENDPOINT'),
'organization' => getenv('APIGEE_EDGE_ORGANIZATION'),
'username' => getenv('APIGEE_EDGE_USERNAME'),
'password' => getenv('APIGEE_EDGE_PASSWORD'),
]));
$key
->save();
$this
->setKey('private_file_oauth');
$this->stack
->queueMockResponse('access_token');
$this->stack
->queueMockResponse([
'org' => [
'org_name' => $orgName,
],
]);
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextNotContains(self::CANNOT_CONNECT_SHORT);
// Use wrong credentials.
$key
->setKeyValue(Json::encode([
'auth_type' => getenv('APIGEE_EDGE_AUTH_TYPE'),
'endpoint' => getenv('APIGEE_EDGE_ENDPOINT'),
'organization' => $this
->getRandomGenerator()
->name(),
'username' => getenv('APIGEE_EDGE_USERNAME'),
'password' => getenv('APIGEE_EDGE_PASSWORD'),
]));
$key
->save();
$this->stack
->queueMockResponse('get_not_found');
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextContains(self::CANNOT_CONNECT_LONG);
// Unset private file path.
$settings['settings']['file_private_path'] = (object) [
'value' => '',
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->rebuildContainer();
$this
->drupalGet($status_report_path);
$this
->assertSession()
->pageTextContains(self::KEY_MALFORMED);
$this
->assertSession()
->pageTextContains(self::CANNOT_CONNECT_LONG);
}