diff --git a/.gitignore b/.gitignore index 42cd73d..3aa184c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/.idea /vendor/ \ No newline at end of file diff --git a/README.md b/README.md index a0f52fe..1794b7f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Each API call is provided via a similarly named function within various classes - [x] [Railgun](https://www.cloudflare.com/railgun/) administration - [ ] [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/) +- [x] Crypto +- [x] Load Balancers +- [x] Firewall Settings Note that this repository is currently under development, additional classes and endpoints being actively added. diff --git a/composer.json b/composer.json index a6dbadd..642dab3 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "require": { "guzzlehttp/guzzle": "^6.2.2", "php": ">=7.0.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "5.7.5", @@ -28,5 +29,10 @@ "classmap": [ "tests/" ] + }, + "config": { + "preferred-install": "dist", + "sort-packages": true, + "optimize-autoloader": true } } diff --git a/phpcbf.phar b/phpcbf.phar new file mode 100644 index 0000000..6771440 Binary files /dev/null and b/phpcbf.phar differ diff --git a/phpcs.phar b/phpcs.phar new file mode 100644 index 0000000..b8ed399 Binary files /dev/null and b/phpcs.phar differ diff --git a/src/Configurations/AccessRules.php b/src/Configurations/AccessRules.php index 17ea57f..ece5e62 100644 --- a/src/Configurations/AccessRules.php +++ b/src/Configurations/AccessRules.php @@ -21,6 +21,11 @@ class AccessRules implements Configurations $this->config = ['target' => 'country', 'value' => $value]; } + public function setASN(string $value) + { + $this->config = ['target' => 'asn', 'value' => $value]; + } + public function getArray(): array { return $this->config; diff --git a/src/Configurations/LoadBalancer.php b/src/Configurations/LoadBalancer.php new file mode 100644 index 0000000..70b2da1 --- /dev/null +++ b/src/Configurations/LoadBalancer.php @@ -0,0 +1,178 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +namespace Cloudflare\API\Configurations; + +class LoadBalancer implements Configurations +{ + private $configs = []; + + public function __construct(string $name, array $defaultPools, string $fallbackPool) + { + $this->setName($name); + $this->setDefaultPools($defaultPools); + $this->setFallbackPool($fallbackPool); + } + + public function setName(string $name) + { + $this->configs['name'] = $name; + } + + public function getName():string + { + return $this->configs['name'] ?? ''; + } + + public function setDefaultPools(array $defaultPools) + { + $this->configs['default_pools'] = $defaultPools; + } + + public function getDefaultPools():array + { + return $this->configs['default_pools'] ?? []; + } + + public function setFallbackPool(string $fallbackPool) + { + $this->configs['fallback_pools'] = $fallbackPool; + } + + public function getFallbackPool():string + { + return $this->configs['fallback_pools'] ?? ''; + } + + public function setSteeringPolicy(string $steeringPolicy = '') + { + $allowedOptions = ['off', 'geo', 'random', 'dynamic_latency', '']; + if (!in_array($steeringPolicy, $allowedOptions)) { + throw new ConfigurationsException('Given steering policy value is not a valid option, valid options are: ' . implode(', ', $allowedOptions)); + } + + $this->configs['steering_policy'] = $steeringPolicy; + } + + public function getSteeringPolicy():string + { + return $this->configs['steering_policy'] ?? ''; + } + + public function enable() + { + $this->configs['enabled'] = true; + } + + public function isEnabled():bool + { + return $this->configs['enabled'] ?? true; + } + + public function disable() + { + $this->configs['enabled'] = false; + } + + public function isDisabled():bool + { + return !$this->configs['enabled'] ?? false; + } + + public function getEnabled():bool + { + return $this->configs['enabled'] ?? true; + } + + public function setPopPools(array $popPools) + { + $this->configs['pop_pools'] = $popPools; + } + + public function getPopPools():array + { + return $this->configs['pop_pools'] ?? []; + } + + public function setTtl(int $ttl) + { + $this->configs['ttl'] = $ttl; + } + + public function getTtl():int + { + return $this->configs['ttl'] ?? 30; + } + + public function setRegionPools(array $regionPools) + { + $this->configs['region_pools'] = $regionPools; + } + + public function getRegionPools():array + { + return $this->configs['region_pools'] ?? []; + } + + public function setSessionAffinity(string $sessionAffinity = '') + { + $allowedOptions = ['none', 'cookie', 'ip_cookie', '']; + if (!in_array($sessionAffinity, $allowedOptions)) { + throw new ConfigurationsException('Given session affinity value is not a valid option, valid options are: ' . implode(', ', $allowedOptions)); + } + $this->configs['session_affinity'] = $sessionAffinity; + } + + public function getSessionAffinity():string + { + return $this->configs['session_affinity'] ?? ''; + } + + public function setDescription(string $description = '') + { + $this->configs['description'] = $description; + } + + public function getDescription():string + { + return $this->configs['description'] ?? ''; + } + + public function enableProxied() + { + $this->configs['proxied'] = true; + } + + public function disableProxied() + { + $this->configs['proxied'] = false; + } + + public function isProxied():bool + { + return $this->configs['proxied'] ?? true; + } + + public function setSessionAffinityTtl(int $sessionAffinityTtl = 82800) + { + if ($sessionAffinityTtl > 604800 || $sessionAffinityTtl < 1800) { + throw new ConfigurationsException('The value of session affinity ttl must be between 1800 and 604800'); + } + + $this->configs['session_affinity_ttl'] = $sessionAffinityTtl; + } + + public function getSessionAffinityTtl():int + { + return $this->configs['session_affinity_ttl'] ?? 82800; + } + + public function getArray(): array + { + return $this->configs; + } +} diff --git a/src/Configurations/PageRulesActions.php b/src/Configurations/PageRulesActions.php old mode 100644 new mode 100755 index 072a207..359d3c7 --- a/src/Configurations/PageRulesActions.php +++ b/src/Configurations/PageRulesActions.php @@ -140,10 +140,10 @@ class PageRulesActions implements Configurations ]); } - public function setHostHeaderOverride(bool $active) + public function setHostHeaderOverride(string $value) { $this->addConfigurationOption('host_header_override', [ - 'value' => $this->getBoolAsOnOrOff($active) + 'value' => $value ]); } @@ -198,7 +198,7 @@ class PageRulesActions implements Configurations ]); } - public function setResolveOverride(bool $value) + public function setResolveOverride(string $value) { $this->addConfigurationOption('resolve_override', [ 'value' => $value diff --git a/src/Configurations/Pool.php b/src/Configurations/Pool.php new file mode 100644 index 0000000..7b45d41 --- /dev/null +++ b/src/Configurations/Pool.php @@ -0,0 +1,121 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +namespace Cloudflare\API\Configurations; + +class Pool implements Configurations +{ + private $configs = []; + + public function __construct(string $name, array $origins) + { + $this->setName($name); + $this->setOrigins($origins); + } + + public function setName(string $name) + { + $this->configs['name'] = $name; + } + + public function getName():string + { + return $this->configs['name'] ?? ''; + } + + public function setOrigins(array $origins) + { + foreach ($origins as $origin) { + if (!isset($origin['name'])) { + throw new ConfigurationsException('name is required for origin'); + } + if (!isset($origin['address'])) { + throw new ConfigurationsException('address is required for origin'); + } + } + $this->configs['origins'] = $origins; + } + + public function getOrigins():array + { + return $this->configs['origins'] ?? []; + } + + public function setDescription(string $description = '') + { + $this->configs['description'] = $description; + } + + public function getDescription():string + { + return $this->configs['description'] ?? ''; + } + + public function enable() + { + $this->configs['enabled'] = true; + } + + public function isEnabled():bool + { + return $this->configs['enabled'] ?? true; + } + + public function disable() + { + $this->configs['enabled'] = false; + } + + public function isDisabled():bool + { + return !$this->configs['enabled'] ?? false; + } + + public function getEnabled():bool + { + return $this->configs['enabled'] ?? true; + } + + public function setMonitor(string $monitor) + { + $this->configs['monitor'] = $monitor; + } + + public function getMonitor():string + { + return $this->configs['monitor'] ?? ''; + } + + public function setCheckRegions(array $checkRegions) + { + $this->configs['check_regions'] = $checkRegions; + } + + public function getCheckRegions():array + { + return $this->configs['check_regions'] ?? []; + } + + public function setNotificationEmail(string $email) + { + if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { + throw new ConfigurationsException('Invalid notification email given'); + } + + $this->configs['notification_email'] = $email; + } + + public function getNotificationEmail():string + { + return $this->configs['notification_email'] ?? ''; + } + + public function getArray(): array + { + return $this->configs; + } +} diff --git a/src/Endpoints/Crypto.php b/src/Endpoints/Crypto.php new file mode 100644 index 0000000..e785c54 --- /dev/null +++ b/src/Endpoints/Crypto.php @@ -0,0 +1,95 @@ +adapter = $adapter; + } + + /** + * Get the Opportunistic Encryption feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getOpportunisticEncryptionSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/opportunistic_encryption' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Get the Onion Routing feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getOnionRoutingSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/opportunistic_onion' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Update the Oppurtunistic Encryption setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateOpportunisticEncryptionSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/opportunistic_encryption', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the Onion Routing setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateOnionRoutingSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/opportunistic_onion', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } +} diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php index d06116f..65dc4a4 100644 --- a/src/Endpoints/DNS.php +++ b/src/Endpoints/DNS.php @@ -125,6 +125,15 @@ class DNS implements API return $this->body->result; } + public function getRecordID(string $zoneID, string $type = '', string $name = ''): string + { + $records = $this->listRecords($zoneID, $type, $name); + if (isset($records->result{0}->id)) { + return $records->result{0}->id; + } + return false; + } + public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass { $response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details); diff --git a/src/Endpoints/FirewallSettings.php b/src/Endpoints/FirewallSettings.php new file mode 100644 index 0000000..36e49fd --- /dev/null +++ b/src/Endpoints/FirewallSettings.php @@ -0,0 +1,135 @@ +adapter = $adapter; + } + + /** + * Get the Security Level feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getSecurityLevelSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/security_level' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Get the Challenge TTL feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return integer|false + */ + public function getChallengeTTLSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/challenge_ttl' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Get the Browser Integrity Check feature for a zone. + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getBrowserIntegrityCheckSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/browser_check' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Update the Security Level setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateSecurityLevelSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/security_level', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the Challenge TTL setting for the zone + * + * @param string $zoneID The ID of the zone + * @param int $value The value of the zone setting + * @return bool + */ + public function updateChallengeTTLSetting(string $zoneID, int $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/challenge_ttl', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the Browser Integrity Check setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateBrowserIntegrityCheckSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/browser_check', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } +} diff --git a/src/Endpoints/LoadBalancers.php b/src/Endpoints/LoadBalancers.php new file mode 100644 index 0000000..7813d31 --- /dev/null +++ b/src/Endpoints/LoadBalancers.php @@ -0,0 +1,157 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +namespace Cloudflare\API\Endpoints; + +use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Configurations\ConfigurationsException; +use Cloudflare\API\Configurations\LoadBalancer; +use Cloudflare\API\Traits\BodyAccessorTrait; + +class LoadBalancers implements API +{ + use BodyAccessorTrait; + + private $adapter; + + public function __construct(Adapter $adapter) + { + $this->adapter = $adapter; + } + + /** + * @param string $zoneID + * @return mixed + */ + public function listLoadBalancers(string $zoneID) + { + $loadBalancers = $this->adapter->get('zones/' . $zoneID . '/load_balancers'); + $this->body = json_decode($loadBalancers->getBody()); + + return $this->body->result; + } + + /** + * @param string $zoneID + * @param string $loadBalancerID + * @return mixed + */ + public function getLoadBalancerDetails(string $zoneID, string $loadBalancerID) + { + $loadBalancer = $this->adapter->get('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID); + $this->body = json_decode($loadBalancer->getBody()); + return $this->body->result; + } + + /** + * @param string $zoneID + * @param string $loadBalancerID + * @return LoadBalancer + * @throws ConfigurationsException + */ + public function getLoadBalancerConfiguration(string $zoneID, string $loadBalancerID) + { + $loadBalancer = $this->getLoadBalancerDetails($zoneID, $loadBalancerID); + + $lbConfiguration = new LoadBalancer($loadBalancer->name, $loadBalancer->default_pools, $loadBalancer->fallback_pool); + $lbConfiguration->setSteeringPolicy($loadBalancer->steering_policy); + if ($loadBalancer->enabled === true) { + $lbConfiguration->enable(); + } elseif ($loadBalancer->enabled === false) { + $lbConfiguration->disable(); + } + + if (is_array($loadBalancer->pop_pools)) { + $lbConfiguration->setPopPools($loadBalancer->pop_pools); + } + + if (isset($loadBalancer->ttl)) { + $lbConfiguration->setTtl($loadBalancer->ttl); + } + + if (is_array($loadBalancer->region_pools)) { + $lbConfiguration->setRegionPools($loadBalancer->region_pools); + } + $lbConfiguration->setSessionAffinity($loadBalancer->session_affinity); + $lbConfiguration->setDescription($loadBalancer->description); + if ($loadBalancer->proxied === true) { + $lbConfiguration->enableProxied(); + } elseif ($loadBalancer->proxied === false) { + $lbConfiguration->disableProxied(); + } + + if (isset($loadBalancer->session_affinity_ttl)) { + $lbConfiguration->setSessionAffinityTtl($loadBalancer->session_affinity_ttl); + } + + return $lbConfiguration; + } + + /** + * @param string $zoneID + * @param string $loadBalancerID + * @param LoadBalancer $lbConfiguration + * @return bool + */ + public function updateLoadBalancer( + string $zoneID, + string $loadBalancerID, + LoadBalancer $lbConfiguration + ): bool { + $options = $lbConfiguration->getArray(); + + $query = $this->adapter->put('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID, $options); + + $this->body = json_decode($query->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + + /** + * @param string $zoneID + * @param LoadBalancer $lbConfiguration + * @return bool + */ + public function createLoadBalancer( + string $zoneID, + LoadBalancer $lbConfiguration + ): bool { + $options = $lbConfiguration->getArray(); + + $query = $this->adapter->post('zones/' . $zoneID . '/load_balancers', $options); + + $this->body = json_decode($query->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + + /** + * @param string $zoneID + * @param string $loadBalancerID + * @return bool + */ + public function deleteLoadBalancer(string $zoneID, string $loadBalancerID): bool + { + $loadBalancer = $this->adapter->delete('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID); + + $this->body = json_decode($loadBalancer->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } +} diff --git a/src/Endpoints/Membership.php b/src/Endpoints/Membership.php new file mode 100644 index 0000000..6a783cb --- /dev/null +++ b/src/Endpoints/Membership.php @@ -0,0 +1,83 @@ +adapter = $adapter; + } + + + public function listMemberships( + string $name = '', + string $status = '', + int $page = 1, + int $perPage = 20, + string $order = '', + string $direction = '' + ): \stdClass { + $query = [ + 'page' => $page, + 'per_page' => $perPage + ]; + + if (!empty($name)) { + $query['account.name'] = $name; + } + + if (!empty($status) && in_array($status, ['accepted', 'pending', 'rejected'], true)) { + $query['status'] = $status; + } + + if (!empty($order) && in_array($order, ['id', 'account.name', 'status'], true)) { + $query['order'] = $order; + } + + if (!empty($direction) && in_array($direction, ['asc', 'desc'], true)) { + $query['direction'] = $direction; + } + + $memberships = $this->adapter->get('memberships', $query); + $this->body = json_decode($memberships->getBody()); + + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; + } + + public function getMembershipDetails(string $membershipId): \stdClass + { + $membership = $this->adapter->get(sprintf('memberships/%s', $membershipId)); + $this->body = json_decode($membership->getBody()); + return $this->body->result; + } + + public function updateMembershipStatus(string $membershipId, string $status): \stdClass + { + $response = $this->adapter->put(sprintf('memberships/%s', $membershipId), ['status' => $status]); + $this->body = json_decode($response->getBody()); + return $this->body; + } + + public function deleteMembership(string $membershipId): bool + { + $response = $this->adapter->delete(sprintf('memberships/%s', $membershipId)); + + $this->body = json_decode($response->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } +} diff --git a/src/Endpoints/PageRules.php b/src/Endpoints/PageRules.php index 3e56007..c8480f4 100644 --- a/src/Endpoints/PageRules.php +++ b/src/Endpoints/PageRules.php @@ -73,19 +73,19 @@ class PageRules implements API string $direction = null, string $match = null ): array { - if ($status === null && !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.'); } - if ($order === null && !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.'); } - if ($direction === null && !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.'); } - if ($match === null && !in_array($match, ['all', 'any'])) { + if ($match != null && !in_array($match, ['all', 'any'])) { throw new EndpointException('Match can only be any or all.'); } @@ -111,6 +111,7 @@ class PageRules implements API public function updatePageRule( string $zoneID, + string $ruleID, PageRulesTargets $target = null, PageRulesActions $actions = null, bool $active = null, @@ -134,8 +135,7 @@ class PageRules implements API $options['priority'] = $priority; } - - $query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', $options); + $query = $this->adapter->patch('zones/' . $zoneID . '/pagerules/' . $ruleID, $options); $this->body = json_decode($query->getBody()); diff --git a/src/Endpoints/Pools.php b/src/Endpoints/Pools.php new file mode 100644 index 0000000..f6ceb59 --- /dev/null +++ b/src/Endpoints/Pools.php @@ -0,0 +1,156 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +namespace Cloudflare\API\Endpoints; + +use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Configurations\ConfigurationsException; +use Cloudflare\API\Configurations\Pool; +use Cloudflare\API\Traits\BodyAccessorTrait; + +class Pools implements API +{ + use BodyAccessorTrait; + + private $adapter; + + public function __construct(Adapter $adapter) + { + $this->adapter = $adapter; + } + + /** + * @param string $accountID + * @return mixed + */ + public function listPools(string $accountID) + { + $pools = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools'); + $this->body = json_decode($pools->getBody()); + + return $this->body->result; + } + + /** + * @param string $accountID + * @param string $poolID + * @return mixed + */ + public function getPoolDetails(string $accountID, string $poolID) + { + $pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID); + $this->body = json_decode($pool->getBody()); + return $this->body->result; + } + + /** + * @param string $accountID + * @param string $poolID + * @return mixed + */ + public function getPoolHealthDetails(string $accountID, string $poolID) + { + $pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID . '/health'); + $this->body = json_decode($pool->getBody()); + return $this->body->result; + } + + /** + * @param string $accountID + * @param string $poolID + * @return Pool + * @throws ConfigurationsException + */ + public function getPoolConfiguration(string $accountID, string $poolID) + { + $pool = $this->getPoolDetails($accountID, $poolID); + + $origins = []; + foreach ($pool->origins as $origin) { + $origins[] = (array)$origin; + } + $poolConfiguration = new Pool($pool->name, $origins); + $poolConfiguration->setDescription($pool->description); + if ($pool->enabled === true) { + $poolConfiguration->enable(); + } elseif ($pool->enabled === false) { + $poolConfiguration->disable(); + } + $poolConfiguration->setMonitor($pool->monitor); + $poolConfiguration->setNotificationEmail($pool->notification_email); + + if (is_array($pool->check_regions)) { + $poolConfiguration->setCheckRegions($pool->check_regions); + } + + return $poolConfiguration; + } + + /** + * @param string $accountID + * @param string $poolID + * @param Pool $poolConfiguration + * @return bool + */ + public function updatePool( + string $accountID, + string $poolID, + Pool $poolConfiguration + ): bool { + $options = $poolConfiguration->getArray(); + + $query = $this->adapter->put('accounts/' . $accountID . '/load_balancers/pools/' . $poolID, $options); + + $this->body = json_decode($query->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + + /** + * @param string $accountID + * @param Pool $poolConfiguration + * @return bool + */ + public function createPool( + string $accountID, + Pool $poolConfiguration + ): bool { + $options = $poolConfiguration->getArray(); + + $query = $this->adapter->post('accounts/' . $accountID . '/load_balancers/pools', $options); + + $this->body = json_decode($query->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + + /** + * @param string $accountID + * @param string $poolID + * @return bool + */ + public function deletePool(string $accountID, string $poolID): bool + { + $pool = $this->adapter->delete('accounts/' . $accountID . '/load_balancers/pools/' . $poolID); + + $this->body = json_decode($pool->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } +} diff --git a/src/Endpoints/SSL.php b/src/Endpoints/SSL.php new file mode 100644 index 0000000..2ed506b --- /dev/null +++ b/src/Endpoints/SSL.php @@ -0,0 +1,183 @@ +adapter = $adapter; + } + + /** + * Get the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getSSLSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/ssl' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + * + * Get SSL Verification Info for a Zone + * + * @param string $zoneID The ID of the zone + * @param bool $retry Immediately retry SSL Verification + * @return array|false + */ + public function getSSLVerificationStatus(string $zoneID, bool $retry = false) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/ssl/verification', + [ + 'retry' => $retry + ] + ); + + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body; + } + return false; + } + + /** + * Get the HTTPS Redirect setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getHTTPSRedirectSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/always_use_https' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Get the HTTPS Rewrite setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getHTTPSRewritesSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Update the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateSSLSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/ssl', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the HTTPS Redirect setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRedirectSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/always_use_https', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the HTTPS Rewrite setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRewritesSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the SSL certificate pack validation method + * + * @param string $zoneID The ID of the zone + * @param string $certPackUUID The certificate pack UUID + * @param string $validationMethod The verification method + * @return bool + */ + public function updateSSLCertificatePackValidationMethod(string $zoneID, string $certPackUUID, string $validationMethod) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/ssl/verification/' . $certPackUUID, + [ + 'validation_method' => $validationMethod, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } +} diff --git a/src/Endpoints/TLS.php b/src/Endpoints/TLS.php index d92a8b7..8519896 100644 --- a/src/Endpoints/TLS.php +++ b/src/Endpoints/TLS.php @@ -19,52 +19,103 @@ class TLS implements API $this->adapter = $adapter; } + /** + * Get the TLS Client Auth setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getTLSClientAuth($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/tls_client_auth' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Enable TLS 1.3 for the zone + * + * @param string $zoneID The ID of the zone + * @return bool + */ public function enableTLS13($zoneID) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/tls_1_3', ['value' => 'on'] ); - $body = json_decode($return->getBody()); - - if ($body->success) { + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { return true; } - return false; } + /** + * Disable TLS 1.3 for the zone + * + * @param string $zoneID The ID of the zone + * @return bool + */ public function disableTLS13($zoneID) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/tls_1_3', ['value' => 'off'] ); - $body = json_decode($return->getBody()); - - if ($body->success) { + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { return true; } - return false; } - - + /** + * Update the minimum TLS version setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $minimumVersion The version to update to + * @return bool + */ public function changeMinimumTLSVersion($zoneID, $minimumVersion) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/min_tls_version', [ - 'value' => $minimumVersion + 'value' => $minimumVersion, ] ); - $body = json_decode($return->getBody()); - - if ($body->success) { + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { return true; } + return false; + } + /** + * Update the TLS Client Auth setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateTLSClientAuth($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/tls_client_auth', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } return false; } } diff --git a/src/Endpoints/ZoneSettings.php b/src/Endpoints/ZoneSettings.php new file mode 100644 index 0000000..a32b84f --- /dev/null +++ b/src/Endpoints/ZoneSettings.php @@ -0,0 +1,180 @@ +adapter = $adapter; + } + + public function getMinifySetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/minify' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function getRocketLoaderSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/rocket_loader' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function getAlwaysOnlineSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/always_online' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function getEmailObfuscationSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/email_obfuscation' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function getHotlinkProtectionSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/hotlink_protection' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function updateMinifySetting($zoneID, $html, $css, $javascript) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/minify', + [ + 'value' => [ + 'html' => $html, + 'css' => $css, + 'js' => $javascript, + ], + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateRocketLoaderSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/rocket_loader', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateAlwaysOnlineSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/always_online', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateEmailObfuscationSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/email_obfuscation', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + + public function updateHotlinkProtectionSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/hotlink_protection', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } +} diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index 22db2ee..bbd3564 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -72,6 +72,15 @@ class Zones implements API return false; } + + public function getZoneById( + string $zoneId + ): \stdClass { + $user = $this->adapter->get('zones/' . $zoneId); + $this->body = json_decode($user->getBody()); + + return (object)['result' => $this->body->result]; + } public function listZones( string $name = '', @@ -159,6 +168,38 @@ class Zones implements API return false; } + /** + * Return caching level settings + * @param string $zoneID + * @return string + */ + public function getCachingLevel(string $zoneID): string + { + $response = $this->adapter->get('zones/' . $zoneID . '/settings/cache_level'); + + $this->body = json_decode($response->getBody()); + + return $this->body->result->value; + } + + /** + * Change caching level settings + * @param string $zoneID + * @param string $level (aggressive | basic | simplified) + * @return bool + */ + public function setCachingLevel(string $zoneID, string $level = 'aggressive'): bool + { + $response = $this->adapter->patch('zones/' . $zoneID . '/settings/cache_level', ['value' => $level]); + + $this->body = json_decode($response->getBody()); + + if ($this->body->success) { + return true; + } + + return false; + } /** * Purge Everything @@ -207,4 +248,18 @@ class Zones implements API return false; } + + /** + * Delete Zone + */ + public function deleteZone(string $identifier): bool + { + $user = $this->adapter->delete('zones/' . $identifier); + $this->body = json_decode($user->getBody()); + if (isset($this->body->result->id)) { + return true; + } + + return false; + } } diff --git a/tests/Configurations/LoadBalancerTest.php b/tests/Configurations/LoadBalancerTest.php new file mode 100644 index 0000000..96b3d1e --- /dev/null +++ b/tests/Configurations/LoadBalancerTest.php @@ -0,0 +1,56 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +use Cloudflare\API\Configurations\ConfigurationsException; +use Cloudflare\API\Configurations\LoadBalancer; + +class LoadBalancerTest extends TestCase +{ + /** + * @dataProvider testArgumentsDataProvider + */ + public function testArguments($setFunction, $arguments, $getFunction, $invalid) + { + $loadBalancer = new LoadBalancer('bogus', [], 'bogus'); + foreach ($arguments as $argument) { + if ($invalid === true) { + try { + $loadBalancer->{$setFunction}($argument); + } catch (ConfigurationsException $e) { + $this->assertNotEquals($argument, $loadBalancer->{$getFunction}()); + } + } elseif ($invalid === false) { + $loadBalancer->{$setFunction}($argument); + $this->assertEquals($argument, $loadBalancer->{$getFunction}()); + } + } + } + + public function testArgumentsDataProvider() + { + return [ + 'steeringPolicy arguments valid' => [ + 'setSteeringPolicy', ['off', 'geo', 'random', 'dynamic_latency', ''], 'getSteeringPolicy', false + ], + 'sessionAffinity arguments valid' => [ + 'setSessionAffinity', ['none', 'cookie', 'ip_cookie', ''], 'getSessionAffinity', false + ], + 'sessionAffinityTtl arguments valid' => [ + 'setSessionAffinityTtl', [3600], 'getSessionAffinityTtl', false + ], + 'steeringPolicy arguments invalid' => [ + 'setSteeringPolicy', ['invalid'], 'getSteeringPolicy', true + ], + 'sessionAffinity arguments invalid' => [ + 'setSessionAffinity', ['invalid'], 'getSessionAffinity', true + ], + 'sessionAffinityTtl arguments invalid' => [ + 'setSessionAffinityTtl', [1337], 'getSessionAffinityTtl', true + ], + ]; + } +} diff --git a/tests/Configurations/PoolTest.php b/tests/Configurations/PoolTest.php new file mode 100644 index 0000000..204b392 --- /dev/null +++ b/tests/Configurations/PoolTest.php @@ -0,0 +1,53 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +use Cloudflare\API\Configurations\ConfigurationsException; +use Cloudflare\API\Configurations\Pool; + +class PoolTest extends TestCase +{ + /** + * @dataProvider testArgumentsDataProvider + */ + public function testArguments($setFunction, $arguments, $getFunction, $invalid) + { + $pool = new Pool('bogus', []); + foreach ($arguments as $argument) { + if ($invalid) { + try { + $pool->{$setFunction}($argument); + } catch (ConfigurationsException $e) { + $this->assertNotEquals($argument, $pool->{$getFunction}()); + } + } elseif ($invalid === false) { + $pool->{$setFunction}($argument); + $this->assertEquals($argument, $pool->{$getFunction}()); + } + } + } + + public function testArgumentsDataProvider() + { + return [ + 'origins arguments valid' => [ + 'setOrigins', [[['name' => 'test', 'address' => 'server1.example.com']]], 'getOrigins', false + ], + 'setNotificationEmail arguments valid' => [ + 'setNotificationEmail', ['user@example.com'], 'getNotificationEmail', false + ], + 'origins arguments invalid no address' => [ + 'setOrigins', [['name' => 'test']], 'getOrigins', true + ], + 'origins arguments invalid no name' => [ + 'setOrigins', [['address' => 'server1.example.com']], 'getOrigins', true + ], + 'setNotificationEmail arguments invalid' => [ + 'setNotificationEmail', ['userexample.com'], 'getNotificationEmail', true + ] + ]; + } +} diff --git a/tests/Endpoints/CryptoTest.php b/tests/Endpoints/CryptoTest.php new file mode 100644 index 0000000..6f617fd --- /dev/null +++ b/tests/Endpoints/CryptoTest.php @@ -0,0 +1,82 @@ +getPsr7JsonResponseForFixture('Endpoints/getOpportunisticEncryptionSetting.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/settings/opportunistic_encryption') + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->getOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testGetOnionRoutingSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getOnionRoutingSetting.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/settings/opportunistic_onion') + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->getOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testUpdateOpportunisticEncryptionSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.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/opportunistic_encryption'), + $this->equalTo(['value' => 'off']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } + + public function testUpdateOnionRoutingSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.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/opportunistic_onion'), + $this->equalTo(['value' => 'off']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } +} diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index 11c21fa..27f6030 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -86,6 +86,25 @@ class DNSTest extends TestCase $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id); } + public function testGetRecordID() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordId.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/dns_records') + ); + + $dns = new \Cloudflare\API\Endpoints\DNS($mock); + $result = $dns->getRecordID('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com'); + + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result); + } + public function testUpdateDNSRecord() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json'); diff --git a/tests/Endpoints/FirewallSettingsTest.php b/tests/Endpoints/FirewallSettingsTest.php new file mode 100644 index 0000000..b8bc289 --- /dev/null +++ b/tests/Endpoints/FirewallSettingsTest.php @@ -0,0 +1,121 @@ +getPsr7JsonResponseForFixture('Endpoints/getSecurityLevelSetting.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/settings/security_level') + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->getSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('medium', $result); + } + + public function testGetChallengeTTLSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getChallengeTTLSetting.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/settings/challenge_ttl') + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->getChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals(1800, $result); + } + + public function testGetBrowserIntegrityCheckSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserIntegrityCheckSetting.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/settings/browser_check') + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->getBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('on', $result); + } + + public function testUpdateSecurityLevelSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSecurityLevelSetting.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/security_level'), + $this->equalTo(['value' => 'medium']) + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->updateSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'medium'); + + $this->assertTrue($result); + } + + public function testUpdateChallengeTTLSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateChallengeTTLSetting.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/challenge_ttl'), + $this->equalTo(['value' => 1800]) + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->updateChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 1800); + + $this->assertTrue($result); + } + + public function testUpdateBrowserIntegrityCheckSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserIntegrityCheckSetting.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/browser_check'), + $this->equalTo(['value' => 'on']) + ); + + $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock); + $result = $firewallSettingsMock->updateBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'on'); + + $this->assertTrue($result); + } +} diff --git a/tests/Endpoints/LoadBalancersTest.php b/tests/Endpoints/LoadBalancersTest.php new file mode 100644 index 0000000..93418d4 --- /dev/null +++ b/tests/Endpoints/LoadBalancersTest.php @@ -0,0 +1,128 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +class LoadBalancersTest extends TestCase +{ + public function testCreateLoadBalancer() + { + $pools = [ + '17b5962d775c646f3f9725cbc7a53df4', + '9290f38c5d07c2e2f4df57b1f61d4196', + '00920f38ce07c2e2f4df50b1f61d4194' + ]; + + $lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4'); + + $response = $this->getPsr7JsonResponseForFixture('Endpoints/createLoadBalancer.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('post')->willReturn($response); + + $mock->expects($this->once()) + ->method('post') + ->with( + $this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers'), + $lbConfiguration->getArray() + ); + + $loadBalancers = new LoadBalancers($mock); + $result = $loadBalancers->createLoadBalancer('699d98642c564d2e855e9661899b7252', $lbConfiguration); + + $this->assertTrue($result); + $this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id); + } + + public function testListLoadBalancer() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/listLoadBalancers.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers') + ); + + $loadBalancers = new LoadBalancers($mock); + $loadBalancers->listLoadBalancers('699d98642c564d2e855e9661899b7252'); + $this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result[0]->id); + } + + public function testGetLoadBalancerDetails() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getLoadBalancerDetails.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252') + ); + + $loadBalancers = new LoadBalancers($mock); + $loadBalancers->getLoadBalancerDetails('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252'); + $this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id); + } + + public function testUpdateLoadBalancer() + { + $pools = [ + '17b5962d775c646f3f9725cbc7a53df4', + '9290f38c5d07c2e2f4df57b1f61d4196', + '00920f38ce07c2e2f4df50b1f61d4194' + ]; + + $lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4'); + + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLoadBalancer.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('put')->willReturn($response); + + $mock->expects($this->once()) + ->method('put') + ->with( + $this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252'), + $this->equalTo($lbConfiguration->getArray()) + ); + + $loadBalancers = new LoadBalancers($mock); + $result = $loadBalancers->updateLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252', $lbConfiguration); + + $this->assertTrue($result); + $this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id); + } + + public function testDeleteLoadBalancer() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLoadBalancer.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('delete')->willReturn($response); + + $mock->expects($this->once()) + ->method('delete') + ->with( + $this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252') + ); + + $loadBalancers = new LoadBalancers($mock); + $result = $loadBalancers->deleteLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252'); + + $this->assertTrue($result); + $this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id); + } +} diff --git a/tests/Endpoints/MembershipTest.php b/tests/Endpoints/MembershipTest.php new file mode 100644 index 0000000..3f93c1e --- /dev/null +++ b/tests/Endpoints/MembershipTest.php @@ -0,0 +1,93 @@ +getPsr7JsonResponseForFixture('Endpoints/listMemberships.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('memberships'), + $this->equalTo([ + 'page' => 1, + 'per_page' => 20, + 'account.name' => 'Demo Account', + 'status' => 'accepted', + 'order' => 'status', + 'direction' => 'desc', + ]) + ); + + $zones = new \Cloudflare\API\Endpoints\Membership($mock); + $result = $zones->listMemberships('Demo Account', 'accepted', 1, 20, 'status', 'desc'); + + $this->assertObjectHasAttribute('result', $result); + $this->assertObjectHasAttribute('result_info', $result); + + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id); + $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $zones->getBody()->result[0]->id); + } + + public function testGetMembershipDetails() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getMembershipDetails.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $membership = new \Cloudflare\API\Endpoints\Membership($mock); + $details = $membership->getMembershipDetails('4536bcfad5faccb111b47003c79917fa'); + + $this->assertObjectHasAttribute('id', $details); + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $details->id); + $this->assertObjectHasAttribute('code', $details); + $this->assertEquals('05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0', $details->code); + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id); + } + + public function testUpdateMembershipDetails() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateMembershipStatus.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('put')->willReturn($response); + + $mock->expects($this->once()) + ->method('put') + ->with( + $this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'), + $this->equalTo([ + 'status' => 'accepted' + ]) + ); + + $membership = new \Cloudflare\API\Endpoints\Membership($mock); + $membership->updateMembershipStatus('4536bcfad5faccb111b47003c79917fa', 'accepted'); + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id); + } + + public function testDeleteMembership() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteMembership.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('delete')->willReturn($response); + + $mock->expects($this->once()) + ->method('delete') + ->with($this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa')); + + $membership = new \Cloudflare\API\Endpoints\Membership($mock); + + $membership->deleteMembership('4536bcfad5faccb111b47003c79917fa'); + + $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id); + } +} diff --git a/tests/Endpoints/PageRulesTest.php b/tests/Endpoints/PageRulesTest.php index f2813fd..f16815a 100644 --- a/tests/Endpoints/PageRulesTest.php +++ b/tests/Endpoints/PageRulesTest.php @@ -49,7 +49,7 @@ class PageRulesTest extends TestCase ->method('get') ->with( $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), - $this->equalTo([ + $this->equalTo([ 'status' => 'active', 'order' => 'status', 'direction' => 'desc', @@ -94,7 +94,7 @@ class PageRulesTest extends TestCase $mock->expects($this->once()) ->method('patch') ->with( - $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([ 'targets' => $target->getArray(), 'actions' => $action->getArray(), @@ -104,7 +104,7 @@ class PageRulesTest extends TestCase ); $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); - $result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1); + $result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac', $target, $action, true, 1); $this->assertTrue($result); $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id); diff --git a/tests/Endpoints/PoolsTest.php b/tests/Endpoints/PoolsTest.php new file mode 100644 index 0000000..9846f48 --- /dev/null +++ b/tests/Endpoints/PoolsTest.php @@ -0,0 +1,133 @@ + + * User: HemeraOne + * Date: 13/05/2019 + */ + +class PoolsTest extends TestCase +{ + public function testCreatePool() + { + $origins = [ + [ + 'name' => 'app-server-1', + 'address' => '0.0.0.0', + 'enabled' => true, + 'weight' => 0.56 + ] + ]; + + $poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins); + + $response = $this->getPsr7JsonResponseForFixture('Endpoints/createPool.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('post')->willReturn($response); + + $mock->expects($this->once()) + ->method('post') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools'), + $poolConfiguration->getArray() + ); + + $pools = new Pools($mock); + $result = $pools->createPool('01a7362d577a6c3019a474fd6f485823', $poolConfiguration); + + $this->assertTrue($result); + $this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id); + } + + public function testListPools() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/listPools.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools') + ); + + $pools = new Pools($mock); + $pools->listPools('01a7362d577a6c3019a474fd6f485823'); + $this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result[0]->id); + } + + public function testGetPoolDetails() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getPoolDetails.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4') + ); + + $pools = new Pools($mock); + $pools->getPoolDetails('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4'); + $this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id); + } + + public function testUpdatePool() + { + $origins = [ + [ + 'name' => 'app-server-1', + 'address' => '0.0.0.0', + 'enabled' => true, + 'weight' => 0.56 + ] + ]; + + $poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins); + + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePool.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('put')->willReturn($response); + + $mock->expects($this->once()) + ->method('put') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4'), + $this->equalTo($poolConfiguration->getArray()) + ); + + $pools = new Pools($mock); + $result = $pools->updatePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4', $poolConfiguration); + + $this->assertTrue($result); + $this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id); + } + + public function testDeletePool() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePool.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('delete')->willReturn($response); + + $mock->expects($this->once()) + ->method('delete') + ->with( + $this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4') + ); + + $pools = new Pools($mock); + $result = $pools->deletePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4'); + + $this->assertTrue($result); + $this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id); + } +} diff --git a/tests/Endpoints/SSLTest.php b/tests/Endpoints/SSLTest.php new file mode 100644 index 0000000..1f0fc53 --- /dev/null +++ b/tests/Endpoints/SSLTest.php @@ -0,0 +1,161 @@ +getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.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/settings/ssl') + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testGetSSLVerificationStatus() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.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/ssl/verification') + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertObjectHasAttribute('result', $result); + $this->assertEquals('active', $result->result{0}->certificate_status); + } + + public function testGetHTTPSRedirectSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.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/settings/always_use_https') + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testGetHTTPSRewritesSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.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/settings/automatic_https_rewrites') + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testUpdateSSLSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.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/ssl'), + $this->equalTo(['value' => 'full']) + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full'); + + $this->assertTrue($result); + } + + public function testUpdateHTTPSRedirectSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.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/always_use_https'), + $this->equalTo(['value' => 'off']) + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } + + public function testUpdateHTTPSRewritesSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.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/automatic_https_rewrites'), + $this->equalTo(['value' => 'off']) + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } + + public function testUpdateSSLCertificatePackValidationMethod() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLCertificatePackValidationMethod.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/ssl/verification/a77f8bd7-3b47-46b4-a6f1-75cf98109948'), + $this->equalTo(['validation_method' => 'txt']) + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'txt'); + + $this->assertTrue($result); + } +} diff --git a/tests/Endpoints/TLSTest.php b/tests/Endpoints/TLSTest.php index d17aabb..cf0018c 100644 --- a/tests/Endpoints/TLSTest.php +++ b/tests/Endpoints/TLSTest.php @@ -9,6 +9,25 @@ class TLSTest extends TestCase { + public function testGetTLSClientAuth() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getTLSClientAuth.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/settings/tls_client_auth') + ); + + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->getTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + public function testEnableTLS13() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/enableTLS13.json'); @@ -23,8 +42,8 @@ class TLSTest extends TestCase $this->equalTo(['value' => 'on']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); } @@ -43,8 +62,8 @@ class TLSTest extends TestCase $this->equalTo(['value' => 'off']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); } @@ -63,8 +82,28 @@ class TLSTest extends TestCase $this->equalTo(['value' => '1.1']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1'); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1'); + + $this->assertTrue($result); + } + + public function testUpdateTLSClientAuth() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateTLSClientAuth.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/tls_client_auth'), + $this->equalTo(['value' => 'off']) + ); + + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->updateTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); $this->assertTrue($result); } diff --git a/tests/Endpoints/UARulesTest.php b/tests/Endpoints/UARulesTest.php index fec94b5..8406745 100644 --- a/tests/Endpoints/UARulesTest.php +++ b/tests/Endpoints/UARulesTest.php @@ -19,10 +19,10 @@ class UARulesTest extends TestCase ->method('get') ->with( $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), - $this->equalTo([ - 'page' => 1, - 'per_page' => 20 - ]) + $this->equalTo([ + 'page' => 1, + 'per_page' => 20 + ]) ); $zones = new \Cloudflare\API\Endpoints\UARules($mock); diff --git a/tests/Endpoints/ZoneDeleteTest.php b/tests/Endpoints/ZoneDeleteTest.php new file mode 100644 index 0000000..5ffd4e1 --- /dev/null +++ b/tests/Endpoints/ZoneDeleteTest.php @@ -0,0 +1,19 @@ +getPsr7JsonResponseForFixture('Endpoints/deleteZoneTest.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') + ); + $zones = new \Cloudflare\API\Endpoints\Zones($mock); + $result = $zones->deleteZone('023e105f4ecef8ad9ca31a8372d0c353'); + $this->assertTrue($result); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id); + } +} diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index a95f690..d0158bf 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -125,6 +125,25 @@ class ZonesTest extends TestCase $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id); } + public function testGetZoneByID() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneById.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')); + + $zones = new \Cloudflare\API\Endpoints\Zones($mock); + $result = $zones->getZoneById('023e105f4ecef8ad9ca31a8372d0c353'); + + $this->assertInstanceOf(\stdClass::class, $result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); + $this->assertEquals('example.com', $zones->getBody()->result->name); + } + public function testGetZoneID() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneId.json'); diff --git a/tests/Fixtures/Endpoints/createLoadBalancer.json b/tests/Fixtures/Endpoints/createLoadBalancer.json new file mode 100644 index 0000000..3316cdd --- /dev/null +++ b/tests/Fixtures/Endpoints/createLoadBalancer.json @@ -0,0 +1,46 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "699d98642c564d2e855e9661899b7252", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Load Balancer for www.example.com", + "name": "www.example.com", + "enabled": true, + "ttl": 30, + "fallback_pool": "17b5962d775c646f3f9725cbc7a53df4", + "default_pools": [ + "17b5962d775c646f3f9725cbc7a53df4", + "9290f38c5d07c2e2f4df57b1f61d4196", + "00920f38ce07c2e2f4df50b1f61d4194" + ], + "region_pools": { + "WNAM": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "ENAM": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "pop_pools": { + "LAX": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "LHR": [ + "abd90f38ced07c2e2f4df50b1f61d4194", + "f9138c5d07c2e2f4df57b1f61d4196" + ], + "SJC": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "proxied": true, + "steering_policy": "dynamic_latency", + "session_affinity": "cookie", + "session_affinity_ttl": 5000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/createPool.json b/tests/Fixtures/Endpoints/createPool.json new file mode 100644 index 0000000..e1397a1 --- /dev/null +++ b/tests/Fixtures/Endpoints/createPool.json @@ -0,0 +1,28 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "17b5962d775c646f3f9725cbc7a53df4", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Primary data center - Provider XYZ", + "name": "primary-dc-1", + "enabled": true, + "minimum_origins": 2, + "monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc", + "check_regions": [ + "WEU", + "ENAM" + ], + "origins": [ + { + "name": "app-server-1", + "address": "0.0.0.0", + "enabled": true, + "weight": 0.56 + } + ], + "notification_email": "someone@example.com" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/deleteLoadBalancer.json b/tests/Fixtures/Endpoints/deleteLoadBalancer.json new file mode 100644 index 0000000..7744044 --- /dev/null +++ b/tests/Fixtures/Endpoints/deleteLoadBalancer.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "699d98642c564d2e855e9661899b7252" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/deleteMembership.json b/tests/Fixtures/Endpoints/deleteMembership.json new file mode 100644 index 0000000..02111aa --- /dev/null +++ b/tests/Fixtures/Endpoints/deleteMembership.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "4536bcfad5faccb111b47003c79917fa" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/deletePool.json b/tests/Fixtures/Endpoints/deletePool.json new file mode 100644 index 0000000..96c4395 --- /dev/null +++ b/tests/Fixtures/Endpoints/deletePool.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "17b5962d775c646f3f9725cbc7a53df4" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/deleteZoneTest.json b/tests/Fixtures/Endpoints/deleteZoneTest.json new file mode 100644 index 0000000..2951fe4 --- /dev/null +++ b/tests/Fixtures/Endpoints/deleteZoneTest.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "9a7806061c88ada191ed06f989cc3dac" + } +} diff --git a/tests/Fixtures/Endpoints/getBrowserIntegrityCheckSetting.json b/tests/Fixtures/Endpoints/getBrowserIntegrityCheckSetting.json new file mode 100644 index 0000000..cdfe4ee --- /dev/null +++ b/tests/Fixtures/Endpoints/getBrowserIntegrityCheckSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "browser_check", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getChallengeTTLSetting.json b/tests/Fixtures/Endpoints/getChallengeTTLSetting.json new file mode 100644 index 0000000..ee6edf1 --- /dev/null +++ b/tests/Fixtures/Endpoints/getChallengeTTLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "challenge_ttl", + "value": 1800, + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json b/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json b/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getLoadBalancerDetails.json b/tests/Fixtures/Endpoints/getLoadBalancerDetails.json new file mode 100644 index 0000000..3316cdd --- /dev/null +++ b/tests/Fixtures/Endpoints/getLoadBalancerDetails.json @@ -0,0 +1,46 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "699d98642c564d2e855e9661899b7252", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Load Balancer for www.example.com", + "name": "www.example.com", + "enabled": true, + "ttl": 30, + "fallback_pool": "17b5962d775c646f3f9725cbc7a53df4", + "default_pools": [ + "17b5962d775c646f3f9725cbc7a53df4", + "9290f38c5d07c2e2f4df57b1f61d4196", + "00920f38ce07c2e2f4df50b1f61d4194" + ], + "region_pools": { + "WNAM": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "ENAM": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "pop_pools": { + "LAX": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "LHR": [ + "abd90f38ced07c2e2f4df50b1f61d4194", + "f9138c5d07c2e2f4df57b1f61d4196" + ], + "SJC": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "proxied": true, + "steering_policy": "dynamic_latency", + "session_affinity": "cookie", + "session_affinity_ttl": 5000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getMembershipDetails.json b/tests/Fixtures/Endpoints/getMembershipDetails.json new file mode 100644 index 0000000..b3d65f3 --- /dev/null +++ b/tests/Fixtures/Endpoints/getMembershipDetails.json @@ -0,0 +1,70 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "4536bcfad5faccb111b47003c79917fa", + "code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", + "status": "accepted", + "account": { + "id": "01a7362d577a6c3019a474fd6f485823", + "name": "Demo Account", + "settings": { + "enforce_twofactor": false + } + }, + "roles": [ + "Account Administrator" + ], + "permissions": { + "analytics": { + "read": true, + "write": true + }, + "billing": { + "read": true, + "write": true + }, + "cache_purge": { + "read": true, + "write": true + }, + "dns": { + "read": true, + "write": true + }, + "dns_records": { + "read": true, + "write": true + }, + "lb": { + "read": true, + "write": true + }, + "logs": { + "read": true, + "write": true + }, + "organization": { + "read": true, + "write": true + }, + "ssl": { + "read": true, + "write": true + }, + "waf": { + "read": true, + "write": true + }, + "zones": { + "read": true, + "write": true + }, + "zone_settings": { + "read": true, + "write": true + } + } +} +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getOnionRoutingSetting.json b/tests/Fixtures/Endpoints/getOnionRoutingSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getOnionRoutingSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json b/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json new file mode 100644 index 0000000..b5df0a4 --- /dev/null +++ b/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "opportunistic_encryption", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getPoolDetails.json b/tests/Fixtures/Endpoints/getPoolDetails.json new file mode 100644 index 0000000..e1397a1 --- /dev/null +++ b/tests/Fixtures/Endpoints/getPoolDetails.json @@ -0,0 +1,28 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "17b5962d775c646f3f9725cbc7a53df4", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Primary data center - Provider XYZ", + "name": "primary-dc-1", + "enabled": true, + "minimum_origins": 2, + "monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc", + "check_regions": [ + "WEU", + "ENAM" + ], + "origins": [ + { + "name": "app-server-1", + "address": "0.0.0.0", + "enabled": true, + "weight": 0.56 + } + ], + "notification_email": "someone@example.com" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getRecordId.json b/tests/Fixtures/Endpoints/getRecordId.json new file mode 100644 index 0000000..63f92c6 --- /dev/null +++ b/tests/Fixtures/Endpoints/getRecordId.json @@ -0,0 +1,29 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "372e67954025e0ba6aaa6d586b9e0b59", + "type": "A", + "name": "example.com", + "content": "198.51.100.4", + "proxiable": true, + "proxied": false, + "ttl": {}, + "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, + "total_pages": 1, + "count": 1, + "total_count": 1 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getSSLSetting.json b/tests/Fixtures/Endpoints/getSSLSetting.json new file mode 100644 index 0000000..43fa3ee --- /dev/null +++ b/tests/Fixtures/Endpoints/getSSLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "ssl", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getSSLVerificationStatus.json b/tests/Fixtures/Endpoints/getSSLVerificationStatus.json new file mode 100644 index 0000000..5e2a4f3 --- /dev/null +++ b/tests/Fixtures/Endpoints/getSSLVerificationStatus.json @@ -0,0 +1,16 @@ +{ + "result": [ + { + "certificate_status": "active", + "verification_type": "cname", + "verification_status": true, + "verification_info": { + "record_name": "b3b90cfedd89a3e487d3e383c56c4267.example.com", + "record_target": "6979be7e4cfc9e5c603e31df7efac9cc60fee82d.comodoca.com" + }, + "brand_check": false, + "validation_method": "txt", + "cert_pack_uuid": "a77f8bd7-3b47-46b4-a6f1-75cf98109948" + } + ] +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getSecurityLevelSetting.json b/tests/Fixtures/Endpoints/getSecurityLevelSetting.json new file mode 100644 index 0000000..bbbf241 --- /dev/null +++ b/tests/Fixtures/Endpoints/getSecurityLevelSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "security_level", + "value": "medium", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getTLSClientAuth.json b/tests/Fixtures/Endpoints/getTLSClientAuth.json new file mode 100644 index 0000000..fac9fa5 --- /dev/null +++ b/tests/Fixtures/Endpoints/getTLSClientAuth.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "tls_client_auth", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getZoneById.json b/tests/Fixtures/Endpoints/getZoneById.json new file mode 100644 index 0000000..bbe6fdb --- /dev/null +++ b/tests/Fixtures/Endpoints/getZoneById.json @@ -0,0 +1,59 @@ +{ + "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", + "activated_on": "2014-01-02T00:01:00.12345Z", + "owner": { + "id": "7c5dae5552338874e5053f2534d2767a", + "email": "user@example.com", + "type": "user" + }, + "account": { + "id": "01a7362d577a6c3019a474fd6f485823", + "name": "Demo Account" + }, + "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", + "name_servers": [ + "tony.ns.cloudflare.com", + "woz.ns.cloudflare.com" + ] + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/listLoadBalancers.json b/tests/Fixtures/Endpoints/listLoadBalancers.json new file mode 100644 index 0000000..47a3b12 --- /dev/null +++ b/tests/Fixtures/Endpoints/listLoadBalancers.json @@ -0,0 +1,54 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "699d98642c564d2e855e9661899b7252", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Load Balancer for www.example.com", + "name": "www.example.com", + "enabled": true, + "ttl": 30, + "fallback_pool": "17b5962d775c646f3f9725cbc7a53df4", + "default_pools": [ + "17b5962d775c646f3f9725cbc7a53df4", + "9290f38c5d07c2e2f4df57b1f61d4196", + "00920f38ce07c2e2f4df50b1f61d4194" + ], + "region_pools": { + "WNAM": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "ENAM": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "pop_pools": { + "LAX": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "LHR": [ + "abd90f38ced07c2e2f4df50b1f61d4194", + "f9138c5d07c2e2f4df57b1f61d4196" + ], + "SJC": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "proxied": true, + "steering_policy": "dynamic_latency", + "session_affinity": "cookie", + "session_affinity_ttl": 5000 + } + ], + "result_info": { + "page": 1, + "per_page": 20, + "count": 1, + "total_count": 2000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/listMemberships.json b/tests/Fixtures/Endpoints/listMemberships.json new file mode 100644 index 0000000..0e209d3 --- /dev/null +++ b/tests/Fixtures/Endpoints/listMemberships.json @@ -0,0 +1,78 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "4536bcfad5faccb111b47003c79917fa", + "code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", + "status": "accepted", + "account": { + "id": "01a7362d577a6c3019a474fd6f485823", + "name": "Demo Account", + "settings": { + "enforce_twofactor": false + } + }, + "roles": [ + "Account Administrator" + ], + "permissions": { + "analytics": { + "read": true, + "write": true + }, + "billing": { + "read": true, + "write": true + }, + "cache_purge": { + "read": true, + "write": true + }, + "dns": { + "read": true, + "write": true + }, + "dns_records": { + "read": true, + "write": true + }, + "lb": { + "read": true, + "write": true + }, + "logs": { + "read": true, + "write": true + }, + "organization": { + "read": true, + "write": true + }, + "ssl": { + "read": true, + "write": true + }, + "waf": { + "read": true, + "write": true + }, + "zones": { + "read": true, + "write": true + }, + "zone_settings": { + "read": true, + "write": true + } + } + } + ], + "result_info": { + "page": 1, + "per_page": 20, + "count": 1, + "total_count": 2000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/listPools.json b/tests/Fixtures/Endpoints/listPools.json new file mode 100644 index 0000000..2c7a471 --- /dev/null +++ b/tests/Fixtures/Endpoints/listPools.json @@ -0,0 +1,36 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "17b5962d775c646f3f9725cbc7a53df4", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Primary data center - Provider XYZ", + "name": "primary-dc-1", + "enabled": true, + "minimum_origins": 2, + "monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc", + "check_regions": [ + "WEU", + "ENAM" + ], + "origins": [ + { + "name": "app-server-1", + "address": "0.0.0.0", + "enabled": true, + "weight": 0.56 + } + ], + "notification_email": "someone@example.com" + } + ], + "result_info": { + "page": 1, + "per_page": 20, + "count": 1, + "total_count": 2000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateBrowserIntegrityCheckSetting.json b/tests/Fixtures/Endpoints/updateBrowserIntegrityCheckSetting.json new file mode 100644 index 0000000..cdfe4ee --- /dev/null +++ b/tests/Fixtures/Endpoints/updateBrowserIntegrityCheckSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "browser_check", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateChallengeTTLSetting.json b/tests/Fixtures/Endpoints/updateChallengeTTLSetting.json new file mode 100644 index 0000000..ee6edf1 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateChallengeTTLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "challenge_ttl", + "value": 1800, + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json b/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json b/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateLoadBalancer.json b/tests/Fixtures/Endpoints/updateLoadBalancer.json new file mode 100644 index 0000000..3316cdd --- /dev/null +++ b/tests/Fixtures/Endpoints/updateLoadBalancer.json @@ -0,0 +1,46 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "699d98642c564d2e855e9661899b7252", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Load Balancer for www.example.com", + "name": "www.example.com", + "enabled": true, + "ttl": 30, + "fallback_pool": "17b5962d775c646f3f9725cbc7a53df4", + "default_pools": [ + "17b5962d775c646f3f9725cbc7a53df4", + "9290f38c5d07c2e2f4df57b1f61d4196", + "00920f38ce07c2e2f4df50b1f61d4194" + ], + "region_pools": { + "WNAM": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "ENAM": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "pop_pools": { + "LAX": [ + "de90f38ced07c2e2f4df50b1f61d4194", + "9290f38c5d07c2e2f4df57b1f61d4196" + ], + "LHR": [ + "abd90f38ced07c2e2f4df50b1f61d4194", + "f9138c5d07c2e2f4df57b1f61d4196" + ], + "SJC": [ + "00920f38ce07c2e2f4df50b1f61d4194" + ] + }, + "proxied": true, + "steering_policy": "dynamic_latency", + "session_affinity": "cookie", + "session_affinity_ttl": 5000 + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateMembershipStatus.json b/tests/Fixtures/Endpoints/updateMembershipStatus.json new file mode 100644 index 0000000..978f58f --- /dev/null +++ b/tests/Fixtures/Endpoints/updateMembershipStatus.json @@ -0,0 +1,70 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "4536bcfad5faccb111b47003c79917fa", + "code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0", + "status": "accepted", + "account": { + "id": "01a7362d577a6c3019a474fd6f485823", + "name": "Demo Account", + "settings": { + "enforce_twofactor": false + } + }, + "roles": [ + "Account Administrator" + ], + "permissions": { + "analytics": { + "read": true, + "write": true + }, + "billing": { + "read": true, + "write": true + }, + "cache_purge": { + "read": true, + "write": true + }, + "dns": { + "read": true, + "write": true + }, + "dns_records": { + "read": true, + "write": true + }, + "lb": { + "read": true, + "write": true + }, + "logs": { + "read": true, + "write": true + }, + "organization": { + "read": true, + "write": true + }, + "ssl": { + "read": true, + "write": true + }, + "waf": { + "read": true, + "write": true + }, + "zones": { + "read": true, + "write": true + }, + "zone_settings": { + "read": true, + "write": true + } + } + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json b/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json b/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json new file mode 100644 index 0000000..e8077c9 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "opportunistic_encryption", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updatePool.json b/tests/Fixtures/Endpoints/updatePool.json new file mode 100644 index 0000000..e1397a1 --- /dev/null +++ b/tests/Fixtures/Endpoints/updatePool.json @@ -0,0 +1,28 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "17b5962d775c646f3f9725cbc7a53df4", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "description": "Primary data center - Provider XYZ", + "name": "primary-dc-1", + "enabled": true, + "minimum_origins": 2, + "monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc", + "check_regions": [ + "WEU", + "ENAM" + ], + "origins": [ + { + "name": "app-server-1", + "address": "0.0.0.0", + "enabled": true, + "weight": 0.56 + } + ], + "notification_email": "someone@example.com" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json new file mode 100644 index 0000000..5e2d5e2 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json @@ -0,0 +1,9 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "validation_method": "txt", + "status": "pending_validation" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateSSLSetting.json b/tests/Fixtures/Endpoints/updateSSLSetting.json new file mode 100644 index 0000000..43fa3ee --- /dev/null +++ b/tests/Fixtures/Endpoints/updateSSLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "ssl", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateSecurityLevelSetting.json b/tests/Fixtures/Endpoints/updateSecurityLevelSetting.json new file mode 100644 index 0000000..bbbf241 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateSecurityLevelSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "security_level", + "value": "medium", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateTLSClientAuth.json b/tests/Fixtures/Endpoints/updateTLSClientAuth.json new file mode 100644 index 0000000..fac9fa5 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateTLSClientAuth.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "tls_client_auth", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file