51 Commits
0.9.1 ... 1.0.4

Author SHA1 Message Date
Junade
e1cf1ae41f Merge pull request #24 from limenet/master
Don't double JSON-encode the request
2017-10-07 00:03:10 +01:00
Linus Metzler
70ee68f755 fix the test 2017-10-05 14:44:09 +02:00
Linus Metzler
566ab3fc70 Don't run json_encode
Guzzle takes care of this thanks to its JSON middleware
2017-10-03 21:16:58 +02:00
Junade
ca80e2c388 Merge pull request #23 from cloudflare/cacheoncookie-patch
Correct input types for (Bypass) Cache on Cookie
2017-10-03 18:16:07 +01:00
Junade Ali
d49028a31e Updated DNSTest style. 2017-10-03 18:09:07 +01:00
Junade
a5384b7466 Correct input types for (Bypass) Cache on Cookie 2017-10-03 17:59:59 +01:00
Junade
8ffd3e3541 Merge pull request #18 from anthonysterling/feature/page-rules-config
Consolidated some of the config/option creation
2017-10-03 17:57:57 +01:00
Junade
3ce5e1911f Merge pull request #21 from anthonysterling/fix/issue-19
Added test coverage for DNS Update
2017-10-03 17:42:26 +01:00
Junade
1226d35472 Merge pull request #22 from anthonysterling/fix/inconsistent-array-declaration
Inconsistent Array Declaration
2017-10-03 17:42:16 +01:00
Anthony Sterling
cebeae15a3 Inconsistent Array Declaration
This PR normalises the declaration of arrays throughout the project, and adds
this to the php-cs-fixer rules.

I've chosen "short" by default, but happy to change the PR to use "long" if
preferred.
2017-10-02 09:05:05 +01:00
Anthony Sterling
db62f1db8a Added test coverage for DNS Update
I've added a test to cover the updating of a DNS record to help debug Issue #19
2017-10-02 08:48:43 +01:00
Anthony Sterling
b7e70655ce Consolidated some of the config/option creation
I've just added some internal methods to handle the casting and formatting of the
configuration/option creation.
2017-09-28 21:16:27 +01:00
Junade
49ed1c9e8f Merge pull request #17 from cloudflare/issue-16
Move friendsofphp/php-cs-fixer to dev requirement
2017-09-25 16:41:28 +01:00
Junade
68a26e7e77 Comma correction 2017-09-25 15:49:49 +01:00
Junade
b4a13d8e2b Move friendsofphp/php-cs-fixer to dev requirement 2017-09-25 15:48:07 +01:00
Junade
a80747ee06 Merge pull request #15 from anthonysterling/feature/fixtures
Moved JSON API Responses to test fixtures
2017-09-24 18:41:15 +01:00
Anthony Sterling
fbb5aac074 Moved JSON API Responses to test fixtures
This PR moves the JSON API responses used in the tests to fixture files
within the tests folder. This allows reuse and the ability to lint/validate
these fixtures if required - although not covered in this PR.

I've added TestCase::getPsr7StreamForFixture and TestCase::getPsr7JsonResponseForFixture
to reduce code duplication and enable some assertions around the expected fixures/responses.

Thanks,
2017-09-24 15:24:33 +01:00
Junade
471227b96f Merge pull request #14 from anthonysterling/feature/coding-standard
feature/coding standard
2017-09-24 14:07:03 +01:00
Junade
4d17609641 Merge pull request #13 from kelunik/readme-improvements
Remove leading namespace slashes in README
2017-09-24 14:04:09 +01:00
Anthony Sterling
feecc9fcbb Added lint target as php-cs-fixer only returns a non-zero exit code during dry run now 2017-09-23 22:04:26 +01:00
Anthony Sterling
589766e008 Removed the before_script section for Travis CI as this functionality is default now 2017-09-23 19:02:17 +01:00
Anthony Sterling
2faff272df Applied PSR2 formatting to existing files 2017-09-23 18:50:51 +01:00
Anthony Sterling
90196ea836 Added, and configured, php-cs-fixer with a Makefile to invoke fix and test 2017-09-23 18:49:58 +01:00
Anthony Sterling
80c611691b Removed out-of-date composer.lock file - libraries usually do not contain one anyway 2017-09-23 18:39:45 +01:00
Niklas Keller
85385dedf5 Remove leading namespace slashes in README
This makes it consistent with the middle line and is nicer to read.
2017-09-23 11:52:05 +02:00
Junade
b91dd5e684 Merge pull request #5 from typhonius/add-query-to-get
Adds the query parameter to the guzzle call for GET requests.
2017-09-21 23:16:50 +01:00
Junade
77df7ead1e Merge pull request #11 from typhonius/fix-zone-id-verification
Changes sizeof check to throw an error if no zone id is found.
2017-09-21 18:07:55 +01:00
Adam Malone
9939afd0b6 Changes sizeof check to throw an error if no zone id is found. 2017-09-22 02:53:25 +10:00
Adam Malone
7d838d7f5f Adds the query parameter to the guzzle call for GET requests. 2017-09-21 11:45:21 +10:00
Junade
ebe2a9803a Added link to Packagist and the Cloudflare KB 2017-09-20 16:17:49 +01:00
Junade
f38b1c61f7 Merge pull request #10 from cloudflare/COM-45
COM-45 :: Bugfix active status in Page Rules
2017-09-20 15:00:53 +01:00
Junade Ali
635a299b43 COM-45 :: Update PageRule tests. 2017-09-20 14:55:44 +01:00
Junade Ali
85d64f8afc COM-45 :: Bugfix active status in Page Rules 2017-09-20 14:50:55 +01:00
Junade
48db6337c5 Merge pull request #9 from cloudflare/COM-45
COM-45 :: Bugfix Page Rules class
2017-09-20 14:35:25 +01:00
Junade Ali
4699270f51 COM-45 :: Bugfix Page Rules class 2017-09-20 14:32:46 +01:00
Junade
2a3929824e Merge pull request #8 from cloudflare/COM-45
COM-45 :: Change API submission type to JSON and adjust function names
2017-09-20 13:36:44 +01:00
Junade Ali
121209e4ca COM-45 :: Adjust Guzzle Tests 2017-09-20 13:25:00 +01:00
Junade Ali
1baeeee882 COM-40 :: Change API submission type to JSON and adjust function names 2017-09-20 13:15:34 +01:00
Junade
a4ddb61d2a Merge pull request #7 from cloudflare/COM-40
COM-40 :: Added Page Rules endpoint.
2017-09-20 11:54:57 +01:00
Junade Ali
3166645a0c COM-40 :: Added Page Rules endpoint. 2017-09-20 11:52:33 +01:00
Junade
1658f4abcc Merge pull request #6 from cloudflare/COM-40
COM-40 :: Add ZoneLockdown and UA Rules
2017-09-19 16:10:19 +01:00
Junade Ali
1e8c8d6019 COM-40 :: Add ZoneLockdown and UA Rules 2017-09-19 16:04:35 +01:00
Junade
1b5d0273ed Merge pull request #4 from cloudflare/COM-40
COM-40 :: Added None Auth class, IPs endpoint and associated tests
2017-09-05 13:13:03 +01:00
Junade Ali
7d0c0c86dc COM-40 :: General refactoring/fixes. 2017-09-04 21:14:34 +01:00
Junade Ali
53cbd9d578 Finalised IPs endpoint 2017-09-04 20:33:22 +01:00
Junade Ali
4876787118 COM-40 :: Added None Auth class, IPs endpoint and associated tests 2017-09-04 20:22:23 +01:00
Junade
938172c17b Merge pull request #3 from cloudflare/COM-40
COM-40 :: Add Travis preview button and remove nightly from build
2017-09-04 19:41:16 +01:00
Junade Ali
7a60774ec2 COM-40 :: Add Travis preview button and remove nightly from build 2017-09-04 19:37:01 +01:00
Junade
5266b2c2af Merge pull request #2 from hans00/master
Use correct format to post data.
2017-08-30 18:48:07 +01:00
Hans
696a36d682 Change post unit test to json. 2017-08-30 17:02:09 +08:00
Hans
91dbd38824 Use correct format to post data. 2017-08-27 00:28:21 -05:00
74 changed files with 2440 additions and 2352 deletions

15
.php_cs Normal file
View File

@@ -0,0 +1,15 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;

View File

@@ -3,7 +3,6 @@ language: php
php:
- 7.0
- 7.1
- nightly
before_install:
- composer self-update
@@ -12,4 +11,5 @@ install:
- travis_retry composer install --no-interaction --prefer-source
script:
- composer test
- make lint
- make test

15
Makefile Normal file
View File

@@ -0,0 +1,15 @@
THIS := $(realpath $(lastword $(MAKEFILE_LIST)))
HERE := $(shell dirname $(THIS))
.PHONY: all fix lint test
all: lint test
fix:
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs
lint:
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs --dry-run
test:
php $(HERE)/vendor/bin/phpunit --configuration $(HERE)/phpunit.xml

View File

@@ -1,8 +1,10 @@
# Cloudflare SDK (v4 API Binding for PHP 7)
[![Build Status](https://travis-ci.org/cloudflare/cloudflare-php.svg?branch=master)](https://travis-ci.org/cloudflare/cloudflare-php)
## Installation
The recommended way to install this package is via the Packagist Dependency Manager.
The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
## Cloudflare API version 4
@@ -10,14 +12,15 @@ The Cloudflare API can be found [here](https://api.cloudflare.com/).
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
- [x] DNS Records
- [x] [DNS Records](https://www.cloudflare.com/dns/)
- [x] Zones
- [x] User Administration (partial)
- [ ] Cloudflare IPs
- [ ] Page Rules
- [ ] Web Application Firewall (WAF)
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [ ] Virtual DNS Management
- [ ] Custom hostnames
- [x] Zone Lockdown and User-Agent Block rules
- [ ] Organization Administration
- [ ] [Railgun](https://www.cloudflare.com/railgun/) administration
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
@@ -28,13 +31,13 @@ Note that this repository is currently under development, additional classes and
## Getting Started
```php
$key = new \Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
$key = new Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
$user = new \Cloudflare\API\Endpoints\User($adapter);
$user = new Cloudflare\API\Endpoints\User($adapter);
echo $user->getUserID();
```
## Licensing
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.

View File

@@ -9,7 +9,8 @@
},
"require-dev": {
"phpunit/phpunit": "5.7.5",
"phpmd/phpmd" : "@stable"
"phpmd/phpmd" : "@stable",
"friendsofphp/php-cs-fixer": "^2.6"
},
"license": "BSD-3-Clause",
"authors": [
@@ -23,7 +24,9 @@
"Cloudflare\\API\\": "src/"
}
},
"scripts": {
"test": "phpunit"
"autoload-dev": {
"classmap": [
"tests/"
]
}
}

1826
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,7 @@ interface Adapter
*
* @return mixed
*/
public function get(String $uri, array $headers): ResponseInterface;
public function get(String $uri, array $query, array $headers): ResponseInterface;
/**
* @param String $uri
@@ -72,4 +72,4 @@ interface Adapter
* @return mixed
*/
public function delete(String $uri, array $headers, array $body): ResponseInterface;
}
}

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Adapter;
use Cloudflare\API\Auth\Auth;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
@@ -19,8 +18,12 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function __construct(Auth $auth, String $baseURI = "https://api.cloudflare.com/client/v4/")
public function __construct(Auth $auth, String $baseURI = null)
{
if ($baseURI === null) {
$baseURI = "https://api.cloudflare.com/client/v4/";
}
$headers = $auth->getHeaders();
$this->client = new Client([
@@ -34,23 +37,24 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function get(String $uri, array $headers = array()): ResponseInterface
public function get(String $uri, array $query = [], array $headers = []): ResponseInterface
{
$response = $this->client->get($uri, ['headers' => $headers]);
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
$this->checkError($response);
return $response;
}
/**
* @inheritDoc
*/
public function post(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function post(String $uri, array $headers = [], array $body = []): ResponseInterface
{
$response = $this->client->post($uri, [
$response = $this->client->post(
$uri,
[
'headers' => $headers,
'form_params' => $body
'json' => $body
]
);
@@ -61,13 +65,13 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function put(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function put(String $uri, array $headers = [], array $body = []): ResponseInterface
{
$jsonBody = json_encode($body);
$response = $this->client->put($uri, [
$response = $this->client->put(
$uri,
[
'headers' => $headers,
'body' => $jsonBody
'json' => $body
]
);
@@ -78,13 +82,13 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function patch(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function patch(String $uri, array $headers = [], array $body = []): ResponseInterface
{
$jsonBody = json_encode($body);
$response = $this->client->patch($uri, [
$response = $this->client->patch(
$uri,
[
'headers' => $headers,
'body' => $jsonBody
'json' => $body
]
);
@@ -95,11 +99,13 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function delete(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function delete(String $uri, array $headers = [], array $body = []): ResponseInterface
{
$response = $this->client->delete($uri, [
$response = $this->client->delete(
$uri,
[
'headers' => $headers,
'form_params' => $body
'json' => $body
]
);
@@ -125,4 +131,4 @@ class Guzzle implements Adapter
throw new ResponseException("Request was unsuccessful.");
}
}
}
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Adapter;
class JSONException extends \Exception
{
}
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Adapter;
class ResponseException extends \Exception
{
}
}

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Auth;
class APIKey implements Auth
{
private $email;
@@ -26,4 +25,4 @@ class APIKey implements Auth
'X-Auth-Key' => $this->apiKey
];
}
}
}

View File

@@ -7,8 +7,7 @@
namespace Cloudflare\API\Auth;
interface Auth
{
public function getHeaders(): array;
}
}

17
src/Auth/None.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 19:55
*/
namespace Cloudflare\API\Auth;
class None implements Auth
{
public function getHeaders(): array
{
return [];
}
}

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Auth;
class UserServiceKey implements Auth
{
private $userServiceKey;
@@ -23,4 +22,4 @@ class UserServiceKey implements Auth
'X-Auth-User-Service-Key' => $this->userServiceKey,
];
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 15:23
*/
namespace Cloudflare\API\Configurations;
interface Configurations
{
public function getArray(): array;
}

View File

@@ -0,0 +1,13 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 16:57
*/
namespace Cloudflare\API\Configurations;
class ConfigurationsException extends \Exception
{
}

View File

@@ -0,0 +1,311 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 16:50
*/
namespace Cloudflare\API\Configurations;
class PageRulesActions implements Configurations
{
private $configs = [];
public function setAlwaysOnline(bool $active)
{
$this->addConfigurationOption("always_online", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAlwaysUseHTTPS(bool $active)
{
$this->addConfigurationOption("always_use_https", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBrowserCacheTTL(int $ttl)
{
$this->addConfigurationOption("browser_cache_ttl", [
'value' => $ttl
]);
}
public function setBrowserIntegrityCheck(bool $active)
{
$this->addConfigurationOption("browser_check", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBypassCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
}
$this->addConfigurationOption("bypass_cache_on_cookie", [
'value' => $value
]);
}
public function setCacheByDeviceType(bool $active)
{
$this->addConfigurationOption("cache_by_device_type", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setCacheKey(string $value)
{
$this->addConfigurationOption("cache_key", [
'value' => $value
]);
}
public function setCacheLevel(string $value)
{
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
throw new ConfigurationsException("Invalid cache level");
}
$this->addConfigurationOption("cache_level", [
'value' => $value
]);
}
public function setCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
}
$this->addConfigurationOption("cache_on_cookie", [
'value' => $value
]);
}
public function setDisableApps(bool $active)
{
$this->addConfigurationOption("disable_apps", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisablePerformance(bool $active)
{
$this->addConfigurationOption("disable_performance", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableSecurity(bool $active)
{
$this->addConfigurationOption("disable_security", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setEdgeCacheTTL(int $value)
{
if ($value > 2419200) {
throw new ConfigurationsException("Edge Cache TTL too high.");
}
$this->addConfigurationOption("edge_cache_ttl", [
'value' => $value
]);
}
public function setEmailObfuscation(bool $active)
{
$this->addConfigurationOption("disable_security", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setForwardingURL(int $statusCode, string $forwardingUrl)
{
if (!in_array($statusCode, ['301', '302'])) {
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
}
$this->addConfigurationOption("forwarding_url", [
'status_code' => $statusCode,
'url' => $forwardingUrl,
]);
}
public function setHostHeaderOverride(bool $active)
{
$this->addConfigurationOption("host_header_override", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setHotlinkProtection(bool $active)
{
$this->addConfigurationOption("hotlink_protection", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setIPGeoLocationHeader(bool $active)
{
$this->addConfigurationOption("ip_geolocation", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setMinification(bool $html, bool $css, bool $js)
{
$this->addConfigurationOption("minification", [
'html' => $this->getBoolAsOnOrOff($html),
'css' => $this->getBoolAsOnOrOff($css),
'js' => $this->getBoolAsOnOrOff($js),
]);
}
public function setMirage(bool $active)
{
$this->addConfigurationOption("mirage", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOriginErrorPagePassthru(bool $active)
{
$this->addConfigurationOption("origin_error_page_pass_thru", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setQueryStringSort(bool $active)
{
$this->addConfigurationOption("sort_query_string_for_cache", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableRailgun(bool $active)
{
$this->addConfigurationOption("disable_railgun", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResolveOverride(bool $value)
{
$this->addConfigurationOption("resolve_override", [
'value' => $value
]);
}
public function setRespectStrongEtag(bool $active)
{
$this->addConfigurationOption("respect_strong_etag", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResponseBuffering(bool $active)
{
$this->addConfigurationOption("response_buffering", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setRocketLoader(string $value)
{
if (!in_array($value, ["off", "manual", "automatic"])) {
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
}
$this->addConfigurationOption("rocket_loader", [
'value' => $value
]);
}
public function setSecurityLevel(string $value)
{
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
}
$this->addConfigurationOption("security_level", [
'value' => $value
]);
}
public function setServerSideExcludes(bool $active)
{
$this->addConfigurationOption("server_side_exclude", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSmartErrors(bool $active)
{
$this->addConfigurationOption("smart_errors", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSSL(string $value)
{
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
}
$this->addConfigurationOption("smart_errors", [
'value' => $value
]);
}
public function setTrueClientIpHeader(bool $active)
{
$this->addConfigurationOption("true_client_ip_header", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setWAF(bool $active)
{
$this->addConfigurationOption("waf", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAutomatedHTTPSRewrites(bool $active)
{
$this->addConfigurationOption("automatic_https_rewrites", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOpportunisticEncryption(bool $active)
{
$this->addConfigurationOption("opportunistic_encryption", [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function getArray(): array
{
return $this->configs;
}
private function addConfigurationOption($id, array $configuration)
{
$configuration['id'] = $id;
array_push($this->configs, (object) $configuration);
}
private function getBoolAsOnOrOff(bool $value): string
{
return true === $value ? 'on' : 'off';
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 18:37
*/
namespace Cloudflare\API\Configurations;
class PageRulesTargets implements Configurations
{
private $targets;
public function __construct(string $queryUrl)
{
$target = new \stdClass();
$target->target = 'url';
$target->constraint = new \stdClass();
$target->constraint->operator = "matches";
$target->constraint->value = $queryUrl;
$this->targets = [$target];
}
public function getArray(): array
{
return $this->targets;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 15:22
*/
namespace Cloudflare\API\Configurations;
class UARules implements Configurations
{
private $configs = [];
public function addUA(string $value)
{
$object = new \stdClass();
$object->target = "ua";
$object->value = $value;
array_push($this->configs, $object);
}
public function getArray(): array
{
return $this->configs;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:43
*/
namespace Cloudflare\API\Configurations;
class ZoneLockdown implements Configurations
{
private $configs = [];
public function addIP(string $value)
{
$object = new \stdClass();
$object->target = "ip";
$object->value = $value;
array_push($this->configs, $object);
}
public function addIPRange(string $value)
{
$object = new \stdClass();
$object->target = "ip_range";
$object->value = $value;
array_push($this->configs, $object);
}
public function getArray(): array
{
return $this->configs;
}
}

View File

@@ -7,10 +7,9 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
interface API
{
public function __construct(Adapter $adapter);
}
}

View File

@@ -19,8 +19,14 @@ class DNS implements API
$this->adapter = $adapter;
}
public function addRecord(string $zoneID, string $type, string $name, string $content, int $ttl = 0, bool $proxied = true): bool
{
public function addRecord(
string $zoneID,
string $type,
string $name,
string $content,
int $ttl = 0,
bool $proxied = true
): bool {
$options = [
'type' => $type,
'name' => $name,
@@ -46,6 +52,7 @@ class DNS implements API
public function listRecords(
string $zoneID,
string $type = "",
string $name = "",
string $content = "",
int $page = 1,
int $perPage = 20,
@@ -53,33 +60,33 @@ class DNS implements API
string $direction = "",
string $match = "all"
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($type)) {
$options['type'] = $type;
$query['type'] = $type;
}
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($content)) {
$options['content'] = $content;
$query['content'] = $content;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
if (!empty($direction)) {
$options['direction'] = $direction;
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records', [], $options);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
@@ -91,20 +98,20 @@ class DNS implements API
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records/'.$recordID, []);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$body = json_decode($user->getBody());
return $body->result;
}
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/'.$zoneID.'/dns_records/'.$recordID, [], $details);
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
return json_decode($response->getBody());
}
public function deleteRecord(string $zoneID, string $recordID): bool
{
$user = $this->adapter->delete('zones/'.$zoneID.'/dns_records/'.$recordID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$body = json_decode($user->getBody());
@@ -114,5 +121,4 @@ class DNS implements API
return false;
}
}
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Endpoints;
class EndpointException extends \Exception
{
}
}

29
src/Endpoints/IPs.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 19:56
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class IPs implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listIPs(): \stdClass
{
$ips = $this->adapter->get('ips', [], []);
$body = json_decode($ips->getBody());
return $body->result;
}
}

148
src/Endpoints/PageRules.php Normal file
View File

@@ -0,0 +1,148 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 16:17
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\PageRulesActions;
use Cloudflare\API\Configurations\PageRulesTargets;
class PageRules implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function createPageRule(
string $zoneID,
PageRulesTargets $target,
PageRulesActions $actions,
bool $active = true,
int $priority = null
): bool {
$options = [
'targets' => $target->getArray(),
'actions' => $actions->getArray()
];
if ($active !== null) {
$options['status'] = $active == true ? 'active' : 'disabled';
}
if ($priority !== null) {
$options['priority'] = $priority;
}
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
$body = json_decode($query->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function listPageRules(
string $zoneID,
string $status = null,
string $order = null,
string $direction = null,
string $match = null
): array {
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
}
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
throw new EndpointException('Page Rules can only be ordered by status or priority.');
}
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
}
if (is_null($match) && !in_array($match, ['all', 'any'])) {
throw new EndpointException('Match can only be any or all.');
}
$query = [
'status' => $status,
'order' => $order,
'direction' => $direction,
'match' => $match
];
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
$body = json_decode($user->getBody());
return $body->result;
}
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$body = json_decode($user->getBody());
return $body->result;
}
public function updatePageRule(
string $zoneID,
PageRulesTargets $target = null,
PageRulesActions $actions = null,
bool $active = null,
int $priority = null
): bool {
$options = [];
if ($active !== null) {
$options['targets'] = $target->getArray();
}
if ($actions !== null) {
$options['actions'] = $actions->getArray();
}
if ($active !== null) {
$options['status'] = $active == true ? 'active' : 'disabled';
}
if ($priority !== null) {
$options['priority'] = $priority;
}
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
$body = json_decode($query->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function deletePageRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
}

120
src/Endpoints/UARules.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 15:17
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class UARules implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listRules(
string $zoneID,
int $page = 1,
int $perPage = 20
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage
];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
}
public function createRule(
string $zoneID,
string $mode,
\Cloudflare\API\Configurations\Configurations $configuration,
string $id = null,
string $description = null
): bool {
$options = [
'mode' => $mode,
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
}
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
$body = json_decode($user->getBody());
return $body->result;
}
public function updateRule(
string $zoneID,
string $ruleID,
string $mode,
\Cloudflare\API\Configurations\UARules $configuration,
string $description = null
): bool {
$options = [
'mode' => $mode,
'id' => $ruleID,
'configurations' => $configuration->getArray()
];
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function deleteRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class User implements API
@@ -21,7 +20,7 @@ class User implements API
public function getUserDetails(): \stdClass
{
$user = $this->adapter->get('user', []);
$user = $this->adapter->get('user', [], []);
$body = json_decode($user->getBody());
return $body->result;
}
@@ -41,4 +40,4 @@ class User implements API
$response = $this->adapter->patch("user", [], $details);
return json_decode($response->getBody());
}
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 20:33
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class ZoneLockdown implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listLockdowns(
string $zoneID,
int $page = 1,
int $perPage = 20
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage
];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
}
public function createLockdown(
string $zoneID,
array $urls,
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
string $id = null,
string $description = null
): bool {
$options = [
'urls' => $urls,
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
}
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$body = json_decode($user->getBody());
return $body->result;
}
public function updateLockdown(
string $zoneID,
string $lockdownID,
array $urls,
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
string $description = null
): bool {
$options = [
'urls' => $urls,
'id' => $lockdownID,
'configurations' => $configuration->getArray()
];
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function deleteLockdown(string $zoneID, string $lockdownID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -58,29 +58,29 @@ class Zones implements API
string $direction = "",
string $match = "all"
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($status)) {
$options['status'] = $status;
$query['status'] = $status;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
if (!empty($direction)) {
$options['direction'] = $direction;
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones', [], $options);
$user = $this->adapter->get('zones', $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
@@ -94,7 +94,7 @@ class Zones implements API
{
$zones = $this->listZones($name);
if (sizeof($zones) < 1) {
if (sizeof($zones->result) < 1) {
throw new EndpointException("Could not find zones with specified name.");
}
@@ -106,7 +106,7 @@ class Zones implements API
* @param string $zoneID
* @return bool
*/
public function purgeAll(string $zoneID): bool
public function cachePurgeEverything(string $zoneID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
@@ -119,7 +119,7 @@ class Zones implements API
return false;
}
public function purge(string $zoneID, array $files = [], array $tags = []): bool
public function cachePurge(string $zoneID, array $files = [], array $tags = []): bool
{
if (empty($files) && empty($tags)) {
throw new EndpointException("No files or tags to purge.");
@@ -140,4 +140,4 @@ class Zones implements API
return false;
}
}
}

View File

@@ -8,7 +8,7 @@
use GuzzleHttp\Psr7\Response;
class GuzzleTest extends PHPUnit_Framework_TestCase
class GuzzleTest extends TestCase
{
private $client;
@@ -34,7 +34,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$body = json_decode($response->getBody());
$this->assertEquals("Test", $body->headers->{"X-Testing"});
$response = $this->client->get('https://httpbin.org/get', ['X-Another-Test' => 'Test2']);
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
$body = json_decode($response->getBody());
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
}
@@ -47,7 +47,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a POST request.", $body->form->{"X-Post-Test"});
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
}
public function testPut()
@@ -63,8 +63,11 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
public function testPatch()
{
$response = $this->client->patch('https://httpbin.org/patch', [],
['X-Patch-Test' => 'Testing a PATCH request.']);
$response = $this->client->patch(
'https://httpbin.org/patch',
[],
['X-Patch-Test' => 'Testing a PATCH request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
@@ -75,14 +78,17 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
public function testDelete()
{
$response = $this->client->delete('https://httpbin.org/delete', [],
['X-Delete-Test' => 'Testing a DELETE request.']);
$response = $this->client->delete(
'https://httpbin.org/delete',
[],
['X-Delete-Test' => 'Testing a DELETE request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a DELETE request.", $body->form->{"X-Delete-Test"});
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
}
public function testErrors()
@@ -124,9 +130,9 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$method->invokeArgs($this->client, [$response]);
}
public function testNotFound() {
public function testNotFound()
{
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
$response = $this->client->get('https://httpbin.org/status/404');
}
}

View File

@@ -5,7 +5,7 @@
* Date: 13/01/2017
* Time: 17:15
*/
class APIKeyTest extends PHPUnit_Framework_TestCase
class APIKeyTest extends TestCase
{
public function testGetHeaders()
{
@@ -19,6 +19,5 @@ class APIKeyTest extends PHPUnit_Framework_TestCase
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
$this->assertEquals(2, sizeof($headers));
}
}

20
tests/Auth/NoneTest.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 20:08
*/
use Cloudflare\API\Auth\None;
class NoneTest extends TestCase
{
public function testGetHeaders()
{
$auth = new \Cloudflare\API\Auth\None();
$headers = $auth->getHeaders();
$this->assertEquals([], $headers);
}
}

View File

@@ -5,7 +5,7 @@
* Date: 13/01/2017
* Time: 18:03
*/
class UserServiceKeyTest extends PHPUnit_Framework_TestCase
class UserServiceKeyTest extends TestCase
{
public function testGetHeaders()
{
@@ -14,10 +14,11 @@ class UserServiceKeyTest extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
$this->assertEquals('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
$headers['X-Auth-User-Service-Key']);
$this->assertEquals(
'v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
$headers['X-Auth-User-Service-Key']
);
$this->assertEquals(1, sizeof($headers));
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 15:24
*/
class ConfigurationsUARulesTest extends TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\UARules();
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ua', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertEquals(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
$array[0]->value
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 18:41
*/
use Cloudflare\API\Configurations\PageRulesTargets;
class PageRulesTargetTest extends TestCase
{
public function testGetArray()
{
$targets = new PageRulesTargets('junade.com/*');
$array = $targets->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
$this->assertEquals("matches", $array[0]->constraint->operator);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:50
*/
class ConfigurationZoneLockdownTest extends TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
$configuration->addIP('1.2.3.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ip', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]->value);
$configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray();
$this->assertEquals(2, sizeof($array));
$this->assertObjectHasAttribute('target', $array[1]);
$this->assertEquals('ip_range', $array[1]->target);
$this->assertObjectHasAttribute('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]->value);
}
}

View File

@@ -1,46 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 15:31
*/
use Cloudflare\API\Endpoints\DNS;
class DNSTest extends PHPUnit_Framework_TestCase
class DNSTest extends TestCase
{
public function testAddRecord()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.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/dns_records'), $this->equalTo([]),
$this->equalTo(['type' => 'A', 'name' => 'example.com', 'content' => '127.0.0.1', 'ttl' => 120, 'proxied' => false])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([]),
$this->equalTo([
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'ttl' => 120,
'proxied' => false
])
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
@@ -49,56 +35,29 @@ class DNSTest extends PHPUnit_Framework_TestCase
public function testListRecords()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.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'),
$this->equalTo([]),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc'
]
));
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'order' => 'type',
'direction' => 'desc']),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353", "A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
@@ -107,36 +66,17 @@ class DNSTest extends PHPUnit_Framework_TestCase
$this->assertEquals(1, $result->result_info->page);
}
public function testGetRecordDetails()
public function testGetDNSRecordDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getDNSRecordDetails.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$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/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
);
@@ -145,4 +85,37 @@ class DNSTest extends PHPUnit_Framework_TestCase
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
}
public function testUpdateDNSRecord()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$details = [
'type' => 'A',
'name' => "example.com",
'content' => "1.2.3.4",
'ttl' => 120,
'proxied' => false,
];
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo($details)
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->updateRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59", $details);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $property }, $value);
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 20:16
*/
use Cloudflare\API\Endpoints\IPs;
class IPsTest extends TestCase
{
public function testListIPs()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listIPs.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('ips'),
$this->equalTo([])
);
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
$ips = $ips->listIPs();
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
}
}

View File

@@ -1,22 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 16:17
*/
namespace Cloudflare\API\Adapter;
use Cloudflare\API\Endpoints\API;
class PageRules implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 19:25
*/
use Cloudflare\API\Adapter\PageRules;
class PageRulesTest extends TestCase
{
public function testCreatePageRule()
{
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
$action = new \Cloudflare\API\Configurations\PageRulesActions();
$action->setAlwaysOnline(true);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.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/pagerules'),
$this->equalTo([]),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
'status' => 'active',
'priority' => 1
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result);
}
public function testListPageRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPageRules.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/pagerules'),
$this->equalTo([
'status' => 'active',
'order' => 'status',
'direction' => 'desc',
'match' => 'all'
]),
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
}
public function testGetPageRuleDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPageRuleDetails.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/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
}
public function testUpdatePageRule()
{
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
$action = new \Cloudflare\API\Configurations\PageRulesActions();
$action->setAlwaysOnline(true);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([]),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
'status' => 'active',
'priority' => 1
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result);
}
public function testDeletePageRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePageRule.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/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([]),
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertTrue($result);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 19/09/2017
* Time: 15:19
*/
use Cloudflare\API\Endpoints\UARules;
class UARulesTest extends TestCase
{
public function testListRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRules.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/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
public function testCreateRule()
{
$config = new \Cloudflare\API\Configurations\UARules();
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRule.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/ua_rules'),
$this->equalTo([]),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->createRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'js_challenge',
$config,
'372e67954025e0ba6aaa6d586b9e0b59',
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
);
}
public function getRuleDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRuleDetails.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/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
);
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
}
public function testUpdateRule()
{
$config = new \Cloudflare\API\Configurations\UARules();
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRule.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/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->updateRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
'js_challenge',
$config,
'Restrict access to these endpoints to requests from a known IP address'
);
}
public function testDeleteRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRule.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/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
}
}

View File

@@ -5,30 +5,12 @@
* Date: 01/02/2017
* Time: 12:50
*/
class UserTest extends PHPUnit_Framework_TestCase
class UserTest extends TestCase
{
public function testGetUserDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
@@ -43,26 +25,8 @@ class UserTest extends PHPUnit_Framework_TestCase
public function testGetUserID()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
@@ -72,26 +36,8 @@ class UserTest extends PHPUnit_Framework_TestCase
public function testGetUserEmail()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
@@ -103,26 +49,8 @@ class UserTest extends PHPUnit_Framework_TestCase
public function testUpdateUserDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);

View File

@@ -0,0 +1,146 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 21:23
*/
class ZoneLockdownTest extends TestCase
{
public function testListLockdowns()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLockdowns.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/lockdowns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
public function testAddLockdown()
{
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addLockdown.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/lockdowns'),
$this->equalTo([]),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->createLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
["api.mysite.com/some/endpoint*"],
$config,
'372e67954025e0ba6aaa6d586b9e0b59',
'Restrict access to these endpoints to requests from a known IP address'
);
}
public function testGetRecordDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordDetails.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/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
);
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
}
public function testUpdateLockdown()
{
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLockdown.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/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->updateLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
["api.mysite.com/some/endpoint*"],
$config,
'Restrict access to these endpoints to requests from a known IP address'
);
}
public function testDeleteLockdown()
{
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLockdown.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/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
}
}

View File

@@ -1,78 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 06/06/2017
* Time: 16:01
*/
use Cloudflare\API\Endpoints\Zones;
class ZonesTest extends PHPUnit_Framework_TestCase
class ZonesTest extends TestCase
{
public function testAddZone()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.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'),
->with(
$this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
);
@@ -83,7 +29,8 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$this->assertObjectHasAttribute("id", $result);
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id);
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
@@ -92,7 +39,8 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones'),
->with(
$this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org])
);
@@ -103,21 +51,15 @@ class ZonesTest extends PHPUnit_Framework_TestCase
public function testActivationTest()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.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/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
$this->equalTo([]),
$this->equalTo([])
);
@@ -130,86 +72,26 @@ class ZonesTest extends PHPUnit_Framework_TestCase
public function testListZones()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listZones.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'),
$this->equalTo([]),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc'
]
));
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
@@ -223,83 +105,23 @@ class ZonesTest extends PHPUnit_Framework_TestCase
public function testGetZoneID()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneId.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'),
$this->equalTo([]),
$this->equalTo([
'name' => 'example.com',
'page' => 1,
'per_page' => 20,
'match' => 'all'
]
));
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneID("example.com");
@@ -307,29 +129,23 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
}
public function testPurgeAll()
public function testCachePurgeEverything()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.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/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo([]),
$this->equalTo(["purge_everything" => true])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->purgeAll("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$this->assertTrue($result);
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}

View File

@@ -0,0 +1,54 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,31 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59"
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac"
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59"
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}

View File

@@ -0,0 +1,31 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,22 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}

View File

@@ -0,0 +1,62 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,13 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"ipv4_cidrs": [
"199.27.128.0/21"
],
"ipv6_cidrs": [
"2400:cb00::/32"
]
}
}

View File

@@ -0,0 +1,26 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,39 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,28 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,26 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,62 @@
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,24 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}

View File

@@ -0,0 +1,22 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}

View File

@@ -0,0 +1,31 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}

41
tests/TestCase.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
use GuzzleHttp\Psr7;
abstract class TestCase extends PHPUnit_Framework_TestCase
{
/**
* Returns a PSR7 Stream for a given fixture.
*
* @param string $fixture The fixture to create the stream for.
* @return Psr7Stream
*/
protected function getPsr7StreamForFixture($fixture): Psr7\Stream
{
$path = sprintf('%s/Fixtures/%s', __DIR__, $fixture);
$this->assertFileExists($path);
$stream = Psr7\stream_for(file_get_contents($path));
$this->assertInstanceOf(Psr7\Stream::class, $stream);
return $stream;
}
/**
* Returns a PSR7 Response (JSON) for a given fixture.
*
* @param string $fixture The fixture to create the response for.
* @param integer $statusCode A HTTP Status Code for the response.
* @return Psr7Response
*/
protected function getPsr7JsonResponseForFixture($fixture, $statusCode = 200): Psr7\Response
{
$stream = $this->getPsr7StreamForFixture($fixture);
$this->assertNotNull(json_decode($stream));
$this->assertEquals(JSON_ERROR_NONE, json_last_error());
return new Psr7\Response($statusCode, ['Content-Type' => 'application/json'], $stream);
}
}