Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd2fd73cc3 | ||
|
|
bd83c6d48a | ||
|
|
4e3d307bdd | ||
|
|
99d89e7dc3 | ||
|
|
55e81fe02c | ||
|
|
d00a1d3f44 | ||
|
|
c8e85d2582 | ||
|
|
ff42f334a5 | ||
|
|
dfa299c895 | ||
|
|
e1864a6824 | ||
|
|
c9d21466aa | ||
|
|
b15b4ecc51 | ||
|
|
0aa9f6c05a | ||
|
|
a09478eb2f | ||
|
|
f6cb9a8e30 | ||
|
|
bc9e15a557 | ||
|
|
5caae74370 | ||
|
|
ee4a42ea06 | ||
|
|
90eaea7be2 | ||
|
|
dac1e15e2d | ||
|
|
a4224265d8 | ||
|
|
4f3f82b1ba | ||
|
|
7c9ea4874d | ||
|
|
0920fc48b2 | ||
|
|
65e4f29bc0 | ||
|
|
3453e44158 | ||
|
|
8ee1bbcc6f | ||
|
|
d8b2093eed | ||
|
|
3cfaed1019 | ||
|
|
84ee7302ca | ||
|
|
f088c67314 | ||
|
|
30fc22aa5b | ||
|
|
0d89f13f9b | ||
|
|
ca9e5bbc28 | ||
|
|
f0213ecf92 | ||
|
|
b4a6237509 | ||
|
|
a909f3780e | ||
|
|
e1cf1ae41f | ||
|
|
70ee68f755 | ||
|
|
566ab3fc70 | ||
|
|
ca80e2c388 | ||
|
|
d49028a31e | ||
|
|
6a76e1cc3c | ||
|
|
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
|
- travis_retry composer install --no-interaction --prefer-source
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- composer test
|
- make lint
|
||||||
|
- make test
|
||||||
|
|||||||
17
CONTRIBUTING.md
Normal file
17
CONTRIBUTING.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Contributing to Cloudflare PHP API Binding
|
||||||
|
|
||||||
|
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
|
||||||
|
|
||||||
|
## How To Contribute
|
||||||
|
|
||||||
|
We welcome community contribution to this repository. To help add functionality or address issues, please take the following steps:
|
||||||
|
|
||||||
|
* Fork the repository from the master branch.
|
||||||
|
* Create a new branch for your features / fixes.
|
||||||
|
* Make the changes you wish to see.
|
||||||
|
* Add tests for all changes.
|
||||||
|
* Run `make fix` command to ensure the code is styled.
|
||||||
|
* Run `make test` command to ensure the tests pass.
|
||||||
|
* Create a pull request with details of what changes have been made and explanation of new behaviour.
|
||||||
|
* Ensure documentation contains the correct information.
|
||||||
|
* Pull requests will be reviewed and hopefully merged into a release.
|
||||||
17
Makefile
Normal file
17
Makefile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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
|
||||||
|
php $(HERE)/vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||||
|
php $(HERE)/vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||||
|
|
||||||
|
test:
|
||||||
|
php $(HERE)/vendor/bin/phpunit --configuration $(HERE)/phpunit.xml
|
||||||
13
README.md
13
README.md
@@ -11,18 +11,17 @@ The recommended way to install this package is via the Packagist Dependency Mana
|
|||||||
The Cloudflare API can be found [here](https://api.cloudflare.com/).
|
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](https://www.cloudflare.com/dns/)
|
- [x] [DNS Records](https://www.cloudflare.com/dns/)
|
||||||
- [x] Zones
|
- [x] Zones
|
||||||
- [x] User Administration (partial)
|
- [x] User Administration (partial)
|
||||||
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
|
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
|
||||||
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
||||||
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
- [x] [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
|
- [x] Zone Lockdown and User-Agent Block rules
|
||||||
- [ ] Organization Administration
|
- [ ] Organization Administration
|
||||||
- [ ] [Railgun](https://www.cloudflare.com/railgun/) administration
|
- [x] [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/)
|
||||||
- [ ] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/)
|
- [ ] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/)
|
||||||
|
|
||||||
@@ -31,13 +30,17 @@ Note that this repository is currently under development, additional classes and
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
```php
|
```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);
|
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
|
||||||
$user = new \Cloudflare\API\Endpoints\User($adapter);
|
$user = new Cloudflare\API\Endpoints\User($adapter);
|
||||||
|
|
||||||
echo $user->getUserID();
|
echo $user->getUserID();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
We welcome community contribution to this repository. [CONTRIBUTING.md](CONTRIBUTING.md) will help you start contributing.
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
|
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "5.7.5",
|
"phpunit/phpunit": "5.7.5",
|
||||||
"phpmd/phpmd" : "@stable"
|
"phpmd/phpmd" : "@stable",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.6"
|
||||||
},
|
},
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -23,7 +24,9 @@
|
|||||||
"Cloudflare\\API\\": "src/"
|
"Cloudflare\\API\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"autoload-dev": {
|
||||||
"test": "phpunit"
|
"classmap": [
|
||||||
|
"tests/"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1826
composer.lock
generated
1826
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -21,55 +21,56 @@ interface Adapter
|
|||||||
* Adapter constructor.
|
* Adapter constructor.
|
||||||
*
|
*
|
||||||
* @param Auth $auth
|
* @param Auth $auth
|
||||||
* @param String $baseURI
|
* @param string $baseURI
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI);
|
public function __construct(Auth $auth, string $baseURI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a GET request.
|
* Sends a GET request.
|
||||||
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
||||||
* RFCs, it is never useful).
|
* RFCs, it is never useful).
|
||||||
*
|
*
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $query
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get(String $uri, array $query, array $headers): ResponseInterface;
|
public function get(string $uri, array $query, array $headers): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
* @param array $body
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function post(String $uri, array $headers, array $body): ResponseInterface;
|
public function post(string $uri, array $headers, array $body): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
* @param array $body
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function put(String $uri, array $headers, array $body): ResponseInterface;
|
public function put(string $uri, array $headers, array $body): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
* @param array $body
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function patch(String $uri, array $headers, array $body): ResponseInterface;
|
public function patch(string $uri, array $headers, array $body): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
* @param array $body
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function delete(String $uri, array $headers, array $body): ResponseInterface;
|
public function delete(string $uri, array $headers, array $body): ResponseInterface;
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Auth\Auth;
|
use Cloudflare\API\Auth\Auth;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@@ -19,10 +18,10 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI = null)
|
public function __construct(Auth $auth, string $baseURI = null)
|
||||||
{
|
{
|
||||||
if ($baseURI === null) {
|
if ($baseURI === null) {
|
||||||
$baseURI = "https://api.cloudflare.com/client/v4/";
|
$baseURI = 'https://api.cloudflare.com/client/v4/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
@@ -38,21 +37,22 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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]);
|
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
|
||||||
|
|
||||||
$this->checkError($response);
|
$this->checkError($response);
|
||||||
return $response;
|
return $response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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,
|
'headers' => $headers,
|
||||||
'json' => $body
|
'json' => $body
|
||||||
]
|
]
|
||||||
@@ -65,13 +65,13 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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,
|
'headers' => $headers,
|
||||||
'json' => $jsonBody
|
'json' => $body
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -82,13 +82,13 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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,
|
'headers' => $headers,
|
||||||
'json' => $jsonBody
|
'json' => $body
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -99,9 +99,11 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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,
|
'headers' => $headers,
|
||||||
'json' => $body
|
'json' => $body
|
||||||
]
|
]
|
||||||
@@ -119,14 +121,12 @@ class Guzzle implements Adapter
|
|||||||
throw new JSONException();
|
throw new JSONException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->errors)) {
|
if (isset($json->errors) && count($json->errors) >= 1) {
|
||||||
foreach ($json->errors as $error) {
|
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code);
|
||||||
throw new ResponseException($error->message, $error->code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->success) && ($json->success === false)) {
|
if (isset($json->success) && !$json->success) {
|
||||||
throw new ResponseException("Request was unsuccessful.");
|
throw new ResponseException('Request was unsuccessful.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
|
||||||
class JSONException extends \Exception
|
class JSONException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
|
||||||
class ResponseException extends \Exception
|
class ResponseException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,12 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class APIKey implements Auth
|
class APIKey implements Auth
|
||||||
{
|
{
|
||||||
private $email;
|
private $email;
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
public function __construct(String $email, String $apiKey)
|
public function __construct(string $email, string $apiKey)
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
interface Auth
|
interface Auth
|
||||||
{
|
{
|
||||||
public function getHeaders(): array;
|
public function getHeaders(): array;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class None implements Auth
|
class None implements Auth
|
||||||
{
|
{
|
||||||
public function getHeaders(): array
|
public function getHeaders(): array
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class UserServiceKey implements Auth
|
class UserServiceKey implements Auth
|
||||||
{
|
{
|
||||||
private $userServiceKey;
|
private $userServiceKey;
|
||||||
|
|
||||||
public function __construct(String $userServiceKey)
|
public function __construct(string $userServiceKey)
|
||||||
{
|
{
|
||||||
$this->userServiceKey = $userServiceKey;
|
$this->userServiceKey = $userServiceKey;
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/Configurations/AccessRules.php
Normal file
28
src/Configurations/AccessRules.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class AccessRules implements Configurations
|
||||||
|
{
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function setIP(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIPRange(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip_range', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCountry(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'country', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
interface Configurations
|
interface Configurations
|
||||||
{
|
{
|
||||||
public function getArray(): array;
|
public function getArray(): array;
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationsException extends \Exception
|
class ConfigurationsException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,360 +10,302 @@ namespace Cloudflare\API\Configurations;
|
|||||||
|
|
||||||
class PageRulesActions implements Configurations
|
class PageRulesActions implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function setAlwaysOnline(bool $active)
|
public function setAlwaysOnline(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('always_online', [
|
||||||
$object->id = "always_online";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAlwaysUseHTTPS(bool $active)
|
public function setAlwaysUseHTTPS(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('always_use_https', [
|
||||||
$object->id = "always_use_https";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserCacheTTL(int $ttl)
|
public function setBrowserCacheTTL(int $ttl)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('browser_cache_ttl', [
|
||||||
$object->id = "browser_cache_ttl";
|
'value' => $ttl
|
||||||
$object->value = $ttl;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserIntegrityCheck(bool $active)
|
public function setBrowserIntegrityCheck(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('browser_check', [
|
||||||
$object->id = "browser_check";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBypassCacheOnCookie(bool $value)
|
public function setBypassCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('bypass_cache_on_cookie', [
|
||||||
$object->id = "bypass_cache_on_cookie";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheByDeviceType(bool $active)
|
public function setCacheByDeviceType(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_by_device_type', [
|
||||||
$object->id = "cache_by_device_type";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheKey(string $value)
|
public function setCacheKey(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_key', [
|
||||||
$object->id = "cache_key";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheLevel(string $value)
|
public function setCacheLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
|
if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) {
|
||||||
throw new ConfigurationsException("Invalid cache level");
|
throw new ConfigurationsException('Invalid cache level');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_level', [
|
||||||
$object->id = "cache_level";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheOnCookie(bool $value)
|
public function setCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_on_cookie', [
|
||||||
$object->id = "cache_on_cookie";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableApps(bool $active)
|
public function setDisableApps(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_apps', [
|
||||||
$object->id = "disable_apps";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisablePerformance(bool $active)
|
public function setDisablePerformance(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_performance', [
|
||||||
$object->id = "disable_performance";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableSecurity(bool $active)
|
public function setDisableSecurity(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_security', [
|
||||||
$object->id = "disable_security";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEdgeCacheTTL(int $value)
|
public function setEdgeCacheTTL(int $value)
|
||||||
{
|
{
|
||||||
if ($value > 2419200) {
|
if ($value > 2419200) {
|
||||||
throw new ConfigurationsException("Edge Cache TTL too high.");
|
throw new ConfigurationsException('Edge Cache TTL too high.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('edge_cache_ttl', [
|
||||||
$object->id = "edge_cache_ttl";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmailObfuscation(bool $active)
|
public function setEmailObfuscation(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_security', [
|
||||||
$object->id = "disable_security";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setForwardingURL(int $statusCode, string $forwardingUrl)
|
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.');
|
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('forwarding_url', [
|
||||||
$object->id = "forwarding_url";
|
'status_code' => $statusCode,
|
||||||
$object->status_code = $statusCode;
|
'url' => $forwardingUrl,
|
||||||
$object->url = $forwardingUrl;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHostHeaderOverride(bool $active)
|
public function setHostHeaderOverride(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('host_header_override', [
|
||||||
$object->id = "host_header_override";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHotlinkProtection(bool $active)
|
public function setHotlinkProtection(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('hotlink_protection', [
|
||||||
$object->id = "hotlink_protection";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIPGeoLocationHeader(bool $active)
|
public function setIPGeoLocationHeader(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('ip_geolocation', [
|
||||||
$object->id = "ip_geolocation";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMinification(bool $html, bool $css, bool $js)
|
public function setMinification(bool $html, bool $css, bool $javascript)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('minification', [
|
||||||
$object->id = "minification";
|
'html' => $this->getBoolAsOnOrOff($html),
|
||||||
$object->html = $html === true ? "on" : "off";
|
'css' => $this->getBoolAsOnOrOff($css),
|
||||||
$object->css = $css === true ? "on" : "off";
|
'js' => $this->getBoolAsOnOrOff($javascript),
|
||||||
$object->js = $js === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMirage(bool $active)
|
public function setMirage(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('mirage', [
|
||||||
$object->id = "mirage";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOriginErrorPagePassthru(bool $active)
|
public function setOriginErrorPagePassthru(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('origin_error_page_pass_thru', [
|
||||||
$object->id = "origin_error_page_pass_thru";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setQueryStringSort(bool $active)
|
public function setQueryStringSort(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('sort_query_string_for_cache', [
|
||||||
$object->id = "sort_query_string_for_cache";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableRailgun(bool $active)
|
public function setDisableRailgun(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_railgun', [
|
||||||
$object->id = "disable_railgun";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResolveOverride(bool $value)
|
public function setResolveOverride(bool $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('resolve_override', [
|
||||||
$object->id = "resolve_override";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRespectStrongEtag(bool $active)
|
public function setRespectStrongEtag(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('respect_strong_etag', [
|
||||||
$object->id = "respect_strong_etag";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResponseBuffering(bool $active)
|
public function setResponseBuffering(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('response_buffering', [
|
||||||
$object->id = "response_buffering";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRocketLoader(string $value)
|
public function setRocketLoader(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "manual", "automatic"])) {
|
if (!in_array($value, ['off', 'manual', 'automatic'])) {
|
||||||
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('rocket_loader', [
|
||||||
$object->id = "rocket_loader";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecurityLevel(string $value)
|
public function setSecurityLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
|
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.');
|
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('security_level', [
|
||||||
$object->id = "security_level";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServerSideExcludes(bool $active)
|
public function setServerSideExcludes(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('server_side_exclude', [
|
||||||
$object->id = "server_side_exclude";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSmartErrors(bool $active)
|
public function setSmartErrors(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('smart_errors', [
|
||||||
$object->id = "smart_errors";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSSL(string $value)
|
public function setSSL(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
|
if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) {
|
||||||
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('smart_errors', [
|
||||||
$object->id = "smart_errors";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTrueClientIpHeader(bool $active)
|
public function setTrueClientIpHeader(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('true_client_ip_header', [
|
||||||
$object->id = "true_client_ip_header";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWAF(bool $active)
|
public function setWAF(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('waf', [
|
||||||
$object->id = "waf";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAutomatedHTTPSRewrites(bool $active)
|
public function setAutomatedHTTPSRewrites(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('automatic_https_rewrites', [
|
||||||
$object->id = "automatic_https_rewrites";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOpportunisticEncryption(bool $active)
|
public function setOpportunisticEncryption(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('opportunistic_encryption', [
|
||||||
$object->id = "opportunistic_encryption";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
{
|
{
|
||||||
return $this->configs;
|
return $this->configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addConfigurationOption(string $setting, array $configuration)
|
||||||
|
{
|
||||||
|
$configuration['id'] = $setting;
|
||||||
|
|
||||||
|
$this->configs[] = (object) $configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBoolAsOnOrOff(bool $value): string
|
||||||
|
{
|
||||||
|
return true === $value ? 'on' : 'off';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,20 +8,21 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class PageRulesTargets implements Configurations
|
class PageRulesTargets implements Configurations
|
||||||
{
|
{
|
||||||
private $targets;
|
private $targets;
|
||||||
|
|
||||||
public function __construct(string $queryUrl)
|
public function __construct(string $queryUrl)
|
||||||
{
|
{
|
||||||
$target = new \stdClass();
|
$this->targets = [
|
||||||
$target->target = 'url';
|
(object)[
|
||||||
$target->constraint = new \stdClass();
|
'target' => 'url',
|
||||||
$target->constraint->operator = "matches";
|
'constraint' => (object)[
|
||||||
$target->constraint->value = $queryUrl;
|
'operator' => 'matches',
|
||||||
|
'value' => $queryUrl
|
||||||
$this->targets = [$target];
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -8,18 +8,13 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class UARules implements Configurations
|
class UARules implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function addUA(string $value)
|
public function addUA(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = (object)['target' => 'ua', 'value' => $value];
|
||||||
$object->target = "ua";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -8,27 +8,18 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class ZoneLockdown implements Configurations
|
class ZoneLockdown implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function addIP(string $value)
|
public function addIP(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = (object)['target' => 'ip', 'value' => $value];
|
||||||
$object->target = "ip";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addIPRange(string $value)
|
public function addIPRange(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = (object)['target' => 'ip_range', 'value' => $value];
|
||||||
$object->target = "ip_range";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
interface API
|
interface API
|
||||||
|
|||||||
153
src/Endpoints/AccessRules.php
Normal file
153
src/Endpoints/AccessRules.php
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\Configurations;
|
||||||
|
|
||||||
|
class AccessRules implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $scopeType
|
||||||
|
* @param string $mode
|
||||||
|
* @param string $configurationTarget
|
||||||
|
* @param string $configurationValue
|
||||||
|
* @param int $page
|
||||||
|
* @param int $perPage
|
||||||
|
* @param string $order
|
||||||
|
* @param string $direction
|
||||||
|
* @param string $match
|
||||||
|
* @param string $notes
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function listRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $scopeType = '',
|
||||||
|
string $mode = '',
|
||||||
|
string $configurationTarget = '',
|
||||||
|
string $configurationValue = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 50,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all',
|
||||||
|
string $notes = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($scopeType)) {
|
||||||
|
$query['scope_type'] = $scopeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($mode)) {
|
||||||
|
$query['mode'] = $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationTarget)) {
|
||||||
|
$query['configuration_target'] = $configurationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationValue)) {
|
||||||
|
$query['configuration_value'] = $configurationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($notes)) {
|
||||||
|
$query['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query, []);
|
||||||
|
$body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $mode,
|
||||||
|
Configurations $configuration,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode,
|
||||||
|
'configuration' => (object) $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
string $mode,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'none'): bool
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'cascade' => $cascade
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options);
|
||||||
|
|
||||||
|
$body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,17 @@ class DNS implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $type
|
||||||
|
* @param string $name
|
||||||
|
* @param string $content
|
||||||
|
* @param int $ttl
|
||||||
|
* @param bool $proxied
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function addRecord(
|
public function addRecord(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type,
|
string $type,
|
||||||
@@ -51,14 +62,14 @@ class DNS implements API
|
|||||||
|
|
||||||
public function listRecords(
|
public function listRecords(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type = "",
|
string $type = '',
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $content = "",
|
string $content = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -89,11 +100,7 @@ class DNS implements API
|
|||||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
||||||
@@ -121,5 +128,4 @@ class DNS implements API
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
class EndpointException extends \Exception
|
class EndpointException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
class IPs implements API
|
class IPs implements API
|
||||||
@@ -20,7 +19,8 @@ class IPs implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listIPs(): \stdClass {
|
public function listIPs(): \stdClass
|
||||||
|
{
|
||||||
$ips = $this->adapter->get('ips', [], []);
|
$ips = $this->adapter->get('ips', [], []);
|
||||||
$body = json_decode($ips->getBody());
|
$body = json_decode($ips->getBody());
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
use Cloudflare\API\Configurations\PageRulesActions;
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
@@ -22,6 +21,16 @@ class PageRules implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param PageRulesTargets $target
|
||||||
|
* @param PageRulesActions $actions
|
||||||
|
* @param bool $active
|
||||||
|
* @param int|null $priority
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function createPageRule(
|
public function createPageRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
PageRulesTargets $target,
|
PageRulesTargets $target,
|
||||||
@@ -61,19 +70,19 @@ class PageRules implements API
|
|||||||
string $direction = null,
|
string $direction = null,
|
||||||
string $match = null
|
string $match = null
|
||||||
): array {
|
): array {
|
||||||
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
|
if ($status === null && !in_array($status, ['active', 'disabled'])) {
|
||||||
throw new EndpointException('Page Rules can only be listed by status of active or 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'])) {
|
if ($order === null && !in_array($order, ['status', 'priority'])) {
|
||||||
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
|
if ($direction === null && !in_array($direction, ['asc', 'desc'])) {
|
||||||
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($match) && !in_array($match, ['all', 'any'])) {
|
if ($match === null && !in_array($match, ['all', 'any'])) {
|
||||||
throw new EndpointException('Match can only be any or all.');
|
throw new EndpointException('Match can only be any or all.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +115,7 @@ class PageRules implements API
|
|||||||
): bool {
|
): bool {
|
||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
if ($active !== null) {
|
if ($target !== null) {
|
||||||
$options['targets'] = $target->getArray();
|
$options['targets'] = $target->getArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
99
src/Endpoints/Railgun.php
Normal file
99
src/Endpoints/Railgun.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class Railgun implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(
|
||||||
|
string $name
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->post('railguns', [], $query);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $direction = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get('railguns', $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(
|
||||||
|
string $railgunID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('railguns/' . $railgunID, [], []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getZones(
|
||||||
|
string $railgunID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(
|
||||||
|
string $railgunID,
|
||||||
|
bool $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'enabled' => $status
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch('railguns/' . $railgunID, [], $query);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(
|
||||||
|
string $railgunID
|
||||||
|
): bool {
|
||||||
|
$user = $this->adapter->delete('railguns/' . $railgunID, [], []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\Configurations;
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
class UARules implements API
|
class UARules implements API
|
||||||
@@ -32,28 +33,23 @@ class UARules implements API
|
|||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRule(
|
public function createRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $mode,
|
string $mode,
|
||||||
\Cloudflare\API\Configurations\Configurations $configuration,
|
Configurations $configuration,
|
||||||
string $id = null,
|
string $ruleID = null,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'configurations' => $configuration->getArray()
|
'configurations' => $configuration->getArray()
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($id !== null) {
|
if ($ruleID !== null) {
|
||||||
$options['id'] = $id;
|
$options['id'] = $ruleID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($description !== null) {
|
if ($description !== null) {
|
||||||
@@ -73,7 +69,7 @@ class UARules implements API
|
|||||||
|
|
||||||
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, [], []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $body->result;
|
||||||
}
|
}
|
||||||
@@ -85,7 +81,6 @@ class UARules implements API
|
|||||||
\Cloudflare\API\Configurations\UARules $configuration,
|
\Cloudflare\API\Configurations\UARules $configuration,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'id' => $ruleID,
|
'id' => $ruleID,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
class User implements API
|
class User implements API
|
||||||
@@ -28,17 +27,17 @@ class User implements API
|
|||||||
|
|
||||||
public function getUserID(): string
|
public function getUserID(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->id;
|
return $this->getUserDetails()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserEmail(): string
|
public function getUserEmail(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->email;
|
return $this->getUserDetails()->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateUserDetails(array $details): \stdClass
|
public function updateUserDetails(array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->patch("user", [], $details);
|
$response = $this->adapter->patch('user', [], $details);
|
||||||
return json_decode($response->getBody());
|
return json_decode($response->getBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
191
src/Endpoints/WAF.php
Normal file
191
src/Endpoints/WAF.php
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class WAF implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPackages(
|
||||||
|
string $zoneID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPackageInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID, [], []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRuleInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $ruleID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $ruleID,
|
||||||
|
string $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'mode' => $status,
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||||
|
[],
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
|
||||||
|
$query,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroupInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $groupID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateGroup(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $groupID,
|
||||||
|
string $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'mode' => $status
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||||
|
[],
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,28 +32,23 @@ class ZoneLockdown implements API
|
|||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createLockdown(
|
public function createLockdown(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
array $urls,
|
array $urls,
|
||||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
string $id = null,
|
string $lockdownID = null,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'urls' => $urls,
|
'urls' => $urls,
|
||||||
'configurations' => $configuration->getArray()
|
'configurations' => $configuration->getArray()
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($id !== null) {
|
if ($lockdownID !== null) {
|
||||||
$options['id'] = $id;
|
$options['id'] = $lockdownID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($description !== null) {
|
if ($description !== null) {
|
||||||
@@ -85,7 +80,6 @@ class ZoneLockdown implements API
|
|||||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'urls' => $urls,
|
'urls' => $urls,
|
||||||
'id' => $lockdownID,
|
'id' => $lockdownID,
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ class Zones implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param bool $jumpstart
|
||||||
|
* @param string $organizationID
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
|
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
@@ -27,9 +35,7 @@ class Zones implements API
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($organizationID)) {
|
if (!empty($organizationID)) {
|
||||||
$organization = new \stdClass();
|
$options['organization'] = (object)['id' => $organizationID];
|
||||||
$organization->id = $organizationID;
|
|
||||||
$options["organization"] = $organization;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones', [], $options);
|
$user = $this->adapter->post('zones', [], $options);
|
||||||
@@ -50,13 +56,13 @@ class Zones implements API
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function listZones(
|
public function listZones(
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $status = "",
|
string $status = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -83,24 +89,57 @@ class Zones implements API
|
|||||||
$user = $this->adapter->get('zones', $query, []);
|
$user = $this->adapter->get('zones', $query, []);
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getZoneID(string $name = ""): string
|
public function getZoneID(string $name = ''): string
|
||||||
{
|
{
|
||||||
$zones = $this->listZones($name);
|
$zones = $this->listZones($name);
|
||||||
|
|
||||||
if (sizeof($zones->result) < 1) {
|
if (count($zones->result) < 1) {
|
||||||
throw new EndpointException("Could not find zones with specified name.");
|
throw new EndpointException('Could not find zones with specified name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $zones->result[0]->id;
|
return $zones->result[0]->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $since
|
||||||
|
* @param string $until
|
||||||
|
* @param bool $continuous
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)], []);
|
||||||
|
|
||||||
|
return json_decode($response->getBody())->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param bool $enable
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => $enable ? 'on' : 'off']);
|
||||||
|
|
||||||
|
$body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge Everything
|
* Purge Everything
|
||||||
* @param string $zoneID
|
* @param string $zoneID
|
||||||
@@ -108,7 +147,7 @@ class Zones implements API
|
|||||||
*/
|
*/
|
||||||
public function cachePurgeEverything(string $zoneID): bool
|
public function cachePurgeEverything(string $zoneID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ['purge_everything' => true]);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|
||||||
@@ -119,10 +158,10 @@ class Zones implements API
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cachePurge(string $zoneID, array $files = [], array $tags = []): bool
|
public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool
|
||||||
{
|
{
|
||||||
if (empty($files) && empty($tags)) {
|
if ($files === null && $tags === null) {
|
||||||
throw new EndpointException("No files or tags to purge.");
|
throw new EndpointException('No files or tags to purge.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
class GuzzleTest extends PHPUnit_Framework_TestCase
|
class GuzzleTest extends TestCase
|
||||||
{
|
{
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
@@ -29,14 +29,14 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$response = $this->client->get('https://httpbin.org/get');
|
$response = $this->client->get('https://httpbin.org/get');
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$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("Test", $body->headers->{"X-Testing"});
|
$this->assertEquals('Test', $body->headers->{'X-Testing'});
|
||||||
|
|
||||||
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
|
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
|
$this->assertEquals('Test2', $body->headers->{'X-Another-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPost()
|
public function testPost()
|
||||||
@@ -44,10 +44,10 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
|
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$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->json->{"X-Post-Test"});
|
$this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPut()
|
public function testPut()
|
||||||
@@ -55,34 +55,40 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
|
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$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 PUT request.", json_decode($body->json)->{"X-Put-Test"});
|
$this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPatch()
|
public function testPatch()
|
||||||
{
|
{
|
||||||
$response = $this->client->patch('https://httpbin.org/patch', [],
|
$response = $this->client->patch(
|
||||||
['X-Patch-Test' => 'Testing a PATCH request.']);
|
'https://httpbin.org/patch',
|
||||||
|
[],
|
||||||
|
['X-Patch-Test' => 'Testing a PATCH request.']
|
||||||
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$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 PATCH request.", json_decode($body->json)->{"X-Patch-Test"});
|
$this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$response = $this->client->delete('https://httpbin.org/delete', [],
|
$response = $this->client->delete(
|
||||||
['X-Delete-Test' => 'Testing a DELETE request.']);
|
'https://httpbin.org/delete',
|
||||||
|
[],
|
||||||
|
['X-Delete-Test' => 'Testing a DELETE request.']
|
||||||
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$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 DELETE request.", $body->json->{"X-Delete-Test"});
|
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrors()
|
public function testErrors()
|
||||||
@@ -124,9 +130,9 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$method->invokeArgs($this->client, [$response]);
|
$method->invokeArgs($this->client, [$response]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotFound() {
|
public function testNotFound()
|
||||||
|
{
|
||||||
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
|
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
|
||||||
$response = $this->client->get('https://httpbin.org/status/404');
|
$this->client->get('https://httpbin.org/status/404');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Date: 13/01/2017
|
* Date: 13/01/2017
|
||||||
* Time: 17:15
|
* Time: 17:15
|
||||||
*/
|
*/
|
||||||
class APIKeyTest extends PHPUnit_Framework_TestCase
|
class APIKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,6 @@ class APIKeyTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
||||||
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
||||||
|
|
||||||
$this->assertEquals(2, sizeof($headers));
|
$this->assertCount(2, $headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
* Time: 20:08
|
* Time: 20:08
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Auth\None;
|
class NoneTest extends TestCase
|
||||||
|
|
||||||
class NoneTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,19 +5,20 @@
|
|||||||
* Date: 13/01/2017
|
* Date: 13/01/2017
|
||||||
* Time: 18:03
|
* Time: 18:03
|
||||||
*/
|
*/
|
||||||
class UserServiceKeyTest extends PHPUnit_Framework_TestCase
|
class UserServiceKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
$auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a");
|
$auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a');
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
||||||
|
|
||||||
$this->assertEquals('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
|
$this->assertEquals(
|
||||||
$headers['X-Auth-User-Service-Key']);
|
'v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
|
||||||
|
$headers['X-Auth-User-Service-Key']
|
||||||
$this->assertEquals(1, sizeof($headers));
|
);
|
||||||
|
|
||||||
|
$this->assertCount(1, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* Date: 19/09/2017
|
* Date: 19/09/2017
|
||||||
* Time: 15:24
|
* Time: 15:24
|
||||||
*/
|
*/
|
||||||
class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
class ConfigurationsUARulesTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetArray()
|
public function testGetArray()
|
||||||
{
|
{
|
||||||
@@ -14,12 +14,14 @@ class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$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');
|
$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();
|
$array = $configuration->getArray();
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[0]);
|
$this->assertObjectHasAttribute('target', $array[0]);
|
||||||
$this->assertEquals('ua', $array[0]->target);
|
$this->assertEquals('ua', $array[0]->target);
|
||||||
$this->assertObjectHasAttribute('value', $array[0]);
|
$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',
|
$this->assertEquals(
|
||||||
$array[0]->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',
|
||||||
|
$array[0]->value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* Date: 05/09/2017
|
* Date: 05/09/2017
|
||||||
* Time: 13:50
|
* Time: 13:50
|
||||||
*/
|
*/
|
||||||
class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
class ConfigurationsZoneLockdownTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetArray()
|
public function testGetArray()
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,7 @@ class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
$configuration->addIP('1.2.3.4');
|
$configuration->addIP('1.2.3.4');
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
$array = $configuration->getArray();
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[0]);
|
$this->assertObjectHasAttribute('target', $array[0]);
|
||||||
$this->assertEquals('ip', $array[0]->target);
|
$this->assertEquals('ip', $array[0]->target);
|
||||||
@@ -24,7 +24,7 @@ class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
$configuration->addIPRange('1.2.3.4/24');
|
$configuration->addIPRange('1.2.3.4/24');
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
$array = $configuration->getArray();
|
||||||
$this->assertEquals(2, sizeof($array));
|
$this->assertCount(2, $array);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[1]);
|
$this->assertObjectHasAttribute('target', $array[1]);
|
||||||
$this->assertEquals('ip_range', $array[1]->target);
|
$this->assertEquals('ip_range', $array[1]->target);
|
||||||
@@ -8,14 +8,15 @@
|
|||||||
|
|
||||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
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/*');
|
$targets = new PageRulesTargets('junade.com/*');
|
||||||
$array = $targets->getArray();
|
$array = $targets->getArray();
|
||||||
|
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
|
$this->assertEquals('junade.com/*', $array[0]->constraint->value);
|
||||||
$this->assertEquals("matches", $array[0]->constraint->operator);
|
$this->assertEquals('matches', $array[0]->constraint->operator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
112
tests/Endpoints/AccessRulesTest.php
Normal file
112
tests/Endpoints/AccessRulesTest.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AccessRulesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccessRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 50,
|
||||||
|
'match' => 'all'
|
||||||
|
]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRule()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\AccessRules();
|
||||||
|
$config->setIP('1.2.3.4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccessRule.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/access_rules/rules'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'configuration' => (object) $config->getArray(),
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->createRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'challenge',
|
||||||
|
$config,
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccessRule.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/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->updateRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'92f17202ed8bd63d69a66b86a49a8f6b',
|
||||||
|
'challenge',
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccessRule.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/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([
|
||||||
|
'cascade' => 'none'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,38 +6,20 @@
|
|||||||
* Date: 09/06/2017
|
* Date: 09/06/2017
|
||||||
* Time: 15:31
|
* Time: 15:31
|
||||||
*/
|
*/
|
||||||
class DNSTest extends PHPUnit_Framework_TestCase
|
class DNSTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAddRecord()
|
public function testAddRecord()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.json');
|
||||||
{
|
|
||||||
"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);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$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([
|
$this->equalTo([
|
||||||
'type' => 'A',
|
'type' => 'A',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
@@ -53,42 +35,15 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testListRecords()
|
public function testListRecords()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": [
|
|
||||||
{
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"type": "A",
|
|
||||||
"name": "example.com",
|
|
||||||
"content": "1.2.3.4",
|
|
||||||
"proxiable": true,
|
|
||||||
"proxied": false,
|
|
||||||
"ttl": 120,
|
|
||||||
"locked": false,
|
|
||||||
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
|
||||||
"zone_name": "example.com",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result_info": {
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 20,
|
|
||||||
"count": 1,
|
|
||||||
"total_count": 2000
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$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/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
@@ -102,51 +57,65 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
$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');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRecordDetails()
|
public function testGetDNSRecordDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getDNSRecordDetails.json');
|
||||||
"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);
|
|
||||||
$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/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,37 +6,25 @@
|
|||||||
* Time: 20:16
|
* Time: 20:16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\IPs;
|
class IPsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListIPs()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listIPs.json');
|
||||||
|
|
||||||
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 = $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('ips'), $this->equalTo([])
|
->with(
|
||||||
|
$this->equalTo('ips'),
|
||||||
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||||
$ips = $ips->listIPs();
|
$ips = $ips->listIPs();
|
||||||
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
|
||||||
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,54 +6,24 @@
|
|||||||
* Time: 19:25
|
* Time: 19:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\PageRules;
|
class PageRulesTest extends TestCase
|
||||||
|
|
||||||
class PageRulesTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testCreatePageRule()
|
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/*');
|
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||||
$action->setAlwaysOnline(true);
|
$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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
@@ -62,61 +32,23 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListPageRules()
|
public function testListPageRules()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPageRules.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'status' => 'active',
|
'status' => 'active',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
@@ -126,101 +58,44 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPageRuleDetails()
|
public function testGetPageRuleDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPageRuleDetails.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([])
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||||
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdatePageRule()
|
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/*');
|
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||||
$action->setAlwaysOnline(true);
|
$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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
@@ -229,39 +104,29 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeletePageRule()
|
public function testDeletePageRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePageRule.json');
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||||
|
$this->equalTo([]),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|||||||
151
tests/Endpoints/RailgunTest.php
Normal file
151
tests/Endpoints/RailgunTest.php
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:20
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RailgunTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testcreate()
|
||||||
|
{
|
||||||
|
$details = [
|
||||||
|
'name' => 'My Railgun',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo(['name' => $details['name']])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->create($details['name']);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testlist()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailguns.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'direction' => 'desc'
|
||||||
|
]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->list(1, 20, 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testget()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->get('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetZones()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailgunZones.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->getZones('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdate()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
|
||||||
|
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testdelete()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$waf->delete('e928d310693a83094309acf9ead50448');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,46 +6,19 @@
|
|||||||
* Time: 15:19
|
* Time: 15:19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\UARules;
|
class UARulesTest extends TestCase
|
||||||
|
|
||||||
class UARulesTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testListRules()
|
public function testListRules()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRules.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20
|
'per_page' => 20
|
||||||
@@ -54,12 +27,12 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,32 +41,16 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\UARules();
|
$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');
|
$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('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRule.json');
|
||||||
{
|
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
@@ -102,47 +59,34 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->createRule('023e105f4ecef8ad9ca31a8372d0c353', 'js_challenge', $config,
|
$rules->createRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'js_challenge',
|
||||||
|
$config,
|
||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'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()
|
public function getRuleDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRuleDetails.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateRule()
|
public function testUpdateRule()
|
||||||
@@ -150,32 +94,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\UARules();
|
$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');
|
$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('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRule.json');
|
||||||
{
|
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('put')->willReturn($response);
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('put')
|
->method('put')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
@@ -185,38 +112,32 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->updateRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
|
$rules->updateRule(
|
||||||
'js_challenge', $config,
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
'Restrict access to these endpoints to requests from a known IP address');
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'js_challenge',
|
||||||
|
$config,
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteRule()
|
public function testDeleteRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRule.json');
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,124 +5,52 @@
|
|||||||
* Date: 01/02/2017
|
* Date: 01/02/2017
|
||||||
* Time: 12:50
|
* Time: 12:50
|
||||||
*/
|
*/
|
||||||
class UserTest extends PHPUnit_Framework_TestCase
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetUserDetails()
|
public function testGetUserDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
|
||||||
{
|
|
||||||
"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);
|
|
||||||
$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);
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$details = $user->getUserDetails();
|
$details = $user->getUserDetails();
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("id", $details);
|
$this->assertObjectHasAttribute('id', $details);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id);
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
|
||||||
$this->assertObjectHasAttribute("email", $details);
|
$this->assertObjectHasAttribute('email', $details);
|
||||||
$this->assertEquals("user@example.com", $details->email);
|
$this->assertEquals('user@example.com', $details->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserID()
|
public function testGetUserID()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
|
||||||
{
|
|
||||||
"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);
|
|
||||||
$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);
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID());
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserEmail()
|
public function testGetUserEmail()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
|
||||||
{
|
|
||||||
"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);
|
|
||||||
$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())->method('get');
|
$mock->expects($this->once())->method('get');
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("user@example.com", $user->getUserEmail());
|
$this->assertEquals('user@example.com', $user->getUserEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateUserDetails()
|
public function testUpdateUserDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
|
||||||
{
|
|
||||||
"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);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
@@ -131,6 +59,6 @@ class UserTest extends PHPUnit_Framework_TestCase
|
|||||||
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
|
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$user->updateUserDetails(['email' => "user2@example.com"]);
|
$user->updateUserDetails(['email' => 'user2@example.com']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
221
tests/Endpoints/WAFTest.php
Normal file
221
tests/Endpoints/WAFTest.php
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 13:34
|
||||||
|
*/
|
||||||
|
|
||||||
|
class WAFTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testgetPackages()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackages.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetPackageInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageInfo.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
|
||||||
|
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetRuleInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageRuleInfo.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
|
||||||
|
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdateRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'mode' => 'on',
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on');
|
||||||
|
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageGroups.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetGroupInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageGroupInfo.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdateGroup()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageGroup.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'mode' => 'off',
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off');
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,44 +6,19 @@
|
|||||||
* Date: 04/09/2017
|
* Date: 04/09/2017
|
||||||
* Time: 21:23
|
* Time: 21:23
|
||||||
*/
|
*/
|
||||||
class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
class ZoneLockdownTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testListLockdowns()
|
public function testListLockdowns()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLockdowns.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
@@ -52,12 +27,12 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
$result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,85 +41,52 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
$config->addIP('1.2.3.4');
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addLockdown.json');
|
||||||
{
|
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||||
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
'configurations' => $config->getArray(),
|
'configurations' => $config->getArray(),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$ld->createLockdown('023e105f4ecef8ad9ca31a8372d0c353', ["api.mysite.com/some/endpoint*"], $config,
|
$zoneLockdown->createLockdown(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
['api.mysite.com/some/endpoint*'],
|
||||||
|
$config,
|
||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'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()
|
public function testGetRecordDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordDetails.json');
|
||||||
"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 = $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/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateLockdown()
|
public function testUpdateLockdown()
|
||||||
@@ -152,49 +94,32 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
$config->addIP('1.2.3.4');
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLockdown.json');
|
||||||
{
|
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('put')->willReturn($response);
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('put')
|
->method('put')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
'configurations' => $config->getArray(),
|
'configurations' => $config->getArray(),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$ld->updateLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
|
$zoneLockdown->updateLockdown(
|
||||||
["api.mysite.com/some/endpoint*"], $config,
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
'Restrict access to these endpoints to requests from a known IP address');
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
['api.mysite.com/some/endpoint*'],
|
||||||
|
$config,
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteLockdown()
|
public function testDeleteLockdown()
|
||||||
@@ -202,31 +127,20 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
$config->addIP('1.2.3.4');
|
$config->addIP('1.2.3.4');
|
||||||
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLockdown.json');
|
||||||
{
|
|
||||||
"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 = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$ld->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,197 +6,82 @@
|
|||||||
* Date: 06/06/2017
|
* Date: 06/06/2017
|
||||||
* Time: 16:01
|
* Time: 16:01
|
||||||
*/
|
*/
|
||||||
class ZonesTest extends PHPUnit_Framework_TestCase
|
class ZonesTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAddZone()
|
public function testAddZone()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.json');
|
||||||
"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);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones'),
|
->with(
|
||||||
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
|
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->addZone("example.com");
|
$result = $zones->addZone('example.com');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("id", $result);
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->id);
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
|
||||||
|
|
||||||
$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('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$org = new stdClass();
|
|
||||||
$org->id = "01a7362d577a6c3019a474fd6f485823";
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones'),
|
->with(
|
||||||
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org])
|
$this->equalTo([
|
||||||
|
'name' => 'example.com',
|
||||||
|
'jumpstart' => true,
|
||||||
|
'organization' => (object)['id' => '01a7362d577a6c3019a474fd6f485823']
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823");
|
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testActivationTest()
|
public function testActivationTest()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$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('put')->willReturn($response);
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('put')
|
->method('put')
|
||||||
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo([])
|
$this->equalTo([])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListZones()
|
public function testListZones()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listZones.json');
|
||||||
"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);
|
|
||||||
$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'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
@@ -210,86 +95,26 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$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');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetZoneID()
|
public function testGetZoneID()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneId.json');
|
||||||
"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);
|
|
||||||
$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'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
@@ -300,34 +125,71 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->getZoneID("example.com");
|
$result = $zones->getZoneID('example.com');
|
||||||
|
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAnalyticsDashboard()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getAnalyticsDashboard.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/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
|
||||||
|
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)]),
|
||||||
|
$this->equalTo([])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$analytics = $zones->getAnalyticsDashboard('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('since', $analytics->totals);
|
||||||
|
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testChangeDevelopmentMode()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.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/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo(['value' => 'on'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCachePurgeEverything()
|
public function testCachePurgeEverything()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$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('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([]),
|
||||||
$this->equalTo(["purge_everything" => true])
|
$this->equalTo(['purge_everything' => true])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tests/Fixtures/Endpoints/changeDevelopmentMode.json
Normal file
12
tests/Fixtures/Endpoints/changeDevelopmentMode.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"id": "development_mode",
|
||||||
|
"value": "on",
|
||||||
|
"modified_on": "2017-11-06T05:16:42.864300Z",
|
||||||
|
"time_remaining": 10800,
|
||||||
|
"editable": true
|
||||||
|
},
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
30
tests/Fixtures/Endpoints/createAccessRule.json
Normal file
30
tests/Fixtures/Endpoints/createAccessRule.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
tests/Fixtures/Endpoints/createRailgun.json
Normal file
23
tests/Fixtures/Endpoints/createRailgun.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "e928d310693a83094309acf9ead50448",
|
||||||
|
"name": "My Railgun",
|
||||||
|
"status": "active",
|
||||||
|
"enabled": true,
|
||||||
|
"zones_connected": 2,
|
||||||
|
"build": "b1234",
|
||||||
|
"version": "2.1",
|
||||||
|
"revision": "123",
|
||||||
|
"activation_key": "e4edc00281cb56ebac22c81be9bac8f3",
|
||||||
|
"activated_on": "2014-01-02T02:20:00Z",
|
||||||
|
"created_on": "2014-01-01T05:20:00Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
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/deleteAccessRule.json
Normal file
12
tests/Fixtures/Endpoints/deleteAccessRule.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b"
|
||||||
|
}
|
||||||
|
}
|
||||||
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/deleteRailgun.json
Normal file
12
tests/Fixtures/Endpoints/deleteRailgun.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "e928d310693a83094309acf9ead50448"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
176
tests/Fixtures/Endpoints/getAnalyticsDashboard.json
Normal file
176
tests/Fixtures/Endpoints/getAnalyticsDashboard.json
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"totals": {
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"requests": {
|
||||||
|
"all": 1234085328,
|
||||||
|
"cached": 1234085328,
|
||||||
|
"uncached": 13876154,
|
||||||
|
"content_type": {
|
||||||
|
"css": 15343,
|
||||||
|
"html": 1234213,
|
||||||
|
"javascript": 318236,
|
||||||
|
"gif": 23178,
|
||||||
|
"jpeg": 1982048
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 4181364,
|
||||||
|
"AG": 37298,
|
||||||
|
"GI": 293846
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 12978361,
|
||||||
|
"unencrypted": 781263
|
||||||
|
},
|
||||||
|
"http_status": {
|
||||||
|
"200": 13496983,
|
||||||
|
"301": 283,
|
||||||
|
"400": 187936,
|
||||||
|
"402": 1828,
|
||||||
|
"404": 1293
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bandwidth": {
|
||||||
|
"all": 213867451,
|
||||||
|
"cached": 113205063,
|
||||||
|
"uncached": 113205063,
|
||||||
|
"content_type": {
|
||||||
|
"css": 237421,
|
||||||
|
"html": 1231290,
|
||||||
|
"javascript": 123245,
|
||||||
|
"gif": 1234242,
|
||||||
|
"jpeg": 784278
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 123145433,
|
||||||
|
"AG": 2342483,
|
||||||
|
"GI": 984753
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 37592942,
|
||||||
|
"unencrypted": 237654192
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"threats": {
|
||||||
|
"all": 23423873,
|
||||||
|
"country": {
|
||||||
|
"US": 123,
|
||||||
|
"CN": 523423,
|
||||||
|
"AU": 91
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"user.ban.ip": 123,
|
||||||
|
"hot.ban.unknown": 5324,
|
||||||
|
"macro.chl.captchaErr": 1341,
|
||||||
|
"macro.chl.jschlErr": 5323
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pageviews": {
|
||||||
|
"all": 5724723,
|
||||||
|
"search_engines": {
|
||||||
|
"googlebot": 35272,
|
||||||
|
"pingdom": 13435,
|
||||||
|
"bingbot": 5372,
|
||||||
|
"baidubot": 1345
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uniques": {
|
||||||
|
"all": 12343
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"timeseries": [
|
||||||
|
{
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"requests": {
|
||||||
|
"all": 1234085328,
|
||||||
|
"cached": 1234085328,
|
||||||
|
"uncached": 13876154,
|
||||||
|
"content_type": {
|
||||||
|
"css": 15343,
|
||||||
|
"html": 1234213,
|
||||||
|
"javascript": 318236,
|
||||||
|
"gif": 23178,
|
||||||
|
"jpeg": 1982048
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 4181364,
|
||||||
|
"AG": 37298,
|
||||||
|
"GI": 293846
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 12978361,
|
||||||
|
"unencrypted": 781263
|
||||||
|
},
|
||||||
|
"http_status": {
|
||||||
|
"200": 13496983,
|
||||||
|
"301": 283,
|
||||||
|
"400": 187936,
|
||||||
|
"402": 1828,
|
||||||
|
"404": 1293
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bandwidth": {
|
||||||
|
"all": 213867451,
|
||||||
|
"cached": 113205063,
|
||||||
|
"uncached": 113205063,
|
||||||
|
"content_type": {
|
||||||
|
"css": 237421,
|
||||||
|
"html": 1231290,
|
||||||
|
"javascript": 123245,
|
||||||
|
"gif": 1234242,
|
||||||
|
"jpeg": 784278
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 123145433,
|
||||||
|
"AG": 2342483,
|
||||||
|
"GI": 984753
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 37592942,
|
||||||
|
"unencrypted": 237654192
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"threats": {
|
||||||
|
"all": 23423873,
|
||||||
|
"country": {
|
||||||
|
"US": 123,
|
||||||
|
"CN": 523423,
|
||||||
|
"AU": 91
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"user.ban.ip": 123,
|
||||||
|
"hot.ban.unknown": 5324,
|
||||||
|
"macro.chl.captchaErr": 1341,
|
||||||
|
"macro.chl.jschlErr": 5323
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pageviews": {
|
||||||
|
"all": 5724723,
|
||||||
|
"search_engines": {
|
||||||
|
"googlebot": 35272,
|
||||||
|
"pingdom": 13435,
|
||||||
|
"bingbot": 5372,
|
||||||
|
"baidubot": 1345
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uniques": {
|
||||||
|
"all": 12343
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"time_delta": 60
|
||||||
|
}
|
||||||
|
}
|
||||||
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": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
tests/Fixtures/Endpoints/getPackageGroupInfo.json
Normal file
22
tests/Fixtures/Endpoints/getPackageGroupInfo.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "de677e5818985db1285d0e80225f06e5",
|
||||||
|
"name": "Project Honey Pot",
|
||||||
|
"description": "Group designed to protect against IP addresses that are a threat and typically used to launch DDoS attacks",
|
||||||
|
"rules_count": 10,
|
||||||
|
"modified_rules_count": 2,
|
||||||
|
"package_id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"mode": "on",
|
||||||
|
"allowed_modes": [
|
||||||
|
"on",
|
||||||
|
"off"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
17
tests/Fixtures/Endpoints/getPackageInfo.json
Normal file
17
tests/Fixtures/Endpoints/getPackageInfo.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"name": "WordPress rules",
|
||||||
|
"description": "Common WordPress exploit protections",
|
||||||
|
"detection_mode": "traditional",
|
||||||
|
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"status": "active"
|
||||||
|
}
|
||||||
|
}
|
||||||
24
tests/Fixtures/Endpoints/getPackageRuleInfo.json
Normal file
24
tests/Fixtures/Endpoints/getPackageRuleInfo.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "f939de3be84e66e757adcdcb87908023",
|
||||||
|
"description": "SQL injection prevention for SELECT statements",
|
||||||
|
"priority": 5,
|
||||||
|
"group": {
|
||||||
|
"id": "de677e5818985db1285d0e80225f06e5",
|
||||||
|
"name": "Project Honey Pot"
|
||||||
|
},
|
||||||
|
"package_id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"allowed_modes": [
|
||||||
|
"on",
|
||||||
|
"off"
|
||||||
|
],
|
||||||
|
"mode": "on"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
tests/Fixtures/Endpoints/getRailgun.json
Normal file
23
tests/Fixtures/Endpoints/getRailgun.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "e928d310693a83094309acf9ead50448",
|
||||||
|
"name": "My Railgun",
|
||||||
|
"status": "active",
|
||||||
|
"enabled": true,
|
||||||
|
"zones_connected": 2,
|
||||||
|
"build": "b1234",
|
||||||
|
"version": "2.1",
|
||||||
|
"revision": "123",
|
||||||
|
"activation_key": "e4edc00281cb56ebac22c81be9bac8f3",
|
||||||
|
"activated_on": "2014-01-02T02:20:00Z",
|
||||||
|
"created_on": "2014-01-01T05:20:00Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/Fixtures/Endpoints/listAccessRules.json
Normal file
38
tests/Fixtures/Endpoints/listAccessRules.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
30
tests/Fixtures/Endpoints/listPackageGroups.json
Normal file
30
tests/Fixtures/Endpoints/listPackageGroups.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "de677e5818985db1285d0e80225f06e5",
|
||||||
|
"name": "Project Honey Pot",
|
||||||
|
"description": "Group designed to protect against IP addresses that are a threat and typically used to launch DDoS attacks",
|
||||||
|
"rules_count": 10,
|
||||||
|
"modified_rules_count": 2,
|
||||||
|
"package_id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"mode": "on",
|
||||||
|
"allowed_modes": [
|
||||||
|
"on",
|
||||||
|
"off"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/Fixtures/Endpoints/listPackageRules.json
Normal file
38
tests/Fixtures/Endpoints/listPackageRules.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/Fixtures/Endpoints/listPackages.json
Normal file
25
tests/Fixtures/Endpoints/listPackages.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"name": "WordPress rules",
|
||||||
|
"description": "Common WordPress exploit protections",
|
||||||
|
"detection_mode": "traditional",
|
||||||
|
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"status": "active"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
30
tests/Fixtures/Endpoints/listRailgunZones.json
Normal file
30
tests/Fixtures/Endpoints/listRailgunZones.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
31
tests/Fixtures/Endpoints/listRailguns.json
Normal file
31
tests/Fixtures/Endpoints/listRailguns.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "e928d310693a83094309acf9ead50448",
|
||||||
|
"name": "My Railgun",
|
||||||
|
"status": "active",
|
||||||
|
"enabled": true,
|
||||||
|
"zones_connected": 2,
|
||||||
|
"build": "b1234",
|
||||||
|
"version": "2.1",
|
||||||
|
"revision": "123",
|
||||||
|
"activation_key": "e4edc00281cb56ebac22c81be9bac8f3",
|
||||||
|
"activated_on": "2014-01-02T02:20:00Z",
|
||||||
|
"created_on": "2014-01-01T05:20:00Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
30
tests/Fixtures/Endpoints/updateAccessRule.json
Normal file
30
tests/Fixtures/Endpoints/updateAccessRule.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
22
tests/Fixtures/Endpoints/updatePackageGroup.json
Normal file
22
tests/Fixtures/Endpoints/updatePackageGroup.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "de677e5818985db1285d0e80225f06e5",
|
||||||
|
"name": "Project Honey Pot",
|
||||||
|
"description": "Group designed to protect against IP addresses that are a threat and typically used to launch DDoS attacks",
|
||||||
|
"rules_count": 10,
|
||||||
|
"modified_rules_count": 2,
|
||||||
|
"package_id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"mode": "off",
|
||||||
|
"allowed_modes": [
|
||||||
|
"on",
|
||||||
|
"off"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
24
tests/Fixtures/Endpoints/updatePackageRule.json
Normal file
24
tests/Fixtures/Endpoints/updatePackageRule.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "f939de3be84e66e757adcdcb87908023",
|
||||||
|
"description": "SQL injection prevention for SELECT statements",
|
||||||
|
"priority": 5,
|
||||||
|
"group": {
|
||||||
|
"id": "de677e5818985db1285d0e80225f06e5",
|
||||||
|
"name": "Project Honey Pot"
|
||||||
|
},
|
||||||
|
"package_id": "a25a9a7e9c00afc1fb2e0245519d725b",
|
||||||
|
"allowed_modes": [
|
||||||
|
"on",
|
||||||
|
"off"
|
||||||
|
],
|
||||||
|
"mode": "on"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
tests/Fixtures/Endpoints/updateRailgun.json
Normal file
23
tests/Fixtures/Endpoints/updateRailgun.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "e928d310693a83094309acf9ead50448",
|
||||||
|
"name": "My Railgun",
|
||||||
|
"status": "active",
|
||||||
|
"enabled": true,
|
||||||
|
"zones_connected": 2,
|
||||||
|
"build": "b1234",
|
||||||
|
"version": "2.1",
|
||||||
|
"revision": "123",
|
||||||
|
"activation_key": "e4edc00281cb56ebac22c81be9bac8f3",
|
||||||
|
"activated_on": "2014-01-02T02:20:00Z",
|
||||||
|
"created_on": "2014-01-01T05:20:00Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user