Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4ddb61d2a | ||
|
|
3166645a0c | ||
|
|
1658f4abcc | ||
|
|
1e8c8d6019 | ||
|
|
1b5d0273ed | ||
|
|
7d0c0c86dc | ||
|
|
53cbd9d578 | ||
|
|
4876787118 | ||
|
|
938172c17b | ||
|
|
7a60774ec2 | ||
|
|
5266b2c2af | ||
|
|
696a36d682 | ||
|
|
91dbd38824 |
@@ -3,7 +3,6 @@ language: php
|
|||||||
php:
|
php:
|
||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- nightly
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- composer self-update
|
- composer self-update
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,5 +1,7 @@
|
|||||||
# Cloudflare SDK (v4 API Binding for PHP 7)
|
# Cloudflare SDK (v4 API Binding for PHP 7)
|
||||||
|
|
||||||
|
[](https://travis-ci.org/cloudflare/cloudflare-php)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The recommended way to install this package is via the Packagist Dependency Manager.
|
The recommended way to install this package is via the Packagist Dependency Manager.
|
||||||
@@ -10,14 +12,15 @@ The Cloudflare API can be found [here](https://api.cloudflare.com/).
|
|||||||
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
|
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
|
||||||
|
|
||||||
|
|
||||||
- [x] DNS Records
|
- [x] [DNS Records](https://www.cloudflare.com/dns/)
|
||||||
- [x] Zones
|
- [x] Zones
|
||||||
- [x] User Administration (partial)
|
- [x] User Administration (partial)
|
||||||
- [ ] Cloudflare IPs
|
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
|
||||||
- [ ] Page Rules
|
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
||||||
- [ ] Web Application Firewall (WAF)
|
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
||||||
- [ ] Virtual DNS Management
|
- [ ] Virtual DNS Management
|
||||||
- [ ] Custom hostnames
|
- [ ] Custom hostnames
|
||||||
|
- [x] Zone Lockdown and User-Agent Block rules
|
||||||
- [ ] Organization Administration
|
- [ ] Organization Administration
|
||||||
- [ ] [Railgun](https://www.cloudflare.com/railgun/) administration
|
- [ ] [Railgun](https://www.cloudflare.com/railgun/) administration
|
||||||
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
|
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI = "https://api.cloudflare.com/client/v4/")
|
public function __construct(Auth $auth, String $baseURI = null)
|
||||||
{
|
{
|
||||||
|
if ($baseURI === null) {
|
||||||
|
$baseURI = "https://api.cloudflare.com/client/v4/";
|
||||||
|
}
|
||||||
|
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
$this->client = new Client([
|
$this->client = new Client([
|
||||||
@@ -50,7 +54,7 @@ class Guzzle implements Adapter
|
|||||||
{
|
{
|
||||||
$response = $this->client->post($uri, [
|
$response = $this->client->post($uri, [
|
||||||
'headers' => $headers,
|
'headers' => $headers,
|
||||||
'form_params' => $body
|
'json' => $body
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -125,4 +129,4 @@ class Guzzle implements Adapter
|
|||||||
throw new ResponseException("Request was unsuccessful.");
|
throw new ResponseException("Request was unsuccessful.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/Auth/None.php
Normal file
18
src/Auth/None.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 19:55
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
|
class None implements Auth
|
||||||
|
{
|
||||||
|
public function getHeaders(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/Configurations/Configurations.php
Normal file
15
src/Configurations/Configurations.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 15:23
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
|
interface Configurations
|
||||||
|
{
|
||||||
|
public function getArray(): array;
|
||||||
|
}
|
||||||
15
src/Configurations/ConfigurationsException.php
Normal file
15
src/Configurations/ConfigurationsException.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 16:57
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurationsException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
369
src/Configurations/PageRulesActions.php
Normal file
369
src/Configurations/PageRulesActions.php
Normal file
@@ -0,0 +1,369 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 16:50
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class PageRulesActions implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = array();
|
||||||
|
|
||||||
|
public function setAlwaysOnline(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "always_online";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAlwaysUseHTTPS(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "always_use_https";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBrowserCacheTTL(int $ttl)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "browser_cache_ttl";
|
||||||
|
$object->value = $ttl;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBrowserIntegrityCheck(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "browser_check";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBypassCacheOnCookie(bool $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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCacheKey(string $value)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "cache_key";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCacheLevel(string $value)
|
||||||
|
{
|
||||||
|
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
|
||||||
|
throw new ConfigurationsException("Invalid cache level");
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "cache_level";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCacheOnCookie(bool $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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisableApps(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "disable_apps";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisablePerformance(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "disable_performance";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisableSecurity(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "disable_security";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEdgeCacheTTL(int $value)
|
||||||
|
{
|
||||||
|
if ($value > 2419200) {
|
||||||
|
throw new ConfigurationsException("Edge Cache TTL too high.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "edge_cache_ttl";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmailObfuscation(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "disable_security";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setForwardingURL(int $statusCode, string $forwardingUrl)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHostHeaderOverride(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "host_header_override";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHotlinkProtection(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "hotlink_protection";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIPGeoLocationHeader(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "ip_geolocation";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMirage(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "mirage";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisableRailgun(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "disable_railgun";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResolveOverride(bool $value)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "resolve_override";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRespectStrongEtag(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "respect_strong_etag";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResponseBuffering(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "response_buffering";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRocketLoader(string $value)
|
||||||
|
{
|
||||||
|
if (!in_array($value, ["off", "manual", "automatic"])) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSecurityLevel(string $value)
|
||||||
|
{
|
||||||
|
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
|
||||||
|
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "security_level";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServerSideExcludes(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "server_side_exclude";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSmartErrors(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "smart_errors";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSSL(string $value)
|
||||||
|
{
|
||||||
|
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
|
||||||
|
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "smart_errors";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWAF(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "waf";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAutomatedHTTPSRewrites(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "automatic_https_rewrites";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOpportunisticEncryption(bool $active)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->id = "opportunistic_encryption";
|
||||||
|
$object->value = $active === true ? "on" : "off";
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/Configurations/PageRulesTargets.php
Normal file
31
src/Configurations/PageRulesTargets.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 18:37
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
|
class PageRulesTargets implements Configurations
|
||||||
|
{
|
||||||
|
private $targets;
|
||||||
|
|
||||||
|
public function __construct(string $queryUrl)
|
||||||
|
{
|
||||||
|
$target = new \stdClass();
|
||||||
|
$target->target = 'url';
|
||||||
|
$target->constraint = new \stdClass();
|
||||||
|
$target->constraint->operator = "matches";
|
||||||
|
$target->constraint->value = $queryUrl;
|
||||||
|
|
||||||
|
$this->targets = [$target];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->targets;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Configurations/UARules.php
Normal file
29
src/Configurations/UARules.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 15:22
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
|
class UARules implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = array();
|
||||||
|
|
||||||
|
public function addUA(string $value)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->target = "ua";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/Configurations/ZoneLockdown.php
Normal file
38
src/Configurations/ZoneLockdown.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 05/09/2017
|
||||||
|
* Time: 13:43
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
|
class ZoneLockdown implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = array();
|
||||||
|
|
||||||
|
public function addIP(string $value)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->target = "ip";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addIPRange(string $value)
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->target = "ip_range";
|
||||||
|
$object->value = $value;
|
||||||
|
|
||||||
|
array_push($this->configs, $object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,8 +19,14 @@ class DNS implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRecord(string $zoneID, string $type, string $name, string $content, int $ttl = 0, bool $proxied = true): bool
|
public function addRecord(
|
||||||
{
|
string $zoneID,
|
||||||
|
string $type,
|
||||||
|
string $name,
|
||||||
|
string $content,
|
||||||
|
int $ttl = 0,
|
||||||
|
bool $proxied = true
|
||||||
|
): bool {
|
||||||
$options = [
|
$options = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
@@ -46,6 +52,7 @@ class DNS implements API
|
|||||||
public function listRecords(
|
public function listRecords(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type = "",
|
string $type = "",
|
||||||
|
string $name = "",
|
||||||
string $content = "",
|
string $content = "",
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
@@ -79,7 +86,9 @@ class DNS implements API
|
|||||||
$options['direction'] = $direction;
|
$options['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records', [], $options);
|
$query = http_build_query($options);
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
$result = new \stdClass();
|
||||||
@@ -91,20 +100,20 @@ class DNS implements API
|
|||||||
|
|
||||||
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records/'.$recordID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->put('zones/'.$zoneID.'/dns_records/'.$recordID, [], $details);
|
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
|
||||||
return json_decode($response->getBody());
|
return json_decode($response->getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteRecord(string $zoneID, string $recordID): bool
|
public function deleteRecord(string $zoneID, string $recordID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/'.$zoneID.'/dns_records/'.$recordID, [], []);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
|||||||
29
src/Endpoints/IPs.php
Normal file
29
src/Endpoints/IPs.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 19:56
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class IPs implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listIPs(): \stdClass {
|
||||||
|
$ips = $this->adapter->get('ips', []);
|
||||||
|
$body = json_decode($ips->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
}
|
||||||
155
src/Endpoints/PageRules.php
Normal file
155
src/Endpoints/PageRules.php
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 09/06/2017
|
||||||
|
* Time: 16:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
|
|
||||||
|
class PageRules implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPageRule(
|
||||||
|
string $zoneID,
|
||||||
|
PageRulesTargets $target,
|
||||||
|
PageRulesActions $actions,
|
||||||
|
bool $active = true,
|
||||||
|
int $priority = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'targets' => $target->getArray(),
|
||||||
|
'actions' => $actions->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($active !== null) {
|
||||||
|
$options['active'] = $active == true ? 'active' : 'disabled';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priority !== null) {
|
||||||
|
$options['priority'] = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listPageRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $status = null,
|
||||||
|
string $order = null,
|
||||||
|
string $direction = null,
|
||||||
|
string $match = null
|
||||||
|
): \stdClass {
|
||||||
|
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
|
||||||
|
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
|
||||||
|
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
|
||||||
|
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($match) && !in_array($match, ['all', 'any'])) {
|
||||||
|
throw new EndpointException('Match can only be any or all.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'status' => $status,
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
$query = http_build_query($options);
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules?' . $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
$result = new \stdClass();
|
||||||
|
$result->result = $body->result;
|
||||||
|
$result->result_info = $body->result_info;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
||||||
|
{
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePageRule(
|
||||||
|
string $zoneID,
|
||||||
|
PageRulesTargets $target = null,
|
||||||
|
PageRulesActions $actions = null,
|
||||||
|
bool $active = null,
|
||||||
|
int $priority = null
|
||||||
|
): bool {
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
if ($active !== null) {
|
||||||
|
$options['targets'] = $target->getArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($actions !== null) {
|
||||||
|
$options['actions'] = $actions->getArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($active !== null) {
|
||||||
|
$options['active'] = $active == true ? 'active' : 'disabled';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priority !== null) {
|
||||||
|
$options['priority'] = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletePageRule(string $zoneID, string $ruleID): bool
|
||||||
|
{
|
||||||
|
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
124
src/Endpoints/UARules.php
Normal file
124
src/Endpoints/UARules.php
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 15:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class UARules implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listRules(
|
||||||
|
string $zoneID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20
|
||||||
|
): \stdClass {
|
||||||
|
$options = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
$query = http_build_query($options);
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
$result = new \stdClass();
|
||||||
|
$result->result = $body->result;
|
||||||
|
$result->result_info = $body->result_info;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $mode,
|
||||||
|
\Cloudflare\API\Configurations\Configurations $configuration,
|
||||||
|
string $id = null,
|
||||||
|
string $description = null
|
||||||
|
): bool {
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode,
|
||||||
|
'configurations' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($id !== null) {
|
||||||
|
$options['id'] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$options['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||||
|
{
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
string $mode,
|
||||||
|
\Cloudflare\API\Configurations\UARules $configuration,
|
||||||
|
string $description = null
|
||||||
|
): bool {
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode,
|
||||||
|
'id' => $ruleID,
|
||||||
|
'configurations' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$options['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRule(string $zoneID, string $ruleID): bool
|
||||||
|
{
|
||||||
|
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
124
src/Endpoints/ZoneLockdown.php
Normal file
124
src/Endpoints/ZoneLockdown.php
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 20:33
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class ZoneLockdown implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listLockdowns(
|
||||||
|
string $zoneID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20
|
||||||
|
): \stdClass {
|
||||||
|
$options = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
$query = http_build_query($options);
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
$result = new \stdClass();
|
||||||
|
$result->result = $body->result;
|
||||||
|
$result->result_info = $body->result_info;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createLockdown(
|
||||||
|
string $zoneID,
|
||||||
|
array $urls,
|
||||||
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
|
string $id = null,
|
||||||
|
string $description = null
|
||||||
|
): bool {
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'urls' => $urls,
|
||||||
|
'configurations' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($id !== null) {
|
||||||
|
$options['id'] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$options['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
||||||
|
{
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateLockdown(
|
||||||
|
string $zoneID,
|
||||||
|
string $lockdownID,
|
||||||
|
array $urls,
|
||||||
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
|
string $description = null
|
||||||
|
): bool {
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'urls' => $urls,
|
||||||
|
'id' => $lockdownID,
|
||||||
|
'configurations' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($description !== null) {
|
||||||
|
$options['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
||||||
|
{
|
||||||
|
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
||||||
|
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,7 +80,9 @@ class Zones implements API
|
|||||||
$options['direction'] = $direction;
|
$options['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('zones', [], $options);
|
$query = http_build_query($options);
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones?' . $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
$result = new \stdClass();
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a POST request.", $body->form->{"X-Post-Test"});
|
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPut()
|
public function testPut()
|
||||||
|
|||||||
20
tests/Auth/NoneTest.php
Normal file
20
tests/Auth/NoneTest.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 20:08
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Auth\None;
|
||||||
|
|
||||||
|
class NoneTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testGetHeaders()
|
||||||
|
{
|
||||||
|
$auth = new \Cloudflare\API\Auth\None();
|
||||||
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
|
$this->assertEquals([], $headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/Configurations/ConfigurationsUARulesTest.php
Normal file
25
tests/Configurations/ConfigurationsUARulesTest.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 15:24
|
||||||
|
*/
|
||||||
|
class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testGetArray()
|
||||||
|
{
|
||||||
|
$configuration = new \Cloudflare\API\Configurations\UARules();
|
||||||
|
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertEquals(1, sizeof($array));
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('target', $array[0]);
|
||||||
|
$this->assertEquals('ua', $array[0]->target);
|
||||||
|
$this->assertObjectHasAttribute('value', $array[0]);
|
||||||
|
$this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
|
||||||
|
$array[0]->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
tests/Configurations/PageRulesTargetTest.php
Normal file
21
tests/Configurations/PageRulesTargetTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 18:41
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
|
|
||||||
|
class PageRulesTargetTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testGetArray() {
|
||||||
|
$targets = new PageRulesTargets('junade.com/*');
|
||||||
|
$array = $targets->getArray();
|
||||||
|
|
||||||
|
$this->assertEquals(1, sizeof($array));
|
||||||
|
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
|
||||||
|
$this->assertEquals("matches", $array[0]->constraint->operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
tests/Configurations/ZoneLockdownTest.php
Normal file
34
tests/Configurations/ZoneLockdownTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 05/09/2017
|
||||||
|
* Time: 13:50
|
||||||
|
*/
|
||||||
|
class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testGetArray()
|
||||||
|
{
|
||||||
|
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$configuration->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertEquals(1, sizeof($array));
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('target', $array[0]);
|
||||||
|
$this->assertEquals('ip', $array[0]->target);
|
||||||
|
$this->assertObjectHasAttribute('value', $array[0]);
|
||||||
|
$this->assertEquals('1.2.3.4', $array[0]->value);
|
||||||
|
|
||||||
|
$configuration->addIPRange('1.2.3.4/24');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertEquals(2, sizeof($array));
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('target', $array[1]);
|
||||||
|
$this->assertEquals('ip_range', $array[1]->target);
|
||||||
|
$this->assertObjectHasAttribute('value', $array[1]);
|
||||||
|
$this->assertEquals('1.2.3.4/24', $array[1]->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by PhpStorm.
|
* Created by PhpStorm.
|
||||||
* User: junade
|
* User: junade
|
||||||
* Date: 09/06/2017
|
* Date: 09/06/2017
|
||||||
* Time: 15:31
|
* Time: 15:31
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\DNS;
|
|
||||||
|
|
||||||
class DNSTest extends PHPUnit_Framework_TestCase
|
class DNSTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testAddRecord()
|
public function testAddRecord()
|
||||||
@@ -40,7 +38,13 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->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', 'content' => '127.0.0.1', 'ttl' => 120, 'proxied' => false])
|
$this->equalTo([
|
||||||
|
'type' => 'A',
|
||||||
|
'name' => 'example.com',
|
||||||
|
'content' => '127.0.0.1',
|
||||||
|
'ttl' => 120,
|
||||||
|
'proxied' => false
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
@@ -77,28 +81,19 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
|||||||
"total_count": 2000
|
"total_count": 2000
|
||||||
}
|
}
|
||||||
}');
|
}');
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones'),
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records?page=1&per_page=20&match=all&type=A&name=example.com&content=127.0.0.1&order=type&direction=desc'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([])
|
||||||
$this->equalTo([
|
);
|
||||||
'page' => 1,
|
|
||||||
'per_page' => 20,
|
|
||||||
'match' => 'all',
|
|
||||||
'name' => 'example.com',
|
|
||||||
'status' => 'active',
|
|
||||||
'order' => 'status',
|
|
||||||
'direction' => 'desc'
|
|
||||||
]
|
|
||||||
));
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $zones->listZones("example.com", "active", 1, 20, "status", "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', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|||||||
42
tests/Endpoints/IPsTest.php
Normal file
42
tests/Endpoints/IPsTest.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 20:16
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Endpoints\IPs;
|
||||||
|
|
||||||
|
class IPsTest extends PHPUnit_Framework_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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with($this->equalTo('ips'), $this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||||
|
$ips = $ips->listIPs();
|
||||||
|
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
|
||||||
|
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: junade
|
|
||||||
* Date: 09/06/2017
|
|
||||||
* Time: 16:17
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\API;
|
|
||||||
|
|
||||||
class PageRules implements API
|
|
||||||
{
|
|
||||||
private $adapter;
|
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
|
||||||
{
|
|
||||||
$this->adapter = $adapter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
261
tests/Endpoints/PageRulesTest.php
Normal file
261
tests/Endpoints/PageRulesTest.php
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 19:25
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\PageRules;
|
||||||
|
|
||||||
|
class PageRulesTest extends PHPUnit_Framework_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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'targets' => $target->getArray(),
|
||||||
|
'actions' => $action->getArray(),
|
||||||
|
'active' => 'active',
|
||||||
|
'priority' => '1'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
|
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 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?status=active&order=status&direction=desc&match=all'), $this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
|
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPageRuleDetails()
|
||||||
|
{
|
||||||
|
$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 = 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([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
|
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'targets' => $target->getArray(),
|
||||||
|
'actions' => $action->getArray(),
|
||||||
|
'active' => 'active',
|
||||||
|
'priority' => '1'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
|
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeletePageRule()
|
||||||
|
{
|
||||||
|
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "9a7806061c88ada191ed06f989cc3dac"
|
||||||
|
}
|
||||||
|
}');
|
||||||
|
|
||||||
|
$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([]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
|
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
218
tests/Endpoints/UARulesTest.php
Normal file
218
tests/Endpoints/UARulesTest.php
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 19/09/2017
|
||||||
|
* Time: 15:19
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Endpoints\UARules;
|
||||||
|
|
||||||
|
class UARulesTest extends PHPUnit_Framework_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 = 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?page=1&per_page=20'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRule()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\UARules();
|
||||||
|
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'js_challenge',
|
||||||
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'description' => 'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack',
|
||||||
|
'configurations' => $config->getArray(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
$ld->createRule('023e105f4ecef8ad9ca31a8372d0c353', 'js_challenge', $config,
|
||||||
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRuleDetails()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
||||||
|
|
||||||
|
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateRule()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\UARules();
|
||||||
|
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'js_challenge',
|
||||||
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
|
'configurations' => $config->getArray(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
$ld->updateRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'js_challenge', $config,
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteRule()
|
||||||
|
{
|
||||||
|
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||||
|
}
|
||||||
|
}');
|
||||||
|
$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/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
}
|
||||||
|
}
|
||||||
228
tests/Endpoints/ZoneLockdownTest.php
Normal file
228
tests/Endpoints/ZoneLockdownTest.php
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 04/09/2017
|
||||||
|
* Time: 21:23
|
||||||
|
*/
|
||||||
|
class ZoneLockdownTest extends PHPUnit_Framework_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 = 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?page=1&per_page=20'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
|
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddLockdown()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'urls' => ["api.mysite.com/some/endpoint*"],
|
||||||
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
|
'configurations' => $config->getArray(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
|
$ld->createLockdown('023e105f4ecef8ad9ca31a8372d0c353', ["api.mysite.com/some/endpoint*"], $config,
|
||||||
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetRecordDetails()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
|
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
||||||
|
|
||||||
|
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateLockdown()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'urls' => ["api.mysite.com/some/endpoint*"],
|
||||||
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
|
'configurations' => $config->getArray(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
|
$ld->updateLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
["api.mysite.com/some/endpoint*"], $config,
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteLockdown()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$stream = GuzzleHttp\Psr7\stream_for('
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
||||||
|
}
|
||||||
|
}');
|
||||||
|
$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/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
|
$ld->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by PhpStorm.
|
* Created by PhpStorm.
|
||||||
* User: junade
|
* User: junade
|
||||||
* Date: 06/06/2017
|
* Date: 06/06/2017
|
||||||
* Time: 16:01
|
* Time: 16:01
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\Zones;
|
|
||||||
|
|
||||||
class ZonesTest extends PHPUnit_Framework_TestCase
|
class ZonesTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testAddZone()
|
public function testAddZone()
|
||||||
@@ -198,18 +196,9 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones'),
|
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com&status=active&order=status&direction=desc'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([])
|
||||||
$this->equalTo([
|
);
|
||||||
'page' => 1,
|
|
||||||
'per_page' => 20,
|
|
||||||
'match' => 'all',
|
|
||||||
'name' => 'example.com',
|
|
||||||
'status' => 'active',
|
|
||||||
'order' => 'status',
|
|
||||||
'direction' => 'desc'
|
|
||||||
]
|
|
||||||
));
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
|
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
|
||||||
@@ -291,15 +280,9 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones'),
|
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([])
|
||||||
$this->equalTo([
|
);
|
||||||
'name' => 'example.com',
|
|
||||||
'page' => 1,
|
|
||||||
'per_page' => 20,
|
|
||||||
'match' => 'all'
|
|
||||||
]
|
|
||||||
));
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->getZoneID("example.com");
|
$result = $zones->getZoneID("example.com");
|
||||||
|
|||||||
Reference in New Issue
Block a user