Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1cf1ae41f | ||
|
|
70ee68f755 | ||
|
|
566ab3fc70 | ||
|
|
ca80e2c388 | ||
|
|
d49028a31e | ||
|
|
a5384b7466 | ||
|
|
8ffd3e3541 | ||
|
|
3ce5e1911f | ||
|
|
1226d35472 | ||
|
|
cebeae15a3 | ||
|
|
db62f1db8a | ||
|
|
b7e70655ce | ||
|
|
49ed1c9e8f | ||
|
|
68a26e7e77 | ||
|
|
b4a13d8e2b | ||
|
|
a80747ee06 | ||
|
|
fbb5aac074 | ||
|
|
471227b96f | ||
|
|
4d17609641 | ||
|
|
feecc9fcbb | ||
|
|
589766e008 | ||
|
|
2faff272df | ||
|
|
90196ea836 | ||
|
|
80c611691b | ||
|
|
85385dedf5 |
15
.php_cs
Normal file
15
.php_cs
Normal 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)
|
||||
;
|
||||
@@ -11,4 +11,5 @@ install:
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- composer test
|
||||
- make lint
|
||||
- make test
|
||||
|
||||
15
Makefile
Normal file
15
Makefile
Normal 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
|
||||
@@ -31,9 +31,9 @@ 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();
|
||||
```
|
||||
|
||||
@@ -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
1826
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -72,4 +72,4 @@ interface Adapter
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(String $uri, array $headers, array $body): ResponseInterface;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
|
||||
use Cloudflare\API\Auth\Auth;
|
||||
use GuzzleHttp\Client;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@@ -38,21 +37,22 @@ class Guzzle implements Adapter
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(String $uri, array $query = array(), array $headers = array()): ResponseInterface
|
||||
public function get(String $uri, array $query = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$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,
|
||||
'json' => $body
|
||||
]
|
||||
@@ -65,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,
|
||||
'json' => $jsonBody
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
|
||||
@@ -82,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,
|
||||
'json' => $jsonBody
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
|
||||
@@ -99,9 +99,11 @@ 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,
|
||||
'json' => $body
|
||||
]
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
|
||||
class JSONException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
|
||||
class ResponseException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
interface Auth
|
||||
{
|
||||
public function getHeaders(): array;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
class None implements Auth
|
||||
{
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
interface Configurations
|
||||
{
|
||||
public function getArray(): array;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class ConfigurationsException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,73 +10,59 @@ namespace Cloudflare\API\Configurations;
|
||||
|
||||
class PageRulesActions implements Configurations
|
||||
{
|
||||
private $configs = array();
|
||||
private $configs = [];
|
||||
|
||||
public function setAlwaysOnline(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "always_online";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("always_online", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setAlwaysUseHTTPS(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "always_use_https";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("always_use_https", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setBrowserCacheTTL(int $ttl)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "browser_cache_ttl";
|
||||
$object->value = $ttl;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("browser_cache_ttl", [
|
||||
'value' => $ttl
|
||||
]);
|
||||
}
|
||||
|
||||
public function setBrowserIntegrityCheck(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "browser_check";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("browser_check", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setBypassCacheOnCookie(bool $value)
|
||||
public function setBypassCacheOnCookie(string $value)
|
||||
{
|
||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||
throw new ConfigurationsException("Invalid cookie string.");
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "bypass_cache_on_cookie";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("bypass_cache_on_cookie", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setCacheByDeviceType(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "cache_by_device_type";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("cache_by_device_type", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setCacheKey(string $value)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "cache_key";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("cache_key", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setCacheLevel(string $value)
|
||||
@@ -85,51 +71,41 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException("Invalid cache level");
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "cache_level";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("cache_level", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setCacheOnCookie(bool $value)
|
||||
public function setCacheOnCookie(string $value)
|
||||
{
|
||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||
throw new ConfigurationsException("Invalid cookie string.");
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "cache_on_cookie";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("cache_on_cookie", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setDisableApps(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "disable_apps";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("disable_apps", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setDisablePerformance(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "disable_performance";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("disable_performance", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setDisableSecurity(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "disable_security";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("disable_security", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setEdgeCacheTTL(int $value)
|
||||
@@ -138,135 +114,107 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException("Edge Cache TTL too high.");
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "edge_cache_ttl";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("edge_cache_ttl", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setEmailObfuscation(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "disable_security";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("disable_security", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setForwardingURL(int $statusCode, string $forwardingUrl)
|
||||
{
|
||||
if (in_array($statusCode, ['301', '302'])) {
|
||||
if (!in_array($statusCode, ['301', '302'])) {
|
||||
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "forwarding_url";
|
||||
$object->status_code = $statusCode;
|
||||
$object->url = $forwardingUrl;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("forwarding_url", [
|
||||
'status_code' => $statusCode,
|
||||
'url' => $forwardingUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
public function setHostHeaderOverride(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "host_header_override";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("host_header_override", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setHotlinkProtection(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "hotlink_protection";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("hotlink_protection", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setIPGeoLocationHeader(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "ip_geolocation";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("ip_geolocation", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setMinification(bool $html, bool $css, bool $js)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "minification";
|
||||
$object->html = $html === true ? "on" : "off";
|
||||
$object->css = $css === true ? "on" : "off";
|
||||
$object->js = $js === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("minification", [
|
||||
'html' => $this->getBoolAsOnOrOff($html),
|
||||
'css' => $this->getBoolAsOnOrOff($css),
|
||||
'js' => $this->getBoolAsOnOrOff($js),
|
||||
]);
|
||||
}
|
||||
|
||||
public function setMirage(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "mirage";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("mirage", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setOriginErrorPagePassthru(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "origin_error_page_pass_thru";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("origin_error_page_pass_thru", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setQueryStringSort(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "sort_query_string_for_cache";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("sort_query_string_for_cache", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setDisableRailgun(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "disable_railgun";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("disable_railgun", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setResolveOverride(bool $value)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "resolve_override";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("resolve_override", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setRespectStrongEtag(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "respect_strong_etag";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("respect_strong_etag", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setResponseBuffering(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "response_buffering";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("response_buffering", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setRocketLoader(string $value)
|
||||
@@ -275,11 +223,9 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "rocket_loader";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("rocket_loader", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setSecurityLevel(string $value)
|
||||
@@ -288,29 +234,23 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "security_level";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("security_level", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setServerSideExcludes(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "server_side_exclude";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("server_side_exclude", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setSmartErrors(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "smart_errors";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("smart_errors", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setSSL(string $value)
|
||||
@@ -319,51 +259,53 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||
}
|
||||
|
||||
$object = new \stdClass();
|
||||
$object->id = "smart_errors";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("smart_errors", [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
public function setTrueClientIpHeader(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "true_client_ip_header";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("true_client_ip_header", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setWAF(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "waf";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("waf", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setAutomatedHTTPSRewrites(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "automatic_https_rewrites";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$this->addConfigurationOption("automatic_https_rewrites", [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setOpportunisticEncryption(bool $active)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = "opportunistic_encryption";
|
||||
$object->value = $active === true ? "on" : "off";
|
||||
|
||||
array_push($this->configs, $object);
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class PageRulesTargets implements Configurations
|
||||
{
|
||||
private $targets;
|
||||
@@ -28,4 +27,4 @@ class PageRulesTargets implements Configurations
|
||||
{
|
||||
return $this->targets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class UARules implements Configurations
|
||||
{
|
||||
private $configs = array();
|
||||
private $configs = [];
|
||||
|
||||
public function addUA(string $value)
|
||||
{
|
||||
@@ -26,4 +25,4 @@ class UARules implements Configurations
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class ZoneLockdown implements Configurations
|
||||
{
|
||||
private $configs = array();
|
||||
private $configs = [];
|
||||
|
||||
public function addIP(string $value)
|
||||
{
|
||||
@@ -35,4 +34,4 @@ class ZoneLockdown implements Configurations
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
interface API
|
||||
{
|
||||
public function __construct(Adapter $adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,5 +121,4 @@ class DNS implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
class EndpointException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class IPs implements API
|
||||
@@ -20,10 +19,11 @@ class IPs implements API
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function listIPs(): \stdClass {
|
||||
public function listIPs(): \stdClass
|
||||
{
|
||||
$ips = $this->adapter->get('ips', [], []);
|
||||
$body = json_decode($ips->getBody());
|
||||
|
||||
return $body->result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Configurations\PageRulesActions;
|
||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||
@@ -146,4 +145,4 @@ class PageRules implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ class UARules implements API
|
||||
string $id = null,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'mode' => $mode,
|
||||
'configurations' => $configuration->getArray()
|
||||
@@ -85,7 +84,6 @@ class UARules implements API
|
||||
\Cloudflare\API\Configurations\UARules $configuration,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'mode' => $mode,
|
||||
'id' => $ruleID,
|
||||
@@ -119,4 +117,4 @@ class UARules implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class User implements API
|
||||
@@ -41,4 +40,4 @@ class User implements API
|
||||
$response = $this->adapter->patch("user", [], $details);
|
||||
return json_decode($response->getBody());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ class ZoneLockdown implements API
|
||||
string $id = null,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'urls' => $urls,
|
||||
'configurations' => $configuration->getArray()
|
||||
@@ -85,7 +84,6 @@ class ZoneLockdown implements API
|
||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'urls' => $urls,
|
||||
'id' => $lockdownID,
|
||||
@@ -119,4 +117,4 @@ class ZoneLockdown implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class GuzzleTest extends PHPUnit_Framework_TestCase
|
||||
class GuzzleTest extends TestCase
|
||||
{
|
||||
private $client;
|
||||
|
||||
@@ -58,25 +58,31 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
||||
|
||||
$body = json_decode($response->getBody());
|
||||
$this->assertEquals("Testing a PUT request.", json_decode($body->json)->{"X-Put-Test"});
|
||||
$this->assertEquals("Testing a PUT request.", $body->json->{"X-Put-Test"});
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
$body = json_decode($response->getBody());
|
||||
$this->assertEquals("Testing a PATCH request.", json_decode($body->json)->{"X-Patch-Test"});
|
||||
$this->assertEquals("Testing a PATCH request.", $body->json->{"X-Patch-Test"});
|
||||
}
|
||||
|
||||
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]);
|
||||
@@ -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');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
use Cloudflare\API\Auth\None;
|
||||
|
||||
class NoneTest extends PHPUnit_Framework_TestCase
|
||||
class NoneTest extends TestCase
|
||||
{
|
||||
public function testGetHeaders()
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Date: 19/09/2017
|
||||
* Time: 15:24
|
||||
*/
|
||||
class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
||||
class ConfigurationsUARulesTest extends TestCase
|
||||
{
|
||||
public function testGetArray()
|
||||
{
|
||||
@@ -19,7 +19,9 @@ class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
||||
$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);
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
|
||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||
|
||||
class PageRulesTargetTest extends PHPUnit_Framework_TestCase
|
||||
class PageRulesTargetTest extends TestCase
|
||||
{
|
||||
public function testGetArray() {
|
||||
public function testGetArray()
|
||||
{
|
||||
$targets = new PageRulesTargets('junade.com/*');
|
||||
$array = $targets->getArray();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Date: 05/09/2017
|
||||
* Time: 13:50
|
||||
*/
|
||||
class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
class ConfigurationZoneLockdownTest extends TestCase
|
||||
{
|
||||
public function testGetArray()
|
||||
{
|
||||
|
||||
@@ -6,38 +6,20 @@
|
||||
* Date: 09/06/2017
|
||||
* Time: 15:31
|
||||
*/
|
||||
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([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'type' => 'A',
|
||||
'name' => 'example.com',
|
||||
@@ -53,42 +35,15 @@ 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 = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.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'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
@@ -102,7 +57,7 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353","A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
|
||||
$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);
|
||||
@@ -111,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([])
|
||||
);
|
||||
|
||||
@@ -149,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,30 +8,20 @@
|
||||
|
||||
use Cloudflare\API\Endpoints\IPs;
|
||||
|
||||
class IPsTest extends PHPUnit_Framework_TestCase
|
||||
class IPsTest extends TestCase
|
||||
{
|
||||
public function testListIPs() {
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"ipv4_cidrs": [
|
||||
"199.27.128.0/21"
|
||||
],
|
||||
"ipv6_cidrs": [
|
||||
"2400:cb00::/32"
|
||||
]
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
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([])
|
||||
->with(
|
||||
$this->equalTo('ips'),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||
|
||||
@@ -8,52 +8,24 @@
|
||||
|
||||
use Cloudflare\API\Adapter\PageRules;
|
||||
|
||||
class PageRulesTest extends PHPUnit_Framework_TestCase
|
||||
class PageRulesTest extends TestCase
|
||||
{
|
||||
public function testCreatePageRule()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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"
|
||||
}
|
||||
}');
|
||||
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||
$action->setAlwaysOnline(true);
|
||||
|
||||
$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);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'targets' => $target->getArray(),
|
||||
'actions' => $action->getArray(),
|
||||
@@ -70,53 +42,15 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testListPageRules()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPageRules.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/pagerules'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||
$this->equalTo([
|
||||
'status' => 'active',
|
||||
'order' => 'status',
|
||||
@@ -132,45 +66,16 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetPageRuleDetails()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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"
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPageRuleDetails.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/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([])
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||
@@ -179,48 +84,20 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUpdatePageRule()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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"
|
||||
}
|
||||
}');
|
||||
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||
$action->setAlwaysOnline(true);
|
||||
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'targets' => $target->getArray(),
|
||||
'actions' => $action->getArray(),
|
||||
@@ -237,26 +114,16 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDeletePageRule()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "9a7806061c88ada191ed06f989cc3dac"
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePageRule.json');
|
||||
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
|
||||
@@ -8,44 +8,19 @@
|
||||
|
||||
use Cloudflare\API\Endpoints\UARules;
|
||||
|
||||
class UARulesTest extends PHPUnit_Framework_TestCase
|
||||
class UARulesTest extends TestCase
|
||||
{
|
||||
public function testListRules()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRules.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/firewall/ua_rules'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20
|
||||
@@ -68,32 +43,16 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
||||
$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');
|
||||
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'js_challenge',
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -103,39 +62,26 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||
$ld->createRule('023e105f4ecef8ad9ca31a8372d0c353', 'js_challenge', $config,
|
||||
$ld->createRule(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'js_challenge',
|
||||
$config,
|
||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack');
|
||||
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
|
||||
);
|
||||
}
|
||||
|
||||
public function getRuleDetails()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRuleDetails.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/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
@@ -150,32 +96,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
||||
$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');
|
||||
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'js_challenge',
|
||||
@@ -186,32 +115,26 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$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');
|
||||
$ld->updateRule(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||
'js_challenge',
|
||||
$config,
|
||||
'Restrict access to these endpoints to requests from a known IP address'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeleteRule()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -6,44 +6,19 @@
|
||||
* Date: 04/09/2017
|
||||
* Time: 21:23
|
||||
*/
|
||||
class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
class ZoneLockdownTest extends TestCase
|
||||
{
|
||||
public function testListLockdowns()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLockdowns.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/firewall/lockdowns'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
@@ -66,32 +41,16 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||
$config->addIP('1.2.3.4');
|
||||
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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([]),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -101,43 +60,26 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||
$ld->createLockdown('023e105f4ecef8ad9ca31a8372d0c353', ["api.mysite.com/some/endpoint*"], $config,
|
||||
$ld->createLockdown(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
["api.mysite.com/some/endpoint*"],
|
||||
$config,
|
||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||
'Restrict access to these endpoints to requests from a known IP address');
|
||||
'Restrict access to these endpoints to requests from a known IP address'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetRecordDetails()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}');
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordDetails.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/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
@@ -152,36 +94,15 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||
$config->addIP('1.2.3.4');
|
||||
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
||||
@@ -192,9 +113,13 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$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');
|
||||
$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()
|
||||
@@ -202,26 +127,15 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||
$config->addIP('1.2.3.4');
|
||||
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$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'),
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
@@ -6,71 +6,19 @@
|
||||
* Date: 06/06/2017
|
||||
* Time: 16:01
|
||||
*/
|
||||
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])
|
||||
);
|
||||
@@ -81,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);
|
||||
|
||||
@@ -90,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])
|
||||
);
|
||||
@@ -101,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([])
|
||||
);
|
||||
@@ -128,75 +72,15 @@ 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'),
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
@@ -221,75 +105,15 @@ 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'),
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
@@ -307,21 +131,15 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
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])
|
||||
);
|
||||
|
||||
8
tests/Fixtures/Endpoints/activationTest.json
Normal file
8
tests/Fixtures/Endpoints/activationTest.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/addLockdown.json
Normal file
18
tests/Fixtures/Endpoints/addLockdown.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
20
tests/Fixtures/Endpoints/addRecord.json
Normal file
20
tests/Fixtures/Endpoints/addRecord.json
Normal 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": {}
|
||||
}
|
||||
}
|
||||
54
tests/Fixtures/Endpoints/addZone.json
Normal file
54
tests/Fixtures/Endpoints/addZone.json
Normal 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"
|
||||
}
|
||||
}
|
||||
8
tests/Fixtures/Endpoints/cachePurgeEverything.json
Normal file
8
tests/Fixtures/Endpoints/cachePurgeEverything.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}
|
||||
31
tests/Fixtures/Endpoints/createPageRule.json
Normal file
31
tests/Fixtures/Endpoints/createPageRule.json
Normal 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"
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/createRule.json
Normal file
18
tests/Fixtures/Endpoints/createRule.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
tests/Fixtures/Endpoints/deleteLockdown.json
Normal file
12
tests/Fixtures/Endpoints/deleteLockdown.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||
}
|
||||
}
|
||||
12
tests/Fixtures/Endpoints/deletePageRule.json
Normal file
12
tests/Fixtures/Endpoints/deletePageRule.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "9a7806061c88ada191ed06f989cc3dac"
|
||||
}
|
||||
}
|
||||
12
tests/Fixtures/Endpoints/deleteRule.json
Normal file
12
tests/Fixtures/Endpoints/deleteRule.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||
}
|
||||
}
|
||||
20
tests/Fixtures/Endpoints/getDNSRecordDetails.json
Normal file
20
tests/Fixtures/Endpoints/getDNSRecordDetails.json
Normal 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": {}
|
||||
}
|
||||
}
|
||||
31
tests/Fixtures/Endpoints/getPageRuleDetails.json
Normal file
31
tests/Fixtures/Endpoints/getPageRuleDetails.json
Normal 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"
|
||||
}
|
||||
}
|
||||
22
tests/Fixtures/Endpoints/getRecordDetails.json
Normal file
22
tests/Fixtures/Endpoints/getRecordDetails.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/getRuleDetails.json
Normal file
18
tests/Fixtures/Endpoints/getRuleDetails.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/getUserDetails.json
Normal file
18
tests/Fixtures/Endpoints/getUserDetails.json
Normal 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
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/getUserEmail.json
Normal file
18
tests/Fixtures/Endpoints/getUserEmail.json
Normal 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
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/getUserId.json
Normal file
18
tests/Fixtures/Endpoints/getUserId.json
Normal 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
|
||||
}
|
||||
}
|
||||
62
tests/Fixtures/Endpoints/getZoneId.json
Normal file
62
tests/Fixtures/Endpoints/getZoneId.json
Normal 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
|
||||
}
|
||||
}
|
||||
13
tests/Fixtures/Endpoints/listIPs.json
Normal file
13
tests/Fixtures/Endpoints/listIPs.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"ipv4_cidrs": [
|
||||
"199.27.128.0/21"
|
||||
],
|
||||
"ipv6_cidrs": [
|
||||
"2400:cb00::/32"
|
||||
]
|
||||
}
|
||||
}
|
||||
26
tests/Fixtures/Endpoints/listLockdowns.json
Normal file
26
tests/Fixtures/Endpoints/listLockdowns.json
Normal 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
|
||||
}
|
||||
}
|
||||
39
tests/Fixtures/Endpoints/listPageRules.json
Normal file
39
tests/Fixtures/Endpoints/listPageRules.json
Normal 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
|
||||
}
|
||||
}
|
||||
28
tests/Fixtures/Endpoints/listRecords.json
Normal file
28
tests/Fixtures/Endpoints/listRecords.json
Normal 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
|
||||
}
|
||||
}
|
||||
26
tests/Fixtures/Endpoints/listRules.json
Normal file
26
tests/Fixtures/Endpoints/listRules.json
Normal 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
|
||||
}
|
||||
}
|
||||
62
tests/Fixtures/Endpoints/listZones.json
Normal file
62
tests/Fixtures/Endpoints/listZones.json
Normal 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
|
||||
}
|
||||
}
|
||||
24
tests/Fixtures/Endpoints/updateDNSRecord.json
Normal file
24
tests/Fixtures/Endpoints/updateDNSRecord.json
Normal 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": {}
|
||||
}
|
||||
}
|
||||
22
tests/Fixtures/Endpoints/updateLockdown.json
Normal file
22
tests/Fixtures/Endpoints/updateLockdown.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
31
tests/Fixtures/Endpoints/updatePageRule.json
Normal file
31
tests/Fixtures/Endpoints/updatePageRule.json
Normal 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"
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/updateRule.json
Normal file
18
tests/Fixtures/Endpoints/updateRule.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/updateUserDetails.json
Normal file
18
tests/Fixtures/Endpoints/updateUserDetails.json
Normal 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
41
tests/TestCase.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user