Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
ISSUE #255 Scope test api request to current zone
Browse files Browse the repository at this point in the history
  • Loading branch information
manatarms committed Sep 23, 2020
1 parent 733042d commit 99c33a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/API/AbstractPluginActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ public function login()
return $this->api->createAPIError('Unable to save user credentials');
}

$params = array();
// Only Wordpress gives us access to the zone name, so check for it here
if ($this->integrationAPI instanceof \CF\WordPress\WordPressAPI) {
$params = array('name' => $this->integrationAPI->getOriginalDomain());
}

//Make a test request to see if the API Key, email are valid
$testRequest = new Request('GET', 'zones/', array(), array());
$testRequest = new Request('GET', 'zones/', $params, array());
$testResponse = $this->clientAPI->callAPI($testRequest);

if (!$this->clientAPI->responseOk($testResponse)) {
//remove bad credentials
$this->dataStore->createUserDataStore(null, null, null, null);
Expand Down
9 changes: 8 additions & 1 deletion src/Test/API/AbstractPluginActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public function setup()
$this->mockAbstractPluginActions = $this->getMockBuilder('CF\API\AbstractPluginActions')
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->mockAbstractPluginActions->setRequest($this->mockRequest);
$this->mockDefaultIntegration = $this->getMockBuilder('\CF\Integration\DefaultIntegration')
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->mockAbstractPluginActions->setAPI($this->mockAPIClient);
$this->mockAbstractPluginActions->setClientAPI($this->mockClientAPI);
$this->mockAbstractPluginActions->setDataStore($this->mockDataStore);
$this->mockAbstractPluginActions->setLogger($this->mockLogger);
$this->mockAbstractPluginActions->setRequest($this->mockRequest);
}

public function testPostAccountSaveAPICredentialsReturnsErrorIfMissingApiKey()
Expand All @@ -47,6 +50,7 @@ public function testPostAccountSaveAPICredentialsReturnsErrorIfMissingApiKey()
'email' => 'email',
));
$this->mockAPIClient->method('createAPIError')->willReturn(array('success' => false));
$this->mockDefaultIntegration->method('getOriginalDomain')->willReturn('name.com');

$response = $this->mockAbstractPluginActions->login();

Expand All @@ -59,6 +63,7 @@ public function testPostAccountSaveAPICredentialsReturnsErrorIfMissingEmail()
'apiKey' => 'apiKey',
));
$this->mockAPIClient->method('createAPIError')->willReturn(array('success' => false));
$this->mockDefaultIntegration->method('getOriginalDomain')->willReturn('name.com');

$response = $this->mockAbstractPluginActions->login();

Expand Down Expand Up @@ -130,6 +135,8 @@ public function testLoginReturnsErrorIfAPIKeyOrEmailAreInvalid()
));
$this->mockDataStore->method('createUserDataStore')->willReturn(true);
$this->mockClientAPI->method('responseOk')->willReturn(false);
$this->mockDefaultIntegration->method('getOriginalDomain')->willReturn('name.com');

$this->mockAPIClient->expects($this->once())->method('createAPIError');
$this->mockAbstractPluginActions->login();
}
Expand Down

0 comments on commit 99c33a7

Please sign in to comment.