Merge remote-tracking branch 'upstream/master'
This commit is contained in:
25
src/Auth/APIToken.php
Normal file
25
src/Auth/APIToken.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* User: czPechy
|
||||||
|
* Date: 30/07/2018
|
||||||
|
* Time: 22:42
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
class APIToken implements Auth
|
||||||
|
{
|
||||||
|
private $apiToken;
|
||||||
|
|
||||||
|
public function __construct(string $apiToken)
|
||||||
|
{
|
||||||
|
$this->apiToken = $apiToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeaders(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Authorization' => 'Bearer ' . $this->apiToken
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/Configurations/FirewallRuleOptions.php
Normal file
46
src/Configurations/FirewallRuleOptions.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class FirewallRuleOptions implements Configurations
|
||||||
|
{
|
||||||
|
protected $configs = [
|
||||||
|
'paused' => false,
|
||||||
|
'action' => 'block'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPaused(bool $paused)
|
||||||
|
{
|
||||||
|
$this->configs['paused'] = $paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionBlock()
|
||||||
|
{
|
||||||
|
$this->configs['action'] = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionAllow()
|
||||||
|
{
|
||||||
|
$this->configs['action'] = 'allow';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionChallenge()
|
||||||
|
{
|
||||||
|
$this->configs['action'] = 'challenge';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionJsChallenge()
|
||||||
|
{
|
||||||
|
$this->configs['action'] = 'js_challenge';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionLog()
|
||||||
|
{
|
||||||
|
$this->configs['action'] = 'log';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,13 @@ class PageRulesActions implements Configurations
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setOriginCacheControl(bool $active)
|
||||||
|
{
|
||||||
|
$this->addConfigurationOption('explicit_cache_control', [
|
||||||
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function setBrowserIntegrityCheck(bool $active)
|
public function setBrowserIntegrityCheck(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption('browser_check', [
|
$this->addConfigurationOption('browser_check', [
|
||||||
|
|||||||
75
src/Endpoints/Accounts.php
Normal file
75
src/Endpoints/Accounts.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* User: kanasite
|
||||||
|
* Date: 01/28/2019
|
||||||
|
* Time: 10:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class Accounts implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listAccounts(
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $direction = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get('accounts', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDomains(string $accountID): array
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains');
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDomainDetails(string $accountID, string $domainName): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains/' . $domainName);
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lockDomain(string $accountID, string $domainName): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => true]);
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unlockDomain(string $accountID, string $domainName): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => false]);
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,8 +124,8 @@ class DNS implements API
|
|||||||
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
|
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
|
||||||
{
|
{
|
||||||
$records = $this->listRecords($zoneID, $type, $name);
|
$records = $this->listRecords($zoneID, $type, $name);
|
||||||
if (isset($records->result{0}->id)) {
|
if (isset($records->result[0]->id)) {
|
||||||
return $records->result{0}->id;
|
return $records->result[0]->id;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
120
src/Endpoints/Firewall.php
Normal file
120
src/Endpoints/Firewall.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\FirewallRuleOptions;
|
||||||
|
|
||||||
|
class Firewall implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createFirewallRules(
|
||||||
|
string $zoneID,
|
||||||
|
array $rules
|
||||||
|
): bool {
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/rules', $rules);
|
||||||
|
$body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
foreach ($body->result as $result) {
|
||||||
|
if (!isset($result->id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createFirewallRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $expression,
|
||||||
|
FirewallRuleOptions $options,
|
||||||
|
string $description = null,
|
||||||
|
int $priority = null
|
||||||
|
): bool {
|
||||||
|
$rule = array_merge([
|
||||||
|
'filter' => [
|
||||||
|
'expression' => $expression,
|
||||||
|
'paused' => false
|
||||||
|
]
|
||||||
|
], $options->getArray());
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$rule['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priority !== null) {
|
||||||
|
$rule['priority'] = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->createFirewallRules($zoneID, [$rule]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listFirewallRules(
|
||||||
|
string $zoneID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 50
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
];
|
||||||
|
|
||||||
|
$rules = $this->adapter->get('zones/' . $zoneID . '/firewall/rules', $query);
|
||||||
|
$body = json_decode($rules->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteFirewallRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID
|
||||||
|
): bool {
|
||||||
|
$rule = $this->adapter->delete('zones/' . $zoneID . '/firewall/rules/' . $ruleID);
|
||||||
|
|
||||||
|
$body = json_decode($rule->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateFirewallRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
string $filterID,
|
||||||
|
string $expression,
|
||||||
|
FirewallRuleOptions $options,
|
||||||
|
string $description = null,
|
||||||
|
int $priority = null
|
||||||
|
): \stdClass {
|
||||||
|
$rule = array_merge([
|
||||||
|
'id' => $ruleID,
|
||||||
|
'filter' => [
|
||||||
|
'id' => $filterID,
|
||||||
|
'expression' => $expression,
|
||||||
|
'paused' => false
|
||||||
|
]
|
||||||
|
], $options->getArray());
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$rule['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priority !== null) {
|
||||||
|
$rule['priority'] = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rule = $this->adapter->put('zones/' . $zoneID . '/firewall/rules/' . $ruleID, $rule);
|
||||||
|
$body = json_decode($rule->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,6 +109,37 @@ class PageRules implements API
|
|||||||
return $this->body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editPageRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
PageRulesTargets $target,
|
||||||
|
PageRulesActions $actions,
|
||||||
|
bool $active = null,
|
||||||
|
int $priority = null
|
||||||
|
): bool {
|
||||||
|
$options = [];
|
||||||
|
$options['targets'] = $target->getArray();
|
||||||
|
$options['actions'] = $actions->getArray();
|
||||||
|
|
||||||
|
if ($active !== null) {
|
||||||
|
$options['status'] = $active == true ? 'active' : 'disabled';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priority !== null) {
|
||||||
|
$options['priority'] = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->put('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function updatePageRule(
|
public function updatePageRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $ruleID,
|
string $ruleID,
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class ZoneSettings implements API
|
class ZoneSettings implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -75,6 +78,20 @@ class ZoneSettings implements API
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getServerSideExcludeSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/server_side_exclude'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function getHotlinkProtectionSetting($zoneID)
|
public function getHotlinkProtectionSetting($zoneID)
|
||||||
{
|
{
|
||||||
$return = $this->adapter->get(
|
$return = $this->adapter->get(
|
||||||
@@ -177,4 +194,21 @@ class ZoneSettings implements API
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateServerSideExcludeSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/server_side_exclude',
|
||||||
|
[
|
||||||
|
'value' => $value
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,30 @@ class Zones implements API
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pause(string $zoneID): bool
|
||||||
|
{
|
||||||
|
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => true]);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unpause(string $zoneID): bool
|
||||||
|
{
|
||||||
|
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => false]);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function getZoneById(
|
public function getZoneById(
|
||||||
string $zoneId
|
string $zoneId
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
|
|||||||
21
tests/Auth/APITokenTest.php
Normal file
21
tests/Auth/APITokenTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: czPechy
|
||||||
|
* Date: 30/07/2018
|
||||||
|
* Time: 23:25
|
||||||
|
*/
|
||||||
|
class APITokenTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetHeaders()
|
||||||
|
{
|
||||||
|
$auth = new \Cloudflare\API\Auth\APIToken('zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy');
|
||||||
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('Authorization', $headers);
|
||||||
|
|
||||||
|
$this->assertEquals('Bearer zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy', $headers['Authorization']);
|
||||||
|
|
||||||
|
$this->assertCount(1, $headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
tests/Endpoints/AccountsTest.php
Normal file
37
tests/Endpoints/AccountsTest.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* User: kanasite
|
||||||
|
* Date: 01/28/2019
|
||||||
|
* Time: 10:00
|
||||||
|
*/
|
||||||
|
class AccountsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListZones()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccounts.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'direction' => 'desc',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$accounts = new \Cloudflare\API\Endpoints\Accounts($mock);
|
||||||
|
$result = $accounts->listAccounts(1, 20, 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
177
tests/Endpoints/FirewallTest.php
Normal file
177
tests/Endpoints/FirewallTest.php
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class FirewallTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreatePageRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
[
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Foo',
|
||||||
|
'filter' => [
|
||||||
|
'expression' => 'http.cookie eq "foo"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Bar',
|
||||||
|
'filter' => [
|
||||||
|
'expression' => 'http.cookie eq "bar"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
]
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||||
|
$result = $firewall->createFirewallRules(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'filter' => [
|
||||||
|
'expression' => 'http.cookie eq "foo"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Foo'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'filter' => [
|
||||||
|
'expression' => 'http.cookie eq "bar"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Bar'
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreatePageRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
[
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Foobar',
|
||||||
|
'filter' => [
|
||||||
|
'expression' => 'http.cookie eq "foobar"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
'paused' => false
|
||||||
|
]
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||||
|
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
|
||||||
|
$options->setActionBlock();
|
||||||
|
$result = $firewall->createFirewallRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'http.cookie eq "foobar"',
|
||||||
|
$options,
|
||||||
|
'Foobar'
|
||||||
|
);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListFirewallRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listFirewallRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 50
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||||
|
$result = $firewall->listFirewallRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteFirewallRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteFirewallRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules/970b10321e3f4adda674c912b5f76591')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||||
|
$firewall->deleteFirewallRule('023e105f4ecef8ad9ca31a8372d0c353', '970b10321e3f4adda674c912b5f76591');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateFirewallRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateFirewallRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules/970b10321e3f4adda674c912b5f76591'),
|
||||||
|
$this->equalTo([
|
||||||
|
'id' => '970b10321e3f4adda674c912b5f76591',
|
||||||
|
'action' => 'block',
|
||||||
|
'description' => 'Foo',
|
||||||
|
'filter' => [
|
||||||
|
'id' => '5def9c4297e0466cb0736b838345d910',
|
||||||
|
'expression' => 'http.cookie eq "foo"',
|
||||||
|
'paused' => false
|
||||||
|
],
|
||||||
|
'paused' => false
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||||
|
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
|
||||||
|
$options->setActionBlock();
|
||||||
|
$result = $firewall->updateFirewallRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'970b10321e3f4adda674c912b5f76591',
|
||||||
|
'5def9c4297e0466cb0736b838345d910',
|
||||||
|
'http.cookie eq "foo"',
|
||||||
|
$options,
|
||||||
|
'Foo'
|
||||||
|
);
|
||||||
|
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ class SSLTest extends TestCase
|
|||||||
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertEquals('active', $result->result{0}->certificate_status);
|
$this->assertEquals('active', $result->result[0]->certificate_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetHTTPSRedirectSetting()
|
public function testGetHTTPSRedirectSetting()
|
||||||
|
|||||||
39
tests/Endpoints/ZoneSettingsTest.php
Normal file
39
tests/Endpoints/ZoneSettingsTest.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Endpoints\ZoneSettings;
|
||||||
|
|
||||||
|
class ZoneSettingsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetServerSideExcludeSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getServerSideExclude.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())->method('get');
|
||||||
|
|
||||||
|
$zones = new ZoneSettings($mock);
|
||||||
|
$result = $zones->getServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertSame('on', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateServerSideExcludeSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateServerSideExclude.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())->method('patch');
|
||||||
|
|
||||||
|
$zones = new ZoneSettings($mock);
|
||||||
|
$result = $zones->updateServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353', 'on');
|
||||||
|
|
||||||
|
$this->assertSame('on', $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
tests/Fixtures/Endpoints/createFirewallRule.json
Normal file
20
tests/Fixtures/Endpoints/createFirewallRule.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "970b10321e3f4adda674c912b5f76591",
|
||||||
|
"paused": false,
|
||||||
|
"description": "Foobar",
|
||||||
|
"action": "block",
|
||||||
|
"filter": {
|
||||||
|
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||||
|
"expression": "http.cookie eq \"foobar\"",
|
||||||
|
"paused": false
|
||||||
|
},
|
||||||
|
"created_on": "2019-07-05T15:53:15Z",
|
||||||
|
"modified_on": "2019-07-05T15:53:15Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
33
tests/Fixtures/Endpoints/createFirewallRules.json
Normal file
33
tests/Fixtures/Endpoints/createFirewallRules.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "970b10321e3f4adda674c912b5f76591",
|
||||||
|
"paused": false,
|
||||||
|
"description": "Foo",
|
||||||
|
"action": "block",
|
||||||
|
"filter": {
|
||||||
|
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||||
|
"expression": "http.cookie eq \"foo\"",
|
||||||
|
"paused": false
|
||||||
|
},
|
||||||
|
"created_on": "2019-07-05T15:53:15Z",
|
||||||
|
"modified_on": "2019-07-05T15:53:15Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "42c05fd0e0af4d17a361d2d1423476bc",
|
||||||
|
"paused": false,
|
||||||
|
"description": "Bar",
|
||||||
|
"action": "block",
|
||||||
|
"filter": {
|
||||||
|
"id": "246b4d9f5f51471485bdc95e1c6b53a7",
|
||||||
|
"expression": "http.cookie eq \"bar\"",
|
||||||
|
"paused": false
|
||||||
|
},
|
||||||
|
"created_on": "2019-07-05T15:53:15Z",
|
||||||
|
"modified_on": "2019-07-05T15:53:15Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
8
tests/Fixtures/Endpoints/deleteFirewallRule.json
Normal file
8
tests/Fixtures/Endpoints/deleteFirewallRule.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"id": "970b10321e3f4adda674c912b5f76591"
|
||||||
|
},
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/getServerSideExclude.json
Normal file
11
tests/Fixtures/Endpoints/getServerSideExclude.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "server_side_exclude",
|
||||||
|
"value": "on",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
tests/Fixtures/Endpoints/listAccounts.json
Normal file
20
tests/Fixtures/Endpoints/listAccounts.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"name": "Example Account",
|
||||||
|
"settings": {
|
||||||
|
"enforce_twofactor": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
27
tests/Fixtures/Endpoints/listFirewallRules.json
Normal file
27
tests/Fixtures/Endpoints/listFirewallRules.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "970b10321e3f4adda674c912b5f76591",
|
||||||
|
"paused": false,
|
||||||
|
"description": "Foobar",
|
||||||
|
"action": "block",
|
||||||
|
"filter": {
|
||||||
|
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||||
|
"expression": "http.cookie eq \"foobar\"",
|
||||||
|
"paused": false
|
||||||
|
},
|
||||||
|
"created_on": "2019-07-05T15:53:15Z",
|
||||||
|
"modified_on": "2019-07-05T15:53:15Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 50,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 1,
|
||||||
|
"total_pages": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
19
tests/Fixtures/Endpoints/updateFirewallRule.json
Normal file
19
tests/Fixtures/Endpoints/updateFirewallRule.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"id": "970b10321e3f4adda674c912b5f76591",
|
||||||
|
"paused": false,
|
||||||
|
"description": "Foo",
|
||||||
|
"action": "block",
|
||||||
|
"filter": {
|
||||||
|
"id": "5def9c4297e0466cb0736b838345d910",
|
||||||
|
"expression": "http.cookie eq \"foo\"",
|
||||||
|
"paused": false
|
||||||
|
},
|
||||||
|
"created_on": "2019-07-05T15:53:15Z",
|
||||||
|
"modified_on": "2019-07-05T18:07:46Z",
|
||||||
|
"index": 1
|
||||||
|
},
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/updateServerSideExclude.json
Normal file
11
tests/Fixtures/Endpoints/updateServerSideExclude.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "server_side_exclude",
|
||||||
|
"value": "on",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user