diff --git a/README.md b/README.md index 0d5bb00..fd68ff1 100755 --- a/README.md +++ b/README.md @@ -38,5 +38,5 @@ $account = new Incapsula\API\Endpoints\Account($adapter); $account_id = 123456; -print_r($account->getStatus($account_id)); +print_r($account->listSites($account_id)); ``` diff --git a/src/Endpoints/Endpoint.php b/src/Endpoint.php similarity index 92% rename from src/Endpoints/Endpoint.php rename to src/Endpoint.php index a1900bc..029158e 100755 --- a/src/Endpoints/Endpoint.php +++ b/src/Endpoint.php @@ -1,6 +1,6 @@ $account_id] : []; - - $query = $this->getAdapter()->request('/api/prov/v1/account', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->account; - } - - public function getToken(int $account_id = null): string - { - $options = $account_id !== null ? ['account_id' => $account_id] : []; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/gettoken', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->generated_token; - } - - public function getSubscription(int $account_id = null): \stdClass - { - $options = $account_id !== null ? ['account_id' => $account_id] : []; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/subscription', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - // - // Managed Accounts - // - - public function getList(int $account_id = null, array $pagination_options = []): array - { - $options = $account_id !== null ? ['account_id' => $account_id] : []; - $options = array_merge($pagination_options, $options); - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/list', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->accounts; - } - - public function add(string $email, array $account_options = []): \stdClass - { - $options = array_merge($account_options, ['email' => $email]); - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->account; - } - - public function delete(int $account_id): bool - { - $options = [ - 'account_id' => $account_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/delete', $options); - - $this->body = json_decode($query->getBody()); - return true; - } - - // - // Logs - // - - public function setLogLevel(int $account_id, string $level): bool - { - $options = [ - 'account_id' => $account_id, - 'log_level' => $level - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/setlog', $options); - - $this->body = json_decode($query->getBody()); - return true; - } - - public function testS3Connection( - int $account_id, - string $bucket_name, - string $access_key, - string $secret_key, - bool $save_on_success = false - ): bool { - $options = [ - 'account_id' => $account_id, - 'bucket_name' => $bucket_name, - 'access_key' => $access_key, - 'secret_key' => $secret_key, - 'save_on_success' => $save_on_success - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/testS3Connection', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Connection test succeeded'); - } - - public function testSFTPConnection( - int $account_id, - string $host, - string $user_name, - string $password, - string $destination_folder, - bool $save_on_success = false - ): bool { - $options = [ - 'account_id' => $account_id, - 'host' => $host, - 'user_name' => $user_name, - 'password' => $password, - 'destination_folder' => $destination_folder, - 'save_on_success' => $save_on_success - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/testSftpConnection', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Connection test succeeded'); - } - - public function setAmazomSiemStorage( - int $account_id, - string $bucket_name, - string $access_key, - string $secret_key - ): bool { - $options = [ - 'account_id' => $account_id, - 'bucket_name' => $bucket_name, - 'access_key' => $access_key, - 'secret_key' => $secret_key - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/setAmazonSiemStorage', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); - } - - public function setSFTPSiemStorage( - int $account_id, - string $host, - string $user_name, - string $password, - string $destination_folder - ): bool { - $options = [ - 'account_id' => $account_id, - 'host' => $host, - 'user_name' => $user_name, - 'password' => $password, - 'destination_folder' => $destination_folder - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/setSftpSiemStorage', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); - } - - public function setDefaultSiemStorage(int $account_id): bool - { - $options = [ - 'account_id' => $account_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/setDefaultSiemStorage', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); - } -} + $account_id] : []; + + $query = $this->getAdapter()->request('/api/prov/v1/account', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->account; + } + + public function getLoginToken(int $account_id = null): string + { + $options = $account_id !== null ? ['account_id' => $account_id] : []; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/gettoken', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->generated_token; + } + + public function getSubscriptionDetails(int $account_id = null): \stdClass + { + $options = $account_id !== null ? ['account_id' => $account_id] : []; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/subscription', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + // + // Managed Accounts + // + + public function listManagedAccounts(int $account_id = null, array $pagination_options = []): array + { + $options = $account_id !== null ? ['account_id' => $account_id] : []; + $options = array_merge($pagination_options, $options); + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/list', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->accounts; + } + + public function addManagedAccount(string $email, array $account_options = []): \stdClass + { + $options = array_merge($account_options, ['email' => $email]); + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->account; + } + + public function deleteManagedAccount(int $account_id): bool + { + $options = [ + 'account_id' => $account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/delete', $options); + + $this->body = json_decode($query->getBody()); + return true; + } + + // + // Sub Accounts + // + + public function listSubAccounts(int $account_id = null, $pagination_options = null): array + { + $options = $account_id !== null ? ['account_id' => $account_id] : []; + $options = array_merge($pagination_options, $options); + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/listSubAccounts', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->resultList; + } + + public function addSubAccount(string $name, array $account_options = []): \stdClass + { + $options = array_merge($account_options, ['sub_account_name' => $name]); + + $query = $this->getAdapter()->request('/api/prov/v1/subaccounts/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->sub_account; + } + + public function deleteSubAccount(int $sub_account_id): bool + { + $options = [ + 'sub_account_id' => $sub_account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/subaccounts/delete', $options); + + $this->body = json_decode($query->getBody()); + return true; + } + + // + // Logs + // + + public function setLogLevel(int $account_id, string $level): bool + { + $options = [ + 'account_id' => $account_id, + 'log_level' => $level + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/setlog', $options); + + $this->body = json_decode($query->getBody()); + return true; + } + + public function testS3Connection( + int $account_id, + string $bucket_name, + string $access_key, + string $secret_key, + bool $save_on_success = false + ): bool { + $options = [ + 'account_id' => $account_id, + 'bucket_name' => $bucket_name, + 'access_key' => $access_key, + 'secret_key' => $secret_key, + 'save_on_success' => $save_on_success + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/testS3Connection', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Connection test succeeded'); + } + + public function testSFTPConnection( + int $account_id, + string $host, + string $user_name, + string $password, + string $destination_folder, + bool $save_on_success = false + ): bool { + $options = [ + 'account_id' => $account_id, + 'host' => $host, + 'user_name' => $user_name, + 'password' => $password, + 'destination_folder' => $destination_folder, + 'save_on_success' => $save_on_success + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/testSftpConnection', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Connection test succeeded'); + } + + public function setAmazomSiemStorage( + int $account_id, + string $bucket_name, + string $access_key, + string $secret_key + ): bool { + $options = [ + 'account_id' => $account_id, + 'bucket_name' => $bucket_name, + 'access_key' => $access_key, + 'secret_key' => $secret_key + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/setAmazonSiemStorage', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); + } + + public function setSFTPSiemStorage( + int $account_id, + string $host, + string $user_name, + string $password, + string $destination_folder + ): bool { + $options = [ + 'account_id' => $account_id, + 'host' => $host, + 'user_name' => $user_name, + 'password' => $password, + 'destination_folder' => $destination_folder + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/setSftpSiemStorage', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); + } + + public function setDefaultSiemStorage(int $account_id): bool + { + $options = [ + 'account_id' => $account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/setDefaultSiemStorage', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->message) && $this->body->debug_info->message == 'Configuration was successfully updated'); + } + + public function setConfig(int $account_id, string $param, $value): bool + { + $options = [ + 'account_id' => $account_id, + 'param' => $param, + 'value' => $value + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/configure', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->{$param}) && $this->body->debug_info->{$param} == $value); + } + + public function getDefaultStorageRegion(int $account_id): string + { + $options = [ + 'account_id' => $account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/data-privacy/show', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->region; + } + + public function setDefaultStorageRegion(int $account_id, string $region): bool + { + $options = [ + 'account_id' => $account_id, + 'region' => $region + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/accounts/data-privacy/set-region-default', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } +} diff --git a/src/Endpoints/Accounts/BaseClass.php b/src/Endpoints/Accounts/BaseClass.php deleted file mode 100755 index edc2593..0000000 --- a/src/Endpoints/Accounts/BaseClass.php +++ /dev/null @@ -1,22 +0,0 @@ -accountID = $account_id; - parent::__construct($adapter); - } - - public function getAccountID() - { - return $this->accountID; - } -} diff --git a/src/Endpoints/Accounts/Configure.php b/src/Endpoints/Accounts/Configure.php deleted file mode 100755 index b99555d..0000000 --- a/src/Endpoints/Accounts/Configure.php +++ /dev/null @@ -1,22 +0,0 @@ - $this->getAccountID(), - 'param' => $param, - 'value' => $value - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/configure', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->{$param}) && $this->body->debug_info->{$param} == $value); - } -} diff --git a/src/Endpoints/Accounts/DataPrivacy.php b/src/Endpoints/Accounts/DataPrivacy.php deleted file mode 100755 index 989ed13..0000000 --- a/src/Endpoints/Accounts/DataPrivacy.php +++ /dev/null @@ -1,33 +0,0 @@ - $this->getAccountID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/data-privacy/show', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->region; - } - - public function setDefault(string $region): bool - { - $options = [ - 'account_id' => $this->getAccountID(), - 'region' => $region - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/data-privacy/set-region-default', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } -} diff --git a/src/Endpoints/Domain.php b/src/Endpoints/Domain.php deleted file mode 100755 index 1b68578..0000000 --- a/src/Endpoints/Domain.php +++ /dev/null @@ -1,18 +0,0 @@ - $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/domain/emails', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->domain_emails; - } -} diff --git a/src/Endpoints/Sites.php b/src/Endpoints/Site.php similarity index 77% rename from src/Endpoints/Sites.php rename to src/Endpoints/Site.php index 64c0311..9c8643b 100755 --- a/src/Endpoints/Sites.php +++ b/src/Endpoints/Site.php @@ -1,438 +1,417 @@ - $site_id - ]; - - if (isset($tests)) { - $options['tests'] = $tests; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/status', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function listSites(int $account_id = null, array $pagination_options = []): array - { - $options = $account_id !== null ? [ - 'account_id' => $account_id - ] : []; - - $sites = $this->getAdapter()->request('api/prov/v1/sites/list', $options, $pagination_options); - - $this->body = json_decode($sites->getBody()); - return $this->body->sites; - } - - public function addSite(int $account_id, array $options): \stdClass - { - $options = array_merge($options, [ - 'account_id' => $account_id - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function deleteSite(int $site_id): bool - { - $query = $this->getAdapter()->request('/api/prov/v1/sites/delete', ['site_id' => $site_id]); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function setLogLevel(int $site_id, string $level): bool - { - $options = [ - 'site_id' => $site_id, - 'log_level' => $level - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/setlog', $options); - - $this->body = json_decode($query->getBody()); - return ($this->body->debug_info->log_level == $level); - } - - public function setSupportTLS(int $site_id, bool $support): \stdClass - { - $options = [ - 'site_id' => $site_id, - 'support_all_tls_versions' => $support - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/tls', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->debug_info; - } - - public function getReport( - int $site_id, - string $report, - string $format, - string $time_range, - array $time_options = [] - ): \stdClass { - $options = array_merge($time_options, [ - 'site_id' => $site_id, - 'report' => $report, - 'format' => $format, - 'time_range' => $time_range - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/report', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function purgeCache(int $site_id, string $pattern = null, string $tag_names = null): bool - { - $options = [ - 'site_id' => $site_id - ]; - - if (isset($pattern)) { - $options['pattern'] = $pattern; - } - if (isset($tag_names)) { - $options['tag_names'] = $tag_names; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/cache/purge', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getGeeTest(int $site_id): \stdClass - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/geetest-level', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setGeeTest(int $site_id, string $algorithm): \stdClass - { - $options = [ - 'site_id' => $site_id, - 'challenge_algorithm' => $algorithm - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/geetest-level/modify', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function purgeHostnameCache(int $site_id, string $host_name): bool - { - $options = [ - 'site_id' => $site_id, - 'host_name' => $host_name - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/hostname/purge', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function uploadCustomCertificate( - int $site_id, - string $crt_base64, - string $key_base64 = null, - string $passphrase = null - ): \stdClass { - $options = [ - 'site_id' => $site_id, - 'certificate' => $crt_base64 - ]; - - if (isset($key_base64)) { - $options['private_key'] = $key_base64; - } - if (isset($passphrase)) { - $options['passphrase'] = $passphrase; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/upload', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function removeCustomCertificate(int $site_id, string $host_name): bool - { - $options = [ - 'site_id' => $site_id, - 'host_name' => $host_name - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/remove', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function createCSR( - int $site_id, - string $email = null, - string $org = null, - string $org_unit = null, - string $country = null, - string $state = null, - string $city = null - ): string { - $options = [ - 'site_id' => $site_id - ]; - - if (isset($email)) { - $options['email'] = $email; - } - if (isset($org)) { - $options['organization'] = $org; - } - if (isset($org_unit)) { - $options['organization_unit'] = $org_unit; - } - if (isset($country)) { - $options['country'] = $country; - } - if (isset($state)) { - $options['state'] = $state; - } - if (isset($city)) { - $options['city'] = $city; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/csr', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->csr_content; - } - - public function addIncapRule( - int $site_id, - string $name, - string $action, - array $rule_options = [] - ): \stdClass { - $options = array_merge($rule_options, [ - 'site_id' => $site_id, - 'name' => $name, - 'action' => $action - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function updateIncapRule( - int $rule_id, - string $action, - array $rule_options = [] - ): \stdClass { - $options = array_merge($rule_options, [ - 'rule_id' => $rule_id, - 'action' => $action - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/edit', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function enableDisableIncapRule(int $rule_id, bool $enable): \stdClass - { - $options = [ - 'rule_id' => $rule_id, - 'enabled' => $enable - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/enableDisable', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function deleteIncapRule(int $rule_id): \stdClass - { - $options = [ - 'rule_id' => $rule_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/delete', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function listIncapRules( - int $site_id, - bool $inc_delivery = null, - bool $inc_incap = null, - array $pagination_options = [] - ): \stdClass { - $options = array_merge($pagination_options, [ - 'site_id' => $site_id - ]); - - if (isset($inc_delivery)) { - $options['include_ad_rules'] = $inc_delivery; - } - if (isset($inc_incap)) { - $options['include_incap_rules'] = $inc_incap; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/list', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function listAccountIncapRules( - int $account_id, - bool $inc_delivery = null, - bool $inc_incap = null - ): \stdClass { - $options = [ - 'account_id' => $account_id - ]; - - if (isset($inc_delivery)) { - $options['include_ad_rules'] = $inc_delivery; - } - if (isset($inc_incap)) { - $options['include_incap_rules'] = $inc_incap; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/account/list', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setIncapRulePriority(int $rule_id, int $priority): \stdClass - { - $options = [ - 'rule_id' => $rule_id, - 'priority' => $priority - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/priority/set', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function getXRayLink(int $site_id): \stdClass - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/xray/get-link', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setDataStorageRegion(int $site_id, string $region): bool - { - $options = [ - 'site_id' => $site_id, - 'data_storage_region' => $region - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/region-change', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getDataStorageRegion(int $site_id): string - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/show', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->region; - } - - public function setDataStorageRegionByGeo(int $account_id, bool $value): bool - { - $options = [ - 'account_id' => $account_id, - 'override_site_regions_by_geo' => $value - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/override-by-geo', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function isDataStorageRegionByGeoEnabled(int $account_id): bool - { - $options = [ - 'account_id' => $account_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/show-override-by-geo', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->override_site_regions_by_geo; - } - - public function checkCompliance(int $site_id): array - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/caa/check-compliance', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->non_compliant_sans; - } - - public function moveSite(int $site_id, int $account_id): \stdClass - { - $options = [ - 'site_id' => $site_id, - 'destination_account_id' => $account_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/moveSite', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } -} + $site_id + ]; + + if (isset($tests)) { + $options['tests'] = $tests; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/status', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function listSites(int $account_id = null, array $pagination_options = []): array + { + $options = $account_id !== null ? [ + 'account_id' => $account_id + ] : []; + + $sites = $this->getAdapter()->request('api/prov/v1/sites/list', $options, $pagination_options); + + $this->body = json_decode($sites->getBody()); + return $this->body->sites; + } + + public function addSite(int $account_id, array $options): \stdClass + { + $options = array_merge($options, [ + 'account_id' => $account_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function deleteSite(int $site_id): bool + { + $query = $this->getAdapter()->request('/api/prov/v1/sites/delete', ['site_id' => $site_id]); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function setLogLevel(int $site_id, string $level): bool + { + $options = [ + 'site_id' => $site_id, + 'log_level' => $level + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/setlog', $options); + + $this->body = json_decode($query->getBody()); + return ($this->body->debug_info->log_level == $level); + } + + public function setSupportTLS(int $site_id, bool $support): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'support_all_tls_versions' => $support + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/tls', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->debug_info; + } + + public function getReport( + int $site_id, + string $report, + string $format, + string $time_range, + array $time_options = [] + ): \stdClass { + $options = array_merge($time_options, [ + 'site_id' => $site_id, + 'report' => $report, + 'format' => $format, + 'time_range' => $time_range + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/report', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getGeeTest(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/geetest-level', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setGeeTest(int $site_id, string $algorithm): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'challenge_algorithm' => $algorithm + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/geetest-level/modify', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function uploadCustomCertificate( + int $site_id, + string $crt_base64, + string $key_base64 = null, + string $passphrase = null + ): \stdClass { + $options = [ + 'site_id' => $site_id, + 'certificate' => $crt_base64 + ]; + + if (isset($key_base64)) { + $options['private_key'] = $key_base64; + } + if (isset($passphrase)) { + $options['passphrase'] = $passphrase; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/upload', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function removeCustomCertificate(int $site_id, string $host_name): bool + { + $options = [ + 'site_id' => $site_id, + 'host_name' => $host_name + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/remove', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function createCSR( + int $site_id, + string $email = null, + string $org = null, + string $org_unit = null, + string $country = null, + string $state = null, + string $city = null + ): string { + $options = [ + 'site_id' => $site_id + ]; + + if (isset($email)) { + $options['email'] = $email; + } + if (isset($org)) { + $options['organization'] = $org; + } + if (isset($org_unit)) { + $options['organization_unit'] = $org_unit; + } + if (isset($country)) { + $options['country'] = $country; + } + if (isset($state)) { + $options['state'] = $state; + } + if (isset($city)) { + $options['city'] = $city; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/customCertificate/csr', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->csr_content; + } + + public function setDataStorageRegion(int $site_id, string $region): bool + { + $options = [ + 'site_id' => $site_id, + 'data_storage_region' => $region + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/region-change', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getDataStorageRegion(int $site_id): string + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/show', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->region; + } + + public function setDataStorageRegionByGeo(int $account_id, bool $value): bool + { + $options = [ + 'account_id' => $account_id, + 'override_site_regions_by_geo' => $value + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/override-by-geo', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function isDataStorageRegionByGeoEnabled(int $account_id): bool + { + $options = [ + 'account_id' => $account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/data-privacy/show-override-by-geo', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->override_site_regions_by_geo; + } + + public function checkCompliance(int $site_id): array + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/caa/check-compliance', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->non_compliant_sans; + } + + public function moveSite(int $site_id, int $account_id): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'destination_account_id' => $account_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/moveSite', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getDomainApproverEmails(int $site_id) + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/domain/emails', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->domain_emails; + } + + public function setConfig(int $site_id, string $param, $value): bool + { + $options = [ + 'site_id' => $site_id, + 'param' => $param, + 'value' => $value + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/configure', $options); + + $this->body = json_decode($query->getBody()); + return (isset($this->body->debug_info->{$param}) && $this->body->debug_info->{$param} == $value); + } + + public function setSecurityConfig(int $site_id, string $rule_id, array $options): \stdClass + { + $options = array_merge($options, [ + 'site_id' => $site_id, + 'rule_id' => $rule_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/security', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setACLConfig(int $site_id, string $rule_id, array $options): \stdClass + { + $options = array_merge($options, [ + 'site_id' => $site_id, + 'rule_id' => $rule_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/acl', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setWhitelistConfig( + int $site_id, + string $rule_id, + int $whitelist_id = null, + array $options + ) { + $options = array_merge($options, [ + 'site_id' => $site_id, + 'rule_id' => $rule_id, + ]); + + if (isset($whitelist_id)) { + $options['whitelist_id'] = $whitelist_id; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/whitelists', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getRewritePort(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/rewrite-port', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setRewritePort( + int $site_id, + bool $enabled = null, + int $port = null, + bool $ssl_enabled = null, + int $ssl_port = null + ): \stdClass { + $options = [ + 'site_id' => $site_id + ]; + + if (isset($enabled)) { + $options['rewrite_port_enabled'] = $enabled; + } + if (isset($port)) { + $options['port'] = $port; + } + if (isset($ssl_enabled)) { + $options['rewrite_ssl_port_enabled'] = $ssl_enabled; + } + if (isset($ssl_port)) { + $options['ssl_port'] = $ssl_port; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/rewrite-port/modify', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getErrorPage(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/error-page', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setErrorPage(int $site_id, string $template): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'error_page_template' => $template + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/error-page/modify', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } +} \ No newline at end of file diff --git a/src/Endpoints/Site/CacheRules.php b/src/Endpoints/Site/CacheRules.php new file mode 100755 index 0000000..a2f2093 --- /dev/null +++ b/src/Endpoints/Site/CacheRules.php @@ -0,0 +1,74 @@ + $site_id, + 'name' => $name, + 'action' => $action + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function deleteCacheRule(int $site_id, int $rule_id): bool + { + $options = [ + 'site_id' => $site_id, + 'rule_id' => $rule_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/delete', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function setCacheRule(int $site_id, int $rule_id, array $rule_options = []): \stdClass + { + $options = array_merge($rule_options, [ + 'site_id' => $site_id, + 'rule_id' => $rule_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/edit', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function enableCacheRule(int $site_id, int $rule_id, bool $enabled): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'rule_id' => $rule_id, + 'enable' => $enabled + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/enable', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function listCacheRules(int $site_id, $pagination_options = null): \stdClass + { + $options = array_merge($pagination_options, [ + 'site_id' => $site_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/list', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } +} \ No newline at end of file diff --git a/src/Endpoints/Sites/Performance.php b/src/Endpoints/Site/Caching.php similarity index 54% rename from src/Endpoints/Sites/Performance.php rename to src/Endpoints/Site/Caching.php index e0adf52..5c9c911 100755 --- a/src/Endpoints/Sites/Performance.php +++ b/src/Endpoints/Site/Caching.php @@ -1,396 +1,312 @@ - $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-mode/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->cache_mode; - } - - public function setCacheMode( - string $mode, - string $dyanmic = null, - string $aggressive = null - ): bool { - $options = [ - 'site_id' => $this->getSiteID(), - 'cache_mode' => $mode - ]; - - if (isset($dyanmic)) { - $options['dynamic_cache_duration'] = $dyanmic; - } - if (isset($aggressive)) { - $options['aggressive_cache_duration'] = $aggressive; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-mode', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getSecureResource(): string - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/secure-resources/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->secured_resources_mode; - } - - public function setSecureResource(string $mode): bool - { - $options = [ - 'site_id' => $this->getSiteID(), - 'secured_resources_mode' => $mode - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/secure-resources', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getStaleContent(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/stale-content/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setStaleContent( - bool $stale, - string $mode = null, - int $time = null, - string $time_unit = null - ): bool { - $options = [ - 'site_id' => $this->getSiteID(), - 'serve_stale_content' => $stale - ]; - - if (isset($mode)) { - $options['stale_content_mode'] = $mode; - } - if (isset($time)) { - $options['time'] = $time; - } - if (isset($time_unit)) { - $options['time_unit'] = $time_unit; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/stale-content', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getCache404(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache404', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setCache404( - bool $enable, - int $time = null, - string $time_unit = null - ): \stdClass { - $options = [ - 'site_id' => $this->getSiteID(), - 'enabled' => $enable - ]; - - if (isset($time)) { - $options['time'] = $time; - } - if (isset($time_unit)) { - $options['time_unit'] = $time_unit; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache404/modify', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function purgeResource(string $url, string $pattern, bool $all_resource = null): bool - { - $options = [ - 'site_id' => $this->getSiteID(), - 'resource_url' => $url, - 'resource_pattern' => $pattern - ]; - - if (isset($all_resource)) { - $options['should_purge_all_site_resources'] = $all_resource; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/purge', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getAdvancedCache(string $param): string - { - $options = [ - 'site_id' => $this->getSiteID(), - 'param' => $param - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/advanced/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->{$param}; - } - - public function setAdvancedCache(string $param, $value): bool - { - $options = [ - 'site_id' => $this->getSiteID(), - 'param' => $param, - 'value' => $value - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/advanced', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getCachedResponseHeaders(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/response-headers/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setCachedResponseHeaders(string $headers, bool $cache_all = null): bool - { - $options = array_merge(isset($cache_all) ? [ - 'cache_all_headers' => $cache_all - ] : [ - 'cache_headers' => $headers - ], [ - 'site_id' => $this->getSiteID() - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/response-headers', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function getTagResponse(): string - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/tag-response/get', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->header; - } - - public function setTagResponse(string $header): bool - { - $options = [ - 'site_id' => $this->getSiteID(), - 'header' => $header - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/tag-response', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function addCacheRule(string $name, string $action, array $rule_options = []): \stdClass - { - $options = array_merge($rule_options, [ - 'site_id' => $this->getSiteID(), - 'name' => $name, - 'action' => $action - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function deleteCacheRule(int $rule_id): bool - { - $options = [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/delete', $options); - - $this->body = json_decode($query->getBody()); - return empty((array) $this->body); - } - - public function setCacheRule(int $rule_id, array $rule_options = []): \stdClass - { - $options = array_merge($rule_options, [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/edit', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function enableCacheRule(int $rule_id, bool $enabled): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id, - 'enable' => $enabled - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/enable', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function listCacheRules($pagination_options = null): \stdClass - { - $options = [ 'site_id' => $this->getSiteID() ]; - $options = isset($pagination_options) ? array_merge($options, $pagination_options) : $options; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/caching-rules/list', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function getRewritePort(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/rewrite-port', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setRewritePort( - bool $enabled = null, - int $port = null, - bool $ssl_enabled = null, - int $ssl_port = null - ): \stdClass { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - if (isset($enabled)) { - $options['rewrite_port_enabled'] = $enabled; - } - if (isset($port)) { - $options['port'] = $port; - } - if (isset($ssl_enabled)) { - $options['rewrite_ssl_port_enabled'] = $ssl_enabled; - } - if (isset($ssl_port)) { - $options['ssl_port'] = $ssl_port; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/rewrite-port/modify', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function getErrorPage(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/error-page', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setErrorPage(string $template): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID(), - 'error_page_template' => $template - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/error-page/modify', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function enableCacheShield(bool $enable): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID(), - 'enabled' => $enable - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-shield/enable', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function isCacheShieldEnabled(): \stdClass - { - $options = [ - 'site_id' => $this->getSiteID() - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-shield', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } -} + $site_id + ]; + + if (isset($pattern)) { + $options['pattern'] = $pattern; + } + if (isset($tag_names)) { + $options['tag_names'] = $tag_names; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/cache/purge', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function purgeHostnameCache(int $site_id, string $host_name): bool + { + $options = [ + 'site_id' => $site_id, + 'host_name' => $host_name + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/hostname/purge', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getXRayLink(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/xray/get-link', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getCacheMode(int $site_id): string + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-mode/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->cache_mode; + } + + public function setCacheMode( + int $site_id, + string $mode, + string $dyanmic = null, + string $aggressive = null + ): bool { + $options = [ + 'site_id' => $site_id, + 'cache_mode' => $mode + ]; + + if (isset($dyanmic)) { + $options['dynamic_cache_duration'] = $dyanmic; + } + if (isset($aggressive)) { + $options['aggressive_cache_duration'] = $aggressive; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-mode', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getSecureResourceMode(int $site_id): string + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/secure-resources/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->secured_resources_mode; + } + + public function setSecureResourceMode(int $site_id, string $mode): bool + { + $options = [ + 'site_id' => $site_id, + 'secured_resources_mode' => $mode + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/secure-resources', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getStaleContentSettings(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/stale-content/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setStaleContentSettings( + int $site_id, + bool $stale, + string $mode = null, + int $time = null, + string $time_unit = null + ): bool { + $options = [ + 'site_id' => $site_id, + 'serve_stale_content' => $stale + ]; + + if (isset($mode)) { + $options['stale_content_mode'] = $mode; + } + if (isset($time)) { + $options['time'] = $time; + } + if (isset($time_unit)) { + $options['time_unit'] = $time_unit; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/stale-content', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getCache404Settings(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache404', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setCache404Settings( + int $site_id, + bool $enable, + int $time = null, + string $time_unit = null + ): \stdClass { + $options = [ + 'site_id' => $site_id, + 'enabled' => $enable + ]; + + if (isset($time)) { + $options['time'] = $time; + } + if (isset($time_unit)) { + $options['time_unit'] = $time_unit; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache404/modify', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function purgeResources(int $site_id, string $url, string $pattern, bool $all_resource = null): bool + { + $options = [ + 'site_id' => $site_id, + 'resource_url' => $url, + 'resource_pattern' => $pattern + ]; + + if (isset($all_resource)) { + $options['should_purge_all_site_resources'] = $all_resource; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/purge', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getAdvancedCacheSettings(int $site_id, string $param): string + { + $options = [ + 'site_id' => $site_id, + 'param' => $param + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/advanced/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->{$param}; + } + + public function setAdvancedCacheSettings(int $site_id, string $param, $value): bool + { + $options = [ + 'site_id' => $site_id, + 'param' => $param, + 'value' => $value + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/advanced', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getCachedResponseHeaders(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/response-headers/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setCachedResponseHeaders(int $site_id, string $headers, bool $cache_all = null): bool + { + $options = array_merge(isset($cache_all) ? [ + 'cache_all_headers' => $cache_all + ] : [ + 'cache_headers' => $headers + ], [ + 'site_id' => $site_id + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/response-headers', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function getTagResponseHeader(int $site_id): string + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/tag-response/get', $options); + + $this->body = json_decode($query->getBody()); + return $this->body->header; + } + + public function setTagResponseHeader(int $site_id, string $header): bool + { + $options = [ + 'site_id' => $site_id, + 'header' => $header + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/tag-response', $options); + + $this->body = json_decode($query->getBody()); + return empty((array) $this->body); + } + + public function enableCacheShield(int $site_id, bool $enable): \stdClass + { + $options = [ + 'site_id' => $site_id, + 'enabled' => $enable + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-shield/enable', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function isCacheShieldEnabled(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/performance/cache-shield', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } +} \ No newline at end of file diff --git a/src/Endpoints/Sites/DataCenter.php b/src/Endpoints/Site/DataCenters.php similarity index 94% rename from src/Endpoints/Sites/DataCenter.php rename to src/Endpoints/Site/DataCenters.php index 52c73ac..56d5899 100755 --- a/src/Endpoints/Sites/DataCenter.php +++ b/src/Endpoints/Site/DataCenters.php @@ -1,191 +1,191 @@ - $site_id, - 'name' => $name, - 'server_address' => $address - ]; - - if (isset($enabled)) { - $options['is_enabled'] = $enabled; - } - if (isset($standby)) { - $options['is_standby'] = $standby; - } - if (isset($content)) { - $options['is_content'] = $content; - } - if (isset($lb_algorithm)) { - $options['lb_algorithm'] = $lb_algorithm; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function editDataCenter( - int $dc_id, - string $name = null, - bool $enabled = null, - bool $standby = null, - bool $content = null - ): \stdClass { - $options = [ - 'dc_id' => $dc_id - ]; - - if (isset($name)) { - $options['name'] = $name; - } - if (isset($enabled)) { - $options['is_enabled'] = $enabled; - } - if (isset($standby)) { - $options['is_standby'] = $standby; - } - if (isset($content)) { - $options['is_content'] = $content; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/edit', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function resumeDataCenterTraffic(int $site_id): \stdClass - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/resume', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function deleteDataCenter(int $dc_id): \stdClass - { - $options = [ - 'dc_id' => $dc_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/delete', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function addServer(int $dc_id, string $address, bool $standby = null): \stdClass - { - $options = [ - 'dc_id' => $dc_id, - 'server_address' => $address - ]; - - if (isset($standby)) { - $options['is_standby'] = $standby; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function editServer( - int $server_id, - string $address = null, - bool $enabled = null, - bool $standby = null - ): \stdClass { - $options = [ - 'server_id' => $server_id - ]; - - if (isset($address)) { - $options['server_address'] = $address; - } - if (isset($enabled)) { - $options['is_enabled'] = $enabled; - } - if (isset($standby)) { - $options['is_standby'] = $standby; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/edit', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function deleteServer(int $server_id): \stdClass - { - $options = [ - 'server_id' => $server_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/delete', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function listDataCenters(int $site_id): \stdClass - { - $options = [ - 'site_id' => $site_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/list', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setDataCenterOriginPOP(int $dc_id, string $origin_pop = null): \stdClass - { - $options = [ - 'dc_id' => $dc_id - ]; - - if (isset($origin_pop)) { - $options['origin_pop'] = $origin_pop; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/datacenter/origin-pop/modify', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function getDataCenterRecommendedOriginPOP(int $dc_id): \stdClass - { - $options = [ - 'dc_id' => $dc_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/datacenter/origin-pop/recommend', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } -} + $site_id, + 'name' => $name, + 'server_address' => $address + ]; + + if (isset($enabled)) { + $options['is_enabled'] = $enabled; + } + if (isset($standby)) { + $options['is_standby'] = $standby; + } + if (isset($content)) { + $options['is_content'] = $content; + } + if (isset($lb_algorithm)) { + $options['lb_algorithm'] = $lb_algorithm; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function editDataCenter( + int $dc_id, + string $name = null, + bool $enabled = null, + bool $standby = null, + bool $content = null + ): \stdClass { + $options = [ + 'dc_id' => $dc_id + ]; + + if (isset($name)) { + $options['name'] = $name; + } + if (isset($enabled)) { + $options['is_enabled'] = $enabled; + } + if (isset($standby)) { + $options['is_standby'] = $standby; + } + if (isset($content)) { + $options['is_content'] = $content; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/edit', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function resumeDataCenterTraffic(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/resume', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function deleteDataCenter(int $dc_id): \stdClass + { + $options = [ + 'dc_id' => $dc_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/delete', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function addServer(int $dc_id, string $address, bool $standby = null): \stdClass + { + $options = [ + 'dc_id' => $dc_id, + 'server_address' => $address + ]; + + if (isset($standby)) { + $options['is_standby'] = $standby; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function editServer( + int $server_id, + string $address = null, + bool $enabled = null, + bool $standby = null + ): \stdClass { + $options = [ + 'server_id' => $server_id + ]; + + if (isset($address)) { + $options['server_address'] = $address; + } + if (isset($enabled)) { + $options['is_enabled'] = $enabled; + } + if (isset($standby)) { + $options['is_standby'] = $standby; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/edit', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function deleteServer(int $server_id): \stdClass + { + $options = [ + 'server_id' => $server_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/servers/delete', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function listDataCenters(int $site_id): \stdClass + { + $options = [ + 'site_id' => $site_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/dataCenters/list', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setDataCenterOriginPOP(int $dc_id, string $origin_pop = null): \stdClass + { + $options = [ + 'dc_id' => $dc_id + ]; + + if (isset($origin_pop)) { + $options['origin_pop'] = $origin_pop; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/datacenter/origin-pop/modify', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function getDataCenterRecommendedOriginPOP(int $dc_id): \stdClass + { + $options = [ + 'dc_id' => $dc_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/datacenter/origin-pop/recommend', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } +} diff --git a/src/Endpoints/Site/Rules.php b/src/Endpoints/Site/Rules.php new file mode 100755 index 0000000..4f1607a --- /dev/null +++ b/src/Endpoints/Site/Rules.php @@ -0,0 +1,125 @@ + $site_id, + 'name' => $name, + 'action' => $action + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/add', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function updateIncapRule( + int $rule_id, + string $action, + array $rule_options = [] + ): \stdClass { + $options = array_merge($rule_options, [ + 'rule_id' => $rule_id, + 'action' => $action + ]); + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/edit', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function enableDisableIncapRule(int $rule_id, bool $enable): \stdClass + { + $options = [ + 'rule_id' => $rule_id, + 'enabled' => $enable + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/enableDisable', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function deleteIncapRule(int $rule_id): \stdClass + { + $options = [ + 'rule_id' => $rule_id + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/delete', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function listIncapRules( + int $site_id, + bool $inc_delivery = null, + bool $inc_incap = null, + array $pagination_options = [] + ): \stdClass { + $options = array_merge($pagination_options, [ + 'site_id' => $site_id + ]); + + if (isset($inc_delivery)) { + $options['include_ad_rules'] = $inc_delivery; + } + if (isset($inc_incap)) { + $options['include_incap_rules'] = $inc_incap; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/list', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function listAccountIncapRules( + int $account_id, + bool $inc_delivery = null, + bool $inc_incap = null + ): \stdClass { + $options = [ + 'account_id' => $account_id + ]; + + if (isset($inc_delivery)) { + $options['include_ad_rules'] = $inc_delivery; + } + if (isset($inc_incap)) { + $options['include_incap_rules'] = $inc_incap; + } + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/account/list', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } + + public function setIncapRulePriority(int $rule_id, int $priority): \stdClass + { + $options = [ + 'rule_id' => $rule_id, + 'priority' => $priority + ]; + + $query = $this->getAdapter()->request('/api/prov/v1/sites/incapRules/priority/set', $options); + + $this->body = json_decode($query->getBody()); + return $this->body; + } +} \ No newline at end of file diff --git a/src/Endpoints/Sites/BaseClass.php b/src/Endpoints/Sites/BaseClass.php deleted file mode 100755 index 61d2f05..0000000 --- a/src/Endpoints/Sites/BaseClass.php +++ /dev/null @@ -1,27 +0,0 @@ -setSiteID($site_id); - parent::__construct($adapter); - } - - public function setSiteID(int $site_id) - { - $this->site_id = $site_id; - } - - public function getSiteID(): int - { - return $this->site_id; - } -} diff --git a/src/Endpoints/Sites/Configure.php b/src/Endpoints/Sites/Configure.php deleted file mode 100755 index abeea8a..0000000 --- a/src/Endpoints/Sites/Configure.php +++ /dev/null @@ -1,68 +0,0 @@ - $this->getSiteID(), - 'param' => $param, - 'value' => $value - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/sites/configure', $options); - - $this->body = json_decode($query->getBody()); - return (isset($this->body->debug_info->{$param}) && $this->body->debug_info->{$param} == $value); - } - - public function setSecurity(string $rule_id, array $options): \stdClass - { - $options = array_merge($options, [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/security', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setACL(string $rule_id, array $options): \stdClass - { - $options = array_merge($options, [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id - ]); - - $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/acl', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } - - public function setWhitelist( - string $rule_id, - int $whitelist_id = null, - array $options - ) { - $options = array_merge($options, [ - 'site_id' => $this->getSiteID(), - 'rule_id' => $rule_id, - ]); - - if (isset($whitelist_id)) { - $options['whitelist_id'] = $whitelist_id; - } - - $query = $this->getAdapter()->request('/api/prov/v1/sites/configure/whitelists', $options); - - $this->body = json_decode($query->getBody()); - return $this->body; - } -} diff --git a/src/Endpoints/SubAccounts.php b/src/Endpoints/SubAccounts.php deleted file mode 100755 index 9e5846b..0000000 --- a/src/Endpoints/SubAccounts.php +++ /dev/null @@ -1,42 +0,0 @@ - $account_id] : []; - $options = array_merge($pagination_options, $options); - - $query = $this->getAdapter()->request('/api/prov/v1/accounts/listSubAccounts', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->resultList; - } - - public function add(string $name, array $account_options = []): \stdClass - { - $options = array_merge($account_options, ['sub_account_name' => $name]); - - $query = $this->getAdapter()->request('/api/prov/v1/subaccounts/add', $options); - - $this->body = json_decode($query->getBody()); - return $this->body->sub_account; - } - - public function delete(int $sub_account_id): bool - { - $options = [ - 'sub_account_id' => $sub_account_id - ]; - - $query = $this->getAdapter()->request('/api/prov/v1/subaccounts/delete', $options); - - $this->body = json_decode($query->getBody()); - return true; - } -} diff --git a/tests/Endpoints/AccountsTest.php b/tests/Endpoints/AccountTest.php similarity index 59% rename from tests/Endpoints/AccountsTest.php rename to tests/Endpoints/AccountTest.php index 2305d9e..e05267c 100755 --- a/tests/Endpoints/AccountsTest.php +++ b/tests/Endpoints/AccountTest.php @@ -1,252 +1,373 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Accounts($this->getAdapter()); - } - return $this->endpoint; - } - - // - // Account Controls - // - - public function testGetStatus() - { - $this->setAdapter('Endpoints/Account/getStatus.json', '/api/prov/v1/account'); - $status = $this->getEndpoint()->getStatus(); - - $this->assertIsObject($status); - - $this->assertObjectHasAttribute('email', $status); - $this->assertEquals('demo_account@imperva.com', $status->email); - $this->assertObjectHasAttribute('plan_name', $status); - $this->assertEquals('Enterprise', $status->plan_name); - } - - public function testToken() - { - $this->setAdapter('Endpoints/Account/getLoginToken.json', '/api/prov/v1/accounts/gettoken'); - $token = $this->getEndpoint()->getToken(); - - $this->assertIsString($token); - $this->assertEquals('344ebcaf34dff34', $token); - } - - public function testGetSubscription() - { - $this->setAdapter('Endpoints/Account/getSubscription.json', '/api/prov/v1/accounts/subscription'); - $subscription = $this->getEndpoint()->getSubscription(); - - $this->assertIsObject($subscription); - - $this->assertObjectHasAttribute('planStatus', $subscription); - $this->assertIsObject($subscription->planStatus); - $this->assertObjectHasAttribute('bandwidthHistory', $subscription); - $this->assertIsArray($subscription->bandwidthHistory); - } - - // - // Managed Accounts - // - - public function testGetList() - { - $this->setAdapter('Endpoints/Account/getAccounts.json', '/api/prov/v1/accounts/list'); - $accounts = $this->getEndpoint()->getList(); - - $this->assertIsArray($accounts); - $this->assertCount(2, $accounts); - - $this->assertObjectHasAttribute('email', $accounts[0]); - $this->assertEquals('demo_account@imperva.com', $accounts[0]->email); - $this->assertObjectHasAttribute('email', $accounts[1]); - $this->assertEquals('demo_account2@imperva.com', $accounts[1]->email); - - $this->assertObjectHasAttribute('logins', $accounts[0]); - $this->assertIsObject($accounts[0]->logins); - - $this->assertObjectHasAttribute('login_id', $accounts[0]->logins); - $this->assertEquals(1243, $accounts[0]->logins->login_id); - } - - public function testAdd() - { - $this->setAdapter( - 'Endpoints/Account/addAccount.json', - '/api/prov/v1/accounts/add', - [ - 'email' => 'demo_account@imperva.com', - 'user_name' => 'John Doe' - ] - ); - - $account = $this->getEndpoint()->add('demo_account@imperva.com', [ - 'user_name' => 'John Doe' - ]); - - $this->assertIsObject($account); - - $this->assertObjectHasAttribute('email', $account); - $this->assertEquals('demo_account@imperva.com', $account->email); - } - - public function testDelete() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/accounts/delete', - [ - 'account_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->delete(12345); - - $this->assertTrue($result); - } - - // - // Logs - // - - public function testSetLogLevel() - { - $this->setAdapter( - 'Endpoints/Account/setLogLevel.json', - '/api/prov/v1/accounts/setlog', - [ - 'account_id' => 12345, - 'log_level' => 'full' - ] - ); - - $result = $this->getEndpoint()->setLogLevel(12345, 'full'); - - $this->assertTrue($result); - } - - public function testTestS3Connection() - { - $this->setAdapter( - 'Endpoints/Account/testConnection.json', - '/api/prov/v1/accounts/testS3Connection', - [ - 'account_id' => 12345, - 'bucket_name' => 'Test-Bucket-Name', - 'access_key' => 'Test-Access-Key', - 'secret_key' => 'Test-Secret-Key', - 'save_on_success' => true - ] - ); - - $result = $this->getEndpoint()->testS3Connection( - 12345, - 'Test-Bucket-Name', - 'Test-Access-Key', - 'Test-Secret-Key', - true - ); - - $this->assertTrue($result); - } - - public function testTestSFTPConnection() - { - $this->setAdapter( - 'Endpoints/Account/testConnection.json', - '/api/prov/v1/accounts/testSftpConnection', - [ - 'account_id' => 12345, - 'host' => '1.1.1.1', - 'user_name' => 'Test-Username', - 'password' => 'Test-Password', - 'destination_folder' => '/test/destination', - 'save_on_success' => true - ] - ); - - $result = $this->getEndpoint()->testSFTPConnection( - 12345, - '1.1.1.1', - 'Test-Username', - 'Test-Password', - '/test/destination', - true - ); - - $this->assertTrue($result); - } - - public function testSetAmazonSiemStorage() - { - $this->setAdapter( - 'Endpoints/Account/setSiemStorage.json', - '/api/prov/v1/accounts/setAmazonSiemStorage', - [ - 'account_id' => 12345, - 'bucket_name' => 'Test-Bucket-Name', - 'access_key' => 'Test-Access-Key', - 'secret_key' => 'Test-Secret-Key' - ] - ); - - $result = $this->getEndpoint()->setAmazomSiemStorage( - 12345, - 'Test-Bucket-Name', - 'Test-Access-Key', - 'Test-Secret-Key' - ); - - $this->assertTrue($result); - } - - public function testSetSFTPSiemStorage() - { - $this->setAdapter( - 'Endpoints/Account/setSiemStorage.json', - '/api/prov/v1/accounts/setSftpSiemStorage', - [ - 'account_id' => 12345, - 'host' => '1.1.1.1', - 'user_name' => 'Test-Username', - 'password' => 'Test-Password', - 'destination_folder' => '/test/destination' - ] - ); - - $result = $this->getEndpoint()->setSFTPSiemStorage( - 12345, - '1.1.1.1', - 'Test-Username', - 'Test-Password', - '/test/destination' - ); - - $this->assertTrue($result); - } - - public function testSetDefaultSiemStorage() - { - $this->setAdapter( - 'Endpoints/Account/setSiemStorage.json', - '/api/prov/v1/accounts/setDefaultSiemStorage', - [ - 'account_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->setDefaultSiemStorage(12345); - - $this->assertTrue($result); - } -} +endpoint)) { + $this->endpoint = new \Incapsula\API\Endpoints\Account($this->getAdapter()); + } + return $this->endpoint; + } + + // + // Account Controls + // + + public function testGetStatus() + { + $this->setAdapter('Endpoints/Account/getStatus.json', '/api/prov/v1/account'); + $status = $this->getEndpoint()->getStatus(); + + $this->assertIsObject($status); + + $this->assertObjectHasAttribute('email', $status); + $this->assertEquals('demo_account@imperva.com', $status->email); + $this->assertObjectHasAttribute('plan_name', $status); + $this->assertEquals('Enterprise', $status->plan_name); + } + + public function testGetLoginToken() + { + $this->setAdapter('Endpoints/Account/getLoginToken.json', '/api/prov/v1/accounts/gettoken'); + $token = $this->getEndpoint()->getLoginToken(); + + $this->assertIsString($token); + $this->assertEquals('344ebcaf34dff34', $token); + } + + public function testGetSubscriptionDetails() + { + $this->setAdapter( + 'Endpoints/Account/getSubscription.json', + '/api/prov/v1/accounts/subscription', + [ + 'account_id' => 12345 + ] + ); + $subscription = $this->getEndpoint()->getSubscriptionDetails(12345); + + $this->assertIsObject($subscription); + + $this->assertObjectHasAttribute('planStatus', $subscription); + $this->assertIsObject($subscription->planStatus); + $this->assertObjectHasAttribute('bandwidthHistory', $subscription); + $this->assertIsArray($subscription->bandwidthHistory); + } + + public function testSetConfig() + { + $this->setAdapter( + 'Endpoints/Account/setConfiguration.json', + '/api/prov/v1/accounts/configure', + [ + 'account_id' => 12345, + 'param' => 'email', + 'value' => 'admin@example.com' + ] + ); + + $result = $this->getEndpoint()->setConfig(12345, 'email', 'admin@example.com'); + + $this->assertTrue($result); + } + + // + // Managed Accounts + // + + public function testListManagedAccounts() + { + $this->setAdapter('Endpoints/Account/getAccounts.json', '/api/prov/v1/accounts/list'); + $accounts = $this->getEndpoint()->listManagedAccounts(); + + $this->assertIsArray($accounts); + $this->assertCount(2, $accounts); + + $this->assertObjectHasAttribute('email', $accounts[0]); + $this->assertEquals('demo_account@imperva.com', $accounts[0]->email); + $this->assertObjectHasAttribute('email', $accounts[1]); + $this->assertEquals('demo_account2@imperva.com', $accounts[1]->email); + + $this->assertObjectHasAttribute('logins', $accounts[0]); + $this->assertIsObject($accounts[0]->logins); + + $this->assertObjectHasAttribute('login_id', $accounts[0]->logins); + $this->assertEquals(1243, $accounts[0]->logins->login_id); + } + + public function testAddManagedAccount() + { + $this->setAdapter( + 'Endpoints/Account/addAccount.json', + '/api/prov/v1/accounts/add', + [ + 'email' => 'demo_account@imperva.com', + 'user_name' => 'John Doe' + ] + ); + + $account = $this->getEndpoint()->addManagedAccount('demo_account@imperva.com', [ + 'user_name' => 'John Doe' + ]); + + $this->assertIsObject($account); + + $this->assertObjectHasAttribute('email', $account); + $this->assertEquals('demo_account@imperva.com', $account->email); + } + + public function testDeleteManagedAccount() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/accounts/delete', + [ + 'account_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->deleteManagedAccount(12345); + + $this->assertTrue($result); + } + + // + // Sub Accounts + // + + public function testListSubAccounts() + { + $this->setAdapter( + 'Endpoints/Account/getSubAccounts.json', + '/api/prov/v1/accounts/listSubAccounts', + [ + 'account_id' => 12345, + 'page_size' => 100, + 'page_num' => 2 + ] + ); + $subAccounts = $this->getEndpoint()->listSubAccounts(12345, [ + 'page_size' => 100, + 'page_num' => 2 + ]); + + $this->assertIsArray($subAccounts); + $this->assertCount(2, $subAccounts); + + $this->assertObjectHasAttribute('sub_account_id', $subAccounts[0]); + $this->assertEquals(123456, $subAccounts[0]->sub_account_id); + $this->assertObjectHasAttribute('sub_account_name', $subAccounts[1]); + $this->assertEquals('My super lovely sub account', $subAccounts[1]->sub_account_name); + } + + public function testAddSubAccount() + { + $this->setAdapter( + 'Endpoints/Account/addSubAccount.json', + '/api/prov/v1/subaccounts/add', + [ + 'sub_account_name' => 'Sub Account Name', + 'user_name' => 'John Doe' + ] + ); + + $subAccount = $this->getEndpoint()->addSubAccount('Sub Account Name', [ + 'user_name' => 'John Doe' + ]); + + $this->assertIsObject($subAccount); + + $this->assertObjectHasAttribute('sub_account_id', $subAccount); + $this->assertEquals(123456, $subAccount->sub_account_id); + $this->assertObjectHasAttribute('support_level', $subAccount); + $this->assertEquals('Standard', $subAccount->support_level); + } + + public function testDeleteSubAccount() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/subaccounts/delete', + [ + 'sub_account_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->deleteSubAccount(12345); + + $this->assertTrue($result); + } + + // + // Logs + // + + public function testSetLogLevel() + { + $this->setAdapter( + 'Endpoints/Account/setLogLevel.json', + '/api/prov/v1/accounts/setlog', + [ + 'account_id' => 12345, + 'log_level' => 'full' + ] + ); + + $result = $this->getEndpoint()->setLogLevel(12345, 'full'); + + $this->assertTrue($result); + } + + public function testTestS3Connection() + { + $this->setAdapter( + 'Endpoints/Account/testConnection.json', + '/api/prov/v1/accounts/testS3Connection', + [ + 'account_id' => 12345, + 'bucket_name' => 'Test-Bucket-Name', + 'access_key' => 'Test-Access-Key', + 'secret_key' => 'Test-Secret-Key', + 'save_on_success' => true + ] + ); + + $result = $this->getEndpoint()->testS3Connection( + 12345, + 'Test-Bucket-Name', + 'Test-Access-Key', + 'Test-Secret-Key', + true + ); + + $this->assertTrue($result); + } + + public function testTestSFTPConnection() + { + $this->setAdapter( + 'Endpoints/Account/testConnection.json', + '/api/prov/v1/accounts/testSftpConnection', + [ + 'account_id' => 12345, + 'host' => '1.1.1.1', + 'user_name' => 'Test-Username', + 'password' => 'Test-Password', + 'destination_folder' => '/test/destination', + 'save_on_success' => true + ] + ); + + $result = $this->getEndpoint()->testSFTPConnection( + 12345, + '1.1.1.1', + 'Test-Username', + 'Test-Password', + '/test/destination', + true + ); + + $this->assertTrue($result); + } + + public function testSetAmazonSiemStorage() + { + $this->setAdapter( + 'Endpoints/Account/setSiemStorage.json', + '/api/prov/v1/accounts/setAmazonSiemStorage', + [ + 'account_id' => 12345, + 'bucket_name' => 'Test-Bucket-Name', + 'access_key' => 'Test-Access-Key', + 'secret_key' => 'Test-Secret-Key' + ] + ); + + $result = $this->getEndpoint()->setAmazomSiemStorage( + 12345, + 'Test-Bucket-Name', + 'Test-Access-Key', + 'Test-Secret-Key' + ); + + $this->assertTrue($result); + } + + public function testSetSFTPSiemStorage() + { + $this->setAdapter( + 'Endpoints/Account/setSiemStorage.json', + '/api/prov/v1/accounts/setSftpSiemStorage', + [ + 'account_id' => 12345, + 'host' => '1.1.1.1', + 'user_name' => 'Test-Username', + 'password' => 'Test-Password', + 'destination_folder' => '/test/destination' + ] + ); + + $result = $this->getEndpoint()->setSFTPSiemStorage( + 12345, + '1.1.1.1', + 'Test-Username', + 'Test-Password', + '/test/destination' + ); + + $this->assertTrue($result); + } + + public function testSetDefaultSiemStorage() + { + $this->setAdapter( + 'Endpoints/Account/setSiemStorage.json', + '/api/prov/v1/accounts/setDefaultSiemStorage', + [ + 'account_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->setDefaultSiemStorage(12345); + + $this->assertTrue($result); + } + + public function testGetDefaultStorageRegion() + { + $this->setAdapter( + 'Endpoints/Account/getDataStorageRegion.json', + '/api/prov/v1/accounts/data-privacy/show', + [ + 'account_id' => 12345 + ] + ); + + $region = $this->getEndpoint()->getDefaultStorageRegion(12345); + + $this->assertEquals('EU', $region); + } + + public function testSetDefaultStorageRegion() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/accounts/data-privacy/set-region-default', + [ + 'account_id' => 12345, + 'region' => 'EU' + ] + ); + + $result = $this->getEndpoint()->setDefaultStorageRegion(12345, 'EU'); + + $this->assertTrue($result); + } +} diff --git a/tests/Endpoints/Accounts/ConfigureTest.php b/tests/Endpoints/Accounts/ConfigureTest.php deleted file mode 100755 index 4671541..0000000 --- a/tests/Endpoints/Accounts/ConfigureTest.php +++ /dev/null @@ -1,36 +0,0 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Accounts\Configure($this->getAdapter(), 12345); - } - return $this->endpoint; - } - - public function testSet() - { - $this->setAdapter( - 'Endpoints/Account/setConfiguration.json', - '/api/prov/v1/accounts/configure', - [ - 'account_id' => 12345, - 'param' => 'email', - 'value' => 'admin@example.com' - ] - ); - - $result = $this->getEndpoint()->set('email', 'admin@example.com'); - - $this->assertTrue($result); - } -} diff --git a/tests/Endpoints/Accounts/DataPrivacyTest.php b/tests/Endpoints/Accounts/DataPrivacyTest.php deleted file mode 100755 index f913ceb..0000000 --- a/tests/Endpoints/Accounts/DataPrivacyTest.php +++ /dev/null @@ -1,49 +0,0 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Accounts\DataPrivacy($this->getAdapter(), 12345); - } - return $this->endpoint; - } - - public function testGetDefault() - { - $this->setAdapter( - 'Endpoints/Account/getDataStorageRegion.json', - '/api/prov/v1/accounts/data-privacy/show', - [ - 'account_id' => 12345 - ] - ); - - $region = $this->getEndpoint()->getDefault(); - - $this->assertEquals('EU', $region); - } - - public function testSetDefault() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/accounts/data-privacy/set-region-default', - [ - 'account_id' => 12345, - 'region' => 'EU' - ] - ); - - $result = $this->getEndpoint()->setDefault('EU'); - - $this->assertTrue($result); - } -} diff --git a/tests/Endpoints/DomainTest.php b/tests/Endpoints/DomainTest.php deleted file mode 100755 index 034a550..0000000 --- a/tests/Endpoints/DomainTest.php +++ /dev/null @@ -1,36 +0,0 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Domain($this->getAdapter()); - } - return $this->endpoint; - } - - public function testGetEmails() - { - $this->setAdapter( - 'Endpoints/Domain/getEmails.json', - '/api/prov/v1/domain/emails', - [ - 'site_id' => 12345, - ] - ); - $emails = $this->getEndpoint()->getEmails(12345); - - $this->assertIsArray($emails); - $this->assertCount(2, $emails); - - $this->assertEquals('admin@example.com', $emails[0]); - $this->assertEquals('webmaster@example.com', $emails[1]); - } -} diff --git a/tests/Endpoints/Site/CacheRulesTest.php b/tests/Endpoints/Site/CacheRulesTest.php new file mode 100755 index 0000000..3e3a713 --- /dev/null +++ b/tests/Endpoints/Site/CacheRulesTest.php @@ -0,0 +1,120 @@ +endpoint)) { + $this->endpoint = new \Incapsula\API\Endpoints\Site\CacheRules($this->getAdapter()); + } + return $this->endpoint; + } + + public function testAddCacheRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/caching-rules/add', + [ + 'site_id' => 12345, + 'name' => 'New Rule', + 'action' => 'HTTP_CACHE_MAKE_STATIC', + 'ttl' => 10, + 'ttl_unit' => 'MINUTES' + + ] + ); + + $result = $this->getEndpoint()->addCacheRule(12345, 'New Rule', 'HTTP_CACHE_MAKE_STATIC', [ + 'ttl' => 10, + 'ttl_unit' => 'MINUTES' + ]); + + $this->assertIsObject($result); + } + + public function testDeleteCacheRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/caching-rules/delete', + [ + 'site_id' => 12345, + 'rule_id' => 98765 + ] + ); + + $result = $this->getEndpoint()->deleteCacheRule(12345, 98765); + + $this->assertTrue($result); + } + + public function testSetCacheRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/caching-rules/edit', + [ + 'site_id' => 12345, + 'rule_id' => 98765, + 'ttl' => 10, + 'ttl_unit' => 'MINUTES' + ] + ); + + $result = $this->getEndpoint()->setCacheRule(12345, 98765, [ + 'ttl' => 10, + 'ttl_unit' => 'MINUTES' + ]); + + $this->assertIsObject($result); + } + + public function testEnableCacheRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/caching-rules/enable', + [ + 'site_id' => 12345, + 'rule_id' => 98765, + 'enable' => false + ] + ); + + $result = $this->getEndpoint()->enableCacheRule(12345, 98765, false); + + $this->assertIsObject($result); + } + + public function testListCacheRules() + { + $this->setAdapter( + 'Endpoints/Site/Performance/listCacheRules.json', + '/api/prov/v1/sites/performance/caching-rules/list', + [ + 'site_id' => 12345, + 'page_size' => 100, + 'page_num' => 2 + ] + ); + + $result = $this->getEndpoint()->listCacheRules(12345, [ + 'page_size' => 100, + 'page_num' => 2 + ]); + + $this->assertIsObject($result); + $this->assertObjectHasAttribute('HTTP_CACHE_DIFFERENTIATE_BY_GEO', $result); + $this->assertIsArray($result->HTTP_CACHE_DIFFERENTIATE_BY_GEO); + $this->assertEquals('3750', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->id); + $this->assertEquals('0', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->hits); + $this->assertEquals('HTTP_CACHE_DIFFERENTIATE_BY_GEO', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->action); + } +} diff --git a/tests/Endpoints/Sites/PerformanceTest.php b/tests/Endpoints/Site/CachingTest.php similarity index 56% rename from tests/Endpoints/Sites/PerformanceTest.php rename to tests/Endpoints/Site/CachingTest.php index f2b2b4c..a718ed9 100755 --- a/tests/Endpoints/Sites/PerformanceTest.php +++ b/tests/Endpoints/Site/CachingTest.php @@ -1,490 +1,367 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Sites\Performance($this->getAdapter(), 12345); - } - return $this->endpoint; - } - - public function testGetCacheMode() - { - $this->setAdapter( - 'Endpoints/Site/getCacheMode.json', - '/api/prov/v1/sites/performance/cache-mode/get', - [ - 'site_id' => 12345 - ] - ); - - $mode = $this->getEndpoint()->getCacheMode(); - - $this->assertIsString($mode); - $this->assertEquals('dynamic_and_aggressive', $mode); - } - - public function testSetCacheMode() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/cache-mode', - [ - 'site_id' => 12345, - 'cache_mode' => 'static_and_aggressive', - 'dynamic_cache_duration' => '5_min', - 'aggressive_cache_duration' => '1_hr' - ] - ); - - $result = $this->getEndpoint()->setCacheMode('static_and_aggressive', '5_min', '1_hr'); - - $this->assertTrue($result); - } - - public function testGetSecureResource() - { - $this->setAdapter( - 'Endpoints/Site/getSecureResourceMode.json', - '/api/prov/v1/sites/performance/secure-resources/get', - [ - 'site_id' => 12345 - ] - ); - - $mode = $this->getEndpoint()->getSecureResource(); - - $this->assertIsString($mode); - $this->assertEquals('do_not_cache', $mode); - } - - public function testSetSecureResource() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/secure-resources', - [ - 'site_id' => 12345, - 'secured_resources_mode' => 'do_not_cache' - ] - ); - - $result = $this->getEndpoint()->setSecureResource('do_not_cache'); - - $this->assertTrue($result); - } - - public function testGetStaleContent() - { - $this->setAdapter( - 'Endpoints/Site/getStaleContentSettings.json', - '/api/prov/v1/sites/performance/stale-content/get', - [ - 'site_id' => 12345 - ] - ); - - $mode = $this->getEndpoint()->getStaleContent(); - - $this->assertIsObject($mode); - } - - public function testSetStaleContent() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/stale-content', - [ - 'site_id' => 12345, - 'serve_stale_content' => true, - 'stale_content_mode' => 'ADAPTIVE', - 'time' => 5, - 'time_unit' => 'MINUTES' - ] - ); - - $result = $this->getEndpoint()->setStaleContent(true, 'ADAPTIVE', 5, 'MINUTES'); - - $this->assertTrue($result); - } - - public function testGetCache404() - { - $this->setAdapter( - 'Endpoints/Site/Performance/getCache404.json', - '/api/prov/v1/sites/performance/cache404', - [ - 'site_id' => 12345 - ] - ); - - $cache404 = $this->getEndpoint()->getCache404(); - - $this->assertIsObject($cache404); - $this->assertEquals(true, $cache404->enabled); - $this->assertEquals(10, $cache404->time); - } - - public function testSetCache404() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/cache404/modify', - [ - 'site_id' => 12345, - 'enabled' => true, - 'time' => 10, - 'time_unit' => 'HOURS' - ] - ); - - $result = $this->getEndpoint()->setCache404(true, 10, 'HOURS'); - - $this->assertIsObject($result); - } - - public function testPurgeResource() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/purge', - [ - 'site_id' => 12345, - 'resource_url' => '/test/url/page.css', - 'resource_pattern' => 'equals', - 'should_purge_all_site_resources' => true - ] - ); - - $result = $this->getEndpoint()->purgeResource('/test/url/page.css', 'equals', true); - - $this->assertTrue($result); - } - - public function testGetAdvancedCache() - { - $this->setAdapter( - 'Endpoints/Site/Performance/getAdvancedCache.json', - '/api/prov/v1/sites/performance/advanced/get', - [ - 'site_id' => 12345, - 'param' => 'send_age_header' - ] - ); - - $result = $this->getEndpoint()->getAdvancedCache('send_age_header'); - - $this->assertIsString($result); - $this->assertEquals(true, $result); - } - - public function testSetAdvancedCache() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/advanced', - [ - 'site_id' => 12345, - 'param' => 'send_age_header', - 'value' => false - ] - ); - - $result = $this->getEndpoint()->setAdvancedCache('send_age_header', false); - - $this->assertTrue($result); - } - - public function testGetCachedResponseHeaders() - { - $this->setAdapter( - 'Endpoints/Site/Performance/getCachedResponseHeaders.json', - '/api/prov/v1/sites/performance/response-headers/get', - [ - 'site_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->getCachedResponseHeaders(); - - $this->assertIsObject($result); - $this->assertObjectHasAttribute('custom_headers', $result); - $this->assertIsArray($result->custom_headers); - $this->assertEquals('header1', $result->custom_headers[0]); - $this->assertEquals('header2', $result->custom_headers[1]); - $this->assertEquals('header3', $result->custom_headers[2]); - } - - public function testSetCachedResponseHeaders() - { - $this->setAdapter('Endpoints/success.json'); - $this->getAdapter()->expects($this->exactly(2)) - ->method('request') - ->withConsecutive( - [ - $this->equalTo('/api/prov/v1/sites/performance/response-headers'), - $this->equalTo([ - 'site_id' => 12345, - 'cache_all_headers' => true - ]) - ], - [ - $this->equalTo('/api/prov/v1/sites/performance/response-headers'), - $this->equalTo([ - 'site_id' => 12345, - 'cache_headers' => 'test-cache-all' - ]) - ] - ); - - $result = $this->getEndpoint()->setCachedResponseHeaders('test-cache-all', true); - - $this->assertTrue($result); - - $result = $this->getEndpoint()->setCachedResponseHeaders('test-cache-all'); - - $this->assertTrue($result); - } - - public function testGetTagResponse() - { - $this->setAdapter( - 'Endpoints/Site/Performance/getTagResponse.json', - '/api/prov/v1/sites/performance/tag-response/get', - [ - 'site_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->getTagResponse(); - - $this->assertIsString($result); - $this->assertEquals('some_header', $result); - } - - public function testSetTagResponse() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/tag-response', - [ - 'site_id' => 12345, - 'header' => 'some_header' - ] - ); - - $result = $this->getEndpoint()->setTagResponse('some_header'); - - $this->assertTrue($result); - } - - public function testAddCacheRule() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/caching-rules/add', - [ - 'site_id' => 12345, - 'name' => 'New Rule', - 'action' => 'HTTP_CACHE_MAKE_STATIC', - 'ttl' => 10, - 'ttl_unit' => 'MINUTES' - - ] - ); - - $result = $this->getEndpoint()->addCacheRule('New Rule', 'HTTP_CACHE_MAKE_STATIC', [ - 'ttl' => 10, - 'ttl_unit' => 'MINUTES' - ]); - - $this->assertIsObject($result); - } - - public function testDeleteCacheRule() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/caching-rules/delete', - [ - 'site_id' => 12345, - 'rule_id' => 98765 - ] - ); - - $result = $this->getEndpoint()->deleteCacheRule(98765); - - $this->assertTrue($result); - } - - public function testSetCacheRule() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/caching-rules/edit', - [ - 'site_id' => 12345, - 'rule_id' => 98765, - 'ttl' => 10, - 'ttl_unit' => 'MINUTES' - ] - ); - - $result = $this->getEndpoint()->setCacheRule(98765, [ - 'ttl' => 10, - 'ttl_unit' => 'MINUTES' - ]); - - $this->assertIsObject($result); - } - - public function testEnableCacheRule() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/caching-rules/enable', - [ - 'site_id' => 12345, - 'rule_id' => 98765, - 'enable' => false - ] - ); - - $result = $this->getEndpoint()->enableCacheRule(98765, false); - - $this->assertIsObject($result); - } - - public function testListCacheRules() - { - $this->setAdapter( - 'Endpoints/Site/Performance/listCacheRules.json', - '/api/prov/v1/sites/performance/caching-rules/list', - [ - 'site_id' => 12345, - 'page_size' => 100, - 'page_num' => 2 - ] - ); - - $result = $this->getEndpoint()->listCacheRules([ - 'page_size' => 100, - 'page_num' => 2 - ]); - - $this->assertIsObject($result); - $this->assertObjectHasAttribute('HTTP_CACHE_DIFFERENTIATE_BY_GEO', $result); - $this->assertIsArray($result->HTTP_CACHE_DIFFERENTIATE_BY_GEO); - $this->assertEquals('3750', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->id); - $this->assertEquals('0', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->hits); - $this->assertEquals('HTTP_CACHE_DIFFERENTIATE_BY_GEO', $result->HTTP_CACHE_DIFFERENTIATE_BY_GEO[0]->action); - } - - public function testGetRewritePort() - { - $this->setAdapter( - 'Endpoints/Site/Performance/getRewritePort.json', - '/api/prov/v1/sites/performance/rewrite-port', - [ - 'site_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->getRewritePort(); - - $this->assertIsObject($result); - $this->assertObjectHasAttribute('port', $result); - $this->assertIsObject($result->port); - $this->assertEquals('80', $result->port->from); - $this->assertEquals('8080', $result->port->to); - } - - public function testSetRewritePort() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/rewrite-port/modify', - [ - 'site_id' => 12345, - 'rewrite_port_enabled' => true, - 'port' => 8080, - 'rewrite_ssl_port_enabled' => true, - 'ssl_port' => 444 - ] - ); - - $result = $this->getEndpoint()->setRewritePort(true, 8080, true, 444); - - $this->assertIsObject($result); - } - - public function testGetErrorPage() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/error-page', - [ - 'site_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->getErrorPage(); - - $this->assertIsObject($result); - } - - public function testSetErrorPage() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/error-page/modify', - [ - 'site_id' => 12345, - 'error_page_template' => '' - ] - ); - - $result = $this->getEndpoint()->setErrorPage(''); - - $this->assertIsObject($result); - } - - public function testEnableCacheShield() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/cache-shield/enable', - [ - 'site_id' => 12345, - 'enabled' => false - ] - ); - - $result = $this->getEndpoint()->enableCacheShield(false); - - $this->assertIsObject($result); - } - - public function testIsCacheShieldEnabled() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/performance/cache-shield', - [ - 'site_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->isCacheShieldEnabled(); - - $this->assertIsObject($result); - } -} +endpoint)) { + $this->endpoint = new \Incapsula\API\Endpoints\Site\Caching($this->getAdapter(), 12345); + } + return $this->endpoint; + } + + public function testPurgeCache() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/cache/purge', + [ + 'site_id' => 12345, + 'pattern' => 'testPattern', + 'tag_names' => 'test tag,tag2' + ] + ); + + $result = $this->getEndpoint()->purgeCache(12345, 'testPattern', 'test tag,tag2'); + + $this->assertTrue($result); + } + + public function testPurgeHostnameCache() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/hostname/purge', + [ + 'site_id' => 12345, + 'host_name' => 'www.example.com' + ] + ); + + $result = $this->getEndpoint()->purgeHostnameCache(12345, 'www.example.com'); + + $this->assertTrue($result); + } + + public function testGetCacheMode() + { + $this->setAdapter( + 'Endpoints/Site/getCacheMode.json', + '/api/prov/v1/sites/performance/cache-mode/get', + [ + 'site_id' => 12345 + ] + ); + + $mode = $this->getEndpoint()->getCacheMode(12345); + + $this->assertIsString($mode); + $this->assertEquals('dynamic_and_aggressive', $mode); + } + + public function testSetCacheMode() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/cache-mode', + [ + 'site_id' => 12345, + 'cache_mode' => 'static_and_aggressive', + 'dynamic_cache_duration' => '5_min', + 'aggressive_cache_duration' => '1_hr' + ] + ); + + $result = $this->getEndpoint()->setCacheMode(12345, 'static_and_aggressive', '5_min', '1_hr'); + + $this->assertTrue($result); + } + + public function testGetSecureResourceMode() + { + $this->setAdapter( + 'Endpoints/Site/getSecureResourceMode.json', + '/api/prov/v1/sites/performance/secure-resources/get', + [ + 'site_id' => 12345 + ] + ); + + $mode = $this->getEndpoint()->getSecureResourceMode(12345); + + $this->assertIsString($mode); + $this->assertEquals('do_not_cache', $mode); + } + + public function testSetSecureResourceMode() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/secure-resources', + [ + 'site_id' => 12345, + 'secured_resources_mode' => 'do_not_cache' + ] + ); + + $result = $this->getEndpoint()->setSecureResourceMode(12345, 'do_not_cache'); + + $this->assertTrue($result); + } + + public function testGetStaleContentSettings() + { + $this->setAdapter( + 'Endpoints/Site/getStaleContentSettings.json', + '/api/prov/v1/sites/performance/stale-content/get', + [ + 'site_id' => 12345 + ] + ); + + $mode = $this->getEndpoint()->getStaleContentSettings(12345); + + $this->assertIsObject($mode); + } + + public function testSetStaleContentSettings() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/stale-content', + [ + 'site_id' => 12345, + 'serve_stale_content' => true, + 'stale_content_mode' => 'ADAPTIVE', + 'time' => 5, + 'time_unit' => 'MINUTES' + ] + ); + + $result = $this->getEndpoint()->setStaleContentSettings(12345, true, 'ADAPTIVE', 5, 'MINUTES'); + + $this->assertTrue($result); + } + + public function testGetCache404Settings() + { + $this->setAdapter( + 'Endpoints/Site/Performance/getCache404.json', + '/api/prov/v1/sites/performance/cache404', + [ + 'site_id' => 12345 + ] + ); + + $cache404 = $this->getEndpoint()->getCache404Settings(12345); + + $this->assertIsObject($cache404); + $this->assertEquals(true, $cache404->enabled); + $this->assertEquals(10, $cache404->time); + } + + public function testSetCache404Settings() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/cache404/modify', + [ + 'site_id' => 12345, + 'enabled' => true, + 'time' => 10, + 'time_unit' => 'HOURS' + ] + ); + + $result = $this->getEndpoint()->setCache404Settings(12345, true, 10, 'HOURS'); + + $this->assertIsObject($result); + } + + public function testPurgeResources() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/purge', + [ + 'site_id' => 12345, + 'resource_url' => '/test/url/page.css', + 'resource_pattern' => 'equals', + 'should_purge_all_site_resources' => true + ] + ); + + $result = $this->getEndpoint()->purgeResources(12345, '/test/url/page.css', 'equals', true); + + $this->assertTrue($result); + } + + public function testGetAdvancedCacheSettings() + { + $this->setAdapter( + 'Endpoints/Site/Performance/getAdvancedCache.json', + '/api/prov/v1/sites/performance/advanced/get', + [ + 'site_id' => 12345, + 'param' => 'send_age_header' + ] + ); + + $result = $this->getEndpoint()->getAdvancedCacheSettings(12345, 'send_age_header'); + + $this->assertIsString($result); + $this->assertEquals(true, $result); + } + + public function testSetAdvancedCacheSettings() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/advanced', + [ + 'site_id' => 12345, + 'param' => 'send_age_header', + 'value' => false + ] + ); + + $result = $this->getEndpoint()->setAdvancedCacheSettings(12345, 'send_age_header', false); + + $this->assertTrue($result); + } + + public function testGetCachedResponseHeaders() + { + $this->setAdapter( + 'Endpoints/Site/Performance/getCachedResponseHeaders.json', + '/api/prov/v1/sites/performance/response-headers/get', + [ + 'site_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->getCachedResponseHeaders(12345); + + $this->assertIsObject($result); + $this->assertObjectHasAttribute('custom_headers', $result); + $this->assertIsArray($result->custom_headers); + $this->assertEquals('header1', $result->custom_headers[0]); + $this->assertEquals('header2', $result->custom_headers[1]); + $this->assertEquals('header3', $result->custom_headers[2]); + } + + public function testSetCachedResponseHeaders() + { + $this->setAdapter('Endpoints/success.json'); + $this->getAdapter()->expects($this->exactly(2)) + ->method('request') + ->withConsecutive( + [ + $this->equalTo('/api/prov/v1/sites/performance/response-headers'), + $this->equalTo([ + 'site_id' => 12345, + 'cache_all_headers' => true + ]) + ], + [ + $this->equalTo('/api/prov/v1/sites/performance/response-headers'), + $this->equalTo([ + 'site_id' => 12345, + 'cache_headers' => 'test-cache-all' + ]) + ] + ); + + $result = $this->getEndpoint()->setCachedResponseHeaders(12345, 'test-cache-all', true); + + $this->assertTrue($result); + + $result = $this->getEndpoint()->setCachedResponseHeaders(12345, 'test-cache-all'); + + $this->assertTrue($result); + } + + public function testGetTagResponseHeader() + { + $this->setAdapter( + 'Endpoints/Site/Performance/getTagResponse.json', + '/api/prov/v1/sites/performance/tag-response/get', + [ + 'site_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->getTagResponseHeader(12345); + + $this->assertIsString($result); + $this->assertEquals('some_header', $result); + } + + public function testSetTagResponseHeader() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/tag-response', + [ + 'site_id' => 12345, + 'header' => 'some_header' + ] + ); + + $result = $this->getEndpoint()->setTagResponseHeader(12345, 'some_header'); + + $this->assertTrue($result); + } + + public function testEnableCacheShield() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/cache-shield/enable', + [ + 'site_id' => 12345, + 'enabled' => false + ] + ); + + $result = $this->getEndpoint()->enableCacheShield(12345, false); + + $this->assertIsObject($result); + } + + public function testIsCacheShieldEnabled() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/cache-shield', + [ + 'site_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->isCacheShieldEnabled(12345); + + $this->assertIsObject($result); + } + + public function testGetXRayLink() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/xray/get-link', + [ + 'site_id' => 12345 + ] + ); + + $result = $this->getEndpoint()->getXRayLink(12345); + + $this->assertIsObject($result); + } +} diff --git a/tests/Endpoints/Sites/DataCenterTest.php b/tests/Endpoints/Site/DataCentersTest.php similarity index 92% rename from tests/Endpoints/Sites/DataCenterTest.php rename to tests/Endpoints/Site/DataCentersTest.php index d84eeae..6c79868 100755 --- a/tests/Endpoints/Sites/DataCenterTest.php +++ b/tests/Endpoints/Site/DataCentersTest.php @@ -1,198 +1,198 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Sites\DataCenter($this->getAdapter(), 12345); - } - return $this->endpoint; - } - - public function testAddDataCenter() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/add', - [ - 'site_id' => 12345, - 'name' => 'testName', - 'server_address' => '1.2.3.4', - 'is_enabled' => true, - 'is_standby' => false, - 'is_content' => true, - 'lb_algorithm' => 'test algorithm' - ] - ); - - $mode = $this->getEndpoint()->addDataCenter( - 12345, - 'testName', - '1.2.3.4', - true, - false, - true, - 'test algorithm' - ); - - $this->assertIsObject($mode); - } - - public function testEditDataCenter() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/edit', - [ - 'dc_id' => 54321, - 'name' => 'testName', - 'is_enabled' => true, - 'is_standby' => false, - 'is_content' => true, - ] - ); - - $mode = $this->getEndpoint()->editDataCenter( - 54321, - 'testName', - true, - false, - true - ); - - $this->assertIsObject($mode); - } - - public function testResumeDataCenterTraffic() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/resume', - [ - 'site_id' => 12345, - ] - ); - - $mode = $this->getEndpoint()->resumeDataCenterTraffic(12345); - - $this->assertIsObject($mode); - } - - public function testDeleteDataCenter() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/delete', - [ - 'dc_id' => 54321, - ] - ); - - $mode = $this->getEndpoint()->deleteDataCenter(54321); - - $this->assertIsObject($mode); - } - - public function testAddServer() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/servers/add', - [ - 'dc_id' => 54321, - 'server_address' => '1.2.3.4', - 'is_standby' => false - ] - ); - - $mode = $this->getEndpoint()->addServer(54321, '1.2.3.4', false); - - $this->assertIsObject($mode); - } - - public function testEditServer() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/servers/edit', - [ - 'server_id' => 98765, - 'server_address' => '4.3.2.1', - 'is_enabled' => true, - 'is_standby' => false - ] - ); - - $mode = $this->getEndpoint()->editServer(98765, '4.3.2.1', true, false); - - $this->assertIsObject($mode); - } - - public function testDeleteServer() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/servers/delete', - [ - 'server_id' => 54321 - ] - ); - - $mode = $this->getEndpoint()->deleteServer(54321); - - $this->assertIsObject($mode); - } - - public function testListDataCenters() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/dataCenters/list', - [ - 'site_id' => 12345 - ] - ); - - $mode = $this->getEndpoint()->listDataCenters(12345); - - $this->assertIsObject($mode); - } - - public function testGDataCenterOriginPOP() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/datacenter/origin-pop/modify', - [ - 'dc_id' => 54321, - 'origin_pop' => 'AP' - ] - ); - - $mode = $this->getEndpoint()->setDataCenterOriginPOP(54321, 'AP'); - - $this->assertIsObject($mode); - } - - public function testGetDataCenterRecommendedOriginPOP() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/datacenter/origin-pop/recommend', - [ - 'dc_id' => 54321 - ] - ); - - $mode = $this->getEndpoint()->getDataCenterRecommendedOriginPOP(54321); - - $this->assertIsObject($mode); - } -} +endpoint)) { + $this->endpoint = new \Incapsula\API\Endpoints\Site\DataCenters($this->getAdapter(), 12345); + } + return $this->endpoint; + } + + public function testAddDataCenter() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/add', + [ + 'site_id' => 12345, + 'name' => 'testName', + 'server_address' => '1.2.3.4', + 'is_enabled' => true, + 'is_standby' => false, + 'is_content' => true, + 'lb_algorithm' => 'test algorithm' + ] + ); + + $mode = $this->getEndpoint()->addDataCenter( + 12345, + 'testName', + '1.2.3.4', + true, + false, + true, + 'test algorithm' + ); + + $this->assertIsObject($mode); + } + + public function testEditDataCenter() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/edit', + [ + 'dc_id' => 54321, + 'name' => 'testName', + 'is_enabled' => true, + 'is_standby' => false, + 'is_content' => true, + ] + ); + + $mode = $this->getEndpoint()->editDataCenter( + 54321, + 'testName', + true, + false, + true + ); + + $this->assertIsObject($mode); + } + + public function testResumeDataCenterTraffic() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/resume', + [ + 'site_id' => 12345, + ] + ); + + $mode = $this->getEndpoint()->resumeDataCenterTraffic(12345); + + $this->assertIsObject($mode); + } + + public function testDeleteDataCenter() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/delete', + [ + 'dc_id' => 54321, + ] + ); + + $mode = $this->getEndpoint()->deleteDataCenter(54321); + + $this->assertIsObject($mode); + } + + public function testAddServer() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/servers/add', + [ + 'dc_id' => 54321, + 'server_address' => '1.2.3.4', + 'is_standby' => false + ] + ); + + $mode = $this->getEndpoint()->addServer(54321, '1.2.3.4', false); + + $this->assertIsObject($mode); + } + + public function testEditServer() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/servers/edit', + [ + 'server_id' => 98765, + 'server_address' => '4.3.2.1', + 'is_enabled' => true, + 'is_standby' => false + ] + ); + + $mode = $this->getEndpoint()->editServer(98765, '4.3.2.1', true, false); + + $this->assertIsObject($mode); + } + + public function testDeleteServer() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/servers/delete', + [ + 'server_id' => 54321 + ] + ); + + $mode = $this->getEndpoint()->deleteServer(54321); + + $this->assertIsObject($mode); + } + + public function testListDataCenters() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/dataCenters/list', + [ + 'site_id' => 12345 + ] + ); + + $mode = $this->getEndpoint()->listDataCenters(12345); + + $this->assertIsObject($mode); + } + + public function testGDataCenterOriginPOP() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/datacenter/origin-pop/modify', + [ + 'dc_id' => 54321, + 'origin_pop' => 'AP' + ] + ); + + $mode = $this->getEndpoint()->setDataCenterOriginPOP(54321, 'AP'); + + $this->assertIsObject($mode); + } + + public function testGetDataCenterRecommendedOriginPOP() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/datacenter/origin-pop/recommend', + [ + 'dc_id' => 54321 + ] + ); + + $mode = $this->getEndpoint()->getDataCenterRecommendedOriginPOP(54321); + + $this->assertIsObject($mode); + } +} diff --git a/tests/Endpoints/Site/RulesTest.php b/tests/Endpoints/Site/RulesTest.php new file mode 100755 index 0000000..2ec6fc1 --- /dev/null +++ b/tests/Endpoints/Site/RulesTest.php @@ -0,0 +1,147 @@ +endpoint)) { + $this->endpoint = new \Incapsula\API\Endpoints\Site\Rules($this->getAdapter(), 12345); + } + return $this->endpoint; + } + + public function testAddIncapRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/add', + [ + 'site_id' => 12345, + 'name' => 'test name', + 'action' => 'RULE_ACTION_REDIRECT', + 'filter' => 'test Filter', + 'response_code' => 312 + ] + ); + + $result = $this->getEndpoint()->addIncapRule(12345, 'test name', 'RULE_ACTION_REDIRECT', [ + 'filter' => 'test Filter', + 'response_code' => 312 + ]); + + $this->assertIsObject($result); + } + + public function testUpdateIncapRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/edit', + [ + 'rule_id' => 98765, + 'action' => 'RULE_ACTION_REDIRECT', + 'filter' => 'test Filter', + 'response_code' => 312 + ] + ); + + $result = $this->getEndpoint()->updateIncapRule(98765, 'RULE_ACTION_REDIRECT', [ + 'filter' => 'test Filter', + 'response_code' => 312 + ]); + + $this->assertIsObject($result); + } + + public function testEnableDisableIncapRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/enableDisable', + [ + 'rule_id' => 98765, + 'enabled' => false + ] + ); + + $result = $this->getEndpoint()->enableDisableIncapRule(98765, false); + + $this->assertIsObject($result); + } + + public function testDelteIncapRule() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/delete', + [ + 'rule_id' => 98765 + ] + ); + + $result = $this->getEndpoint()->deleteIncapRule(98765); + + $this->assertIsObject($result); + } + + public function testListIncapRules() + { + $this->setAdapter( + 'Endpoints/Site/listIncapRules.json', + '/api/prov/v1/sites/incapRules/list', + [ + 'site_id' => 12345, + 'include_ad_rules' => true, + 'include_incap_rules' => false, + 'page_size' => 100, + 'page_num' => 2 + ] + ); + + $result = $this->getEndpoint()->listIncapRules(12345, true, false, [ + 'page_size' => 100, + 'page_num' => 2 + ]); + + $this->assertIsObject($result); + } + + public function testListAccountIncapRules() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/account/list', + [ + 'account_id' => 12345, + 'include_ad_rules' => true, + 'include_incap_rules' => false + ] + ); + + $result = $this->getEndpoint()->listAccountIncapRules(12345, true, false); + + $this->assertIsObject($result); + } + + public function testSetIncapRulePriority() + { + $this->setAdapter( + 'Endpoints/success.json', + '/api/prov/v1/sites/incapRules/priority/set', + [ + 'rule_id' => 98765, + 'priority' => 10 + ] + ); + + $result = $this->getEndpoint()->setIncapRulePriority(98765, 10); + + $this->assertIsObject($result); + } +} diff --git a/tests/Endpoints/SitesTest.php b/tests/Endpoints/SiteTest.php similarity index 73% rename from tests/Endpoints/SitesTest.php rename to tests/Endpoints/SiteTest.php index 510ed2f..670c29d 100755 --- a/tests/Endpoints/SitesTest.php +++ b/tests/Endpoints/SiteTest.php @@ -2,17 +2,16 @@ namespace Incapsula\API\Tests\Endpoints; -use Incapsula\API\Tests\Interfaces\TestConfigure; use Incapsula\API\Tests\Interfaces\TestEndpoint; -class SitesTest extends \TestCase implements TestEndpoint +class SiteTest extends \TestCase implements TestEndpoint { private $endpoint; public function getEndpoint(): \Incapsula\API\Interfaces\Endpoint { if (!isset($this->endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Sites($this->getAdapter()); + $this->endpoint = new \Incapsula\API\Endpoints\Site($this->getAdapter()); } return $this->endpoint; } @@ -37,6 +36,24 @@ public function testGetStatus() $this->assertEquals('34.33.22.1', $status->ips[0]); } + public function testGetDomainApproverEmails() + { + $this->setAdapter( + 'Endpoints/Domain/getEmails.json', + '/api/prov/v1/domain/emails', + [ + 'site_id' => 12345, + ] + ); + $emails = $this->getEndpoint()->getDomainApproverEmails(12345); + + $this->assertIsArray($emails); + $this->assertCount(2, $emails); + + $this->assertEquals('admin@example.com', $emails[0]); + $this->assertEquals('webmaster@example.com', $emails[1]); + } + // // Managed Sites // @@ -104,11 +121,108 @@ public function testDeleteSite() $this->assertTrue($result); } + // // Site Configuration // + public function testSetConfig() + { + $this->setAdapter( + 'Endpoints/Site/setConfig.json', + '/api/prov/v1/sites/configure', + [ + 'site_id' => 12345, + 'param' => 'domain_email', + 'value' => 'admin@example.com' + ] + ); + + $result = $this->getEndpoint()->setConfig(12345, 'domain_email', 'admin@example.com'); + + $this->assertTrue($result); + } + + public function testSetSecurityConfig() + { + $this->setAdapter( + 'Endpoints/Site/getStatus.json', + '/api/prov/v1/sites/configure/security', + [ + 'site_id' => 12345, + 'rule_id' => 'api.threats.bot_access_control', + 'block_bad_bots' => true, + 'challenge_suspected_bots' => true + ] + ); + + $result = $this->getEndpoint()->setSecurityConfig( + 12345, + 'api.threats.bot_access_control', + [ + 'block_bad_bots' => true, + 'challenge_suspected_bots' => true + ] + ); + + $this->assertIsObject($result); + } + + public function testSetACLConfig() + { + $this->setAdapter( + 'Endpoints/Site/getStatus.json', + '/api/prov/v1/sites/configure/acl', + [ + 'site_id' => 12345, + 'rule_id' => 'api.acl.blacklisted_urls', + 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', + 'url_patterns' => 'contains,equals' + ] + ); + + $result = $this->getEndpoint()->setACLConfig( + 12345, + 'api.acl.blacklisted_urls', + [ + 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', + 'url_patterns' => 'contains,equals' + ] + ); + + $this->assertIsObject($result); + } + + public function testSetWhitelistConfig() + { + $this->setAdapter( + 'Endpoints/Site/getStatus.json', + '/api/prov/v1/sites/configure/whitelists', + [ + 'site_id' => 12345, + 'rule_id' => 'api.threats.sql_injection', + 'whitelist_id' => 12345, + 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', + 'ips' => '1.2.3.4,192.168.1.1-192.168.1.100,192.168.1.1/24', + 'countries' => 'GT,VN' + ] + ); + + $result = $this->getEndpoint()->setWhitelistConfig( + 12345, + 'api.threats.sql_injection', + 12345, + [ + 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', + 'ips' => '1.2.3.4,192.168.1.1-192.168.1.100,192.168.1.1/24', + 'countries' => 'GT,VN' + ] + ); + + $this->assertIsObject($result); + } + public function testSetLogLevel() { $this->setAdapter( @@ -181,23 +295,6 @@ public function testGetReport() ); } - public function testPurgeCache() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/cache/purge', - [ - 'site_id' => 12345, - 'pattern' => 'testPattern', - 'tag_names' => 'test tag,tag2' - ] - ); - - $result = $this->getEndpoint()->purgeCache(12345, 'testPattern', 'test tag,tag2'); - - $this->assertTrue($result); - } - public function testGetGeeTest() { $this->setAdapter( @@ -229,22 +326,6 @@ public function testSetGeeTest() $this->assertIsObject($result); } - public function testPurgeHostnameCache() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/hostname/purge', - [ - 'site_id' => 12345, - 'host_name' => 'www.example.com' - ] - ); - - $result = $this->getEndpoint()->purgeHostnameCache(12345, 'www.example.com'); - - $this->assertTrue($result); - } - public function testUploadCustomCertificate() { $this->setAdapter( @@ -317,245 +398,170 @@ public function testCreateCSR() ); } - public function testAddIncapRule() + public function testSetDataStorageRegion() { $this->setAdapter( 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/add', + '/api/prov/v1/sites/data-privacy/region-change', [ 'site_id' => 12345, - 'name' => 'test name', - 'action' => 'RULE_ACTION_REDIRECT', - 'filter' => 'test Filter', - 'response_code' => 312 + 'data_storage_region' => 'AP' ] ); - $result = $this->getEndpoint()->addIncapRule(12345, 'test name', 'RULE_ACTION_REDIRECT', [ - 'filter' => 'test Filter', - 'response_code' => 312 - ]); + $result = $this->getEndpoint()->setDataStorageRegion(12345, 'AP'); - $this->assertIsObject($result); + $this->assertTrue($result); } - public function testUpdateIncapRule() + public function testGetDataStorageRegion() { $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/edit', + 'Endpoints/Account/getDataStorageRegion.json', + '/api/prov/v1/sites/data-privacy/show', [ - 'rule_id' => 98765, - 'action' => 'RULE_ACTION_REDIRECT', - 'filter' => 'test Filter', - 'response_code' => 312 + 'site_id' => 12345 ] ); - $result = $this->getEndpoint()->updateIncapRule(98765, 'RULE_ACTION_REDIRECT', [ - 'filter' => 'test Filter', - 'response_code' => 312 - ]); + $result = $this->getEndpoint()->getDataStorageRegion(12345); - $this->assertIsObject($result); + $this->assertIsString($result); + $this->assertEquals('EU', $result); } - public function testEnableDisableIncapRule() + public function testSetDataStorageRegionByGeo() { $this->setAdapter( 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/enableDisable', + '/api/prov/v1/sites/data-privacy/override-by-geo', [ - 'rule_id' => 98765, - 'enabled' => false + 'account_id' => 12345, + 'override_site_regions_by_geo' => true ] ); - $result = $this->getEndpoint()->enableDisableIncapRule(98765, false); + $result = $this->getEndpoint()->setDataStorageRegionByGeo(12345, true); - $this->assertIsObject($result); + $this->assertTrue($result); } - public function testDelteIncapRule() + public function testIsDataStorageRegionByGeoEnabled() { $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/delete', + 'Endpoints/Site/isDataStorageRegionByGeoEnabled.json', + '/api/prov/v1/sites/data-privacy/show-override-by-geo', [ - 'rule_id' => 98765 + 'account_id' => 12345, ] ); - $result = $this->getEndpoint()->deleteIncapRule(98765); + $result = $this->getEndpoint()->isDataStorageRegionByGeoEnabled(12345); - $this->assertIsObject($result); + $this->assertTrue($result); } - public function testListIncapRules() + public function testCheckCompliance() { $this->setAdapter( - 'Endpoints/Site/listIncapRules.json', - '/api/prov/v1/sites/incapRules/list', + 'Endpoints/Site/checkCompliance.json', + '/api/prov/v1/caa/check-compliance', [ 'site_id' => 12345, - 'include_ad_rules' => true, - 'include_incap_rules' => false, - 'page_size' => 100, - 'page_num' => 2 - ] - ); - - $result = $this->getEndpoint()->listIncapRules(12345, true, false, [ - 'page_size' => 100, - 'page_num' => 2 - ]); - - $this->assertIsObject($result); - } - - public function testListAccountIncapRules() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/account/list', - [ - 'account_id' => 12345, - 'include_ad_rules' => true, - 'include_incap_rules' => false ] ); - $result = $this->getEndpoint()->listAccountIncapRules(12345, true, false); + $result = $this->getEndpoint()->checkCompliance(12345); - $this->assertIsObject($result); + $this->assertIsArray($result); + $this->assertCount(1, $result); + $this->assertEquals('*.caa.incaptest.co', $result[0]); } - public function testSetIncapRulePriority() + public function testMoveSite() { $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/incapRules/priority/set', + 'Endpoints/Site/moveSite.json', + '/api/prov/v1/sites/moveSite', [ - 'rule_id' => 98765, - 'priority' => 10 + 'site_id' => 12345, + 'destination_account_id' => 54321 ] ); - $result = $this->getEndpoint()->setIncapRulePriority(98765, 10); + $result = $this->getEndpoint()->moveSite(12345, 54321); $this->assertIsObject($result); + $this->assertObjectHasAttribute('status', $result); + $this->assertEquals('', $result->status); } - public function testGetXRayLink() + public function testGetRewritePort() { $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/sites/xray/get-link', + 'Endpoints/Site/Performance/getRewritePort.json', + '/api/prov/v1/sites/performance/rewrite-port', [ 'site_id' => 12345 ] ); - $result = $this->getEndpoint()->getXRayLink(12345); + $result = $this->getEndpoint()->getRewritePort(12345); $this->assertIsObject($result); + $this->assertObjectHasAttribute('port', $result); + $this->assertIsObject($result->port); + $this->assertEquals('80', $result->port->from); + $this->assertEquals('8080', $result->port->to); } - public function testSetDataStorageRegion() + public function testSetRewritePort() { $this->setAdapter( 'Endpoints/success.json', - '/api/prov/v1/sites/data-privacy/region-change', + '/api/prov/v1/sites/performance/rewrite-port/modify', [ 'site_id' => 12345, - 'data_storage_region' => 'AP' + 'rewrite_port_enabled' => true, + 'port' => 8080, + 'rewrite_ssl_port_enabled' => true, + 'ssl_port' => 444 ] ); - $result = $this->getEndpoint()->setDataStorageRegion(12345, 'AP'); + $result = $this->getEndpoint()->setRewritePort(12345, true, 8080, true, 444); - $this->assertTrue($result); + $this->assertIsObject($result); } - public function testGetDataStorageRegion() + public function testGetErrorPage() { $this->setAdapter( - 'Endpoints/Account/getDataStorageRegion.json', - '/api/prov/v1/sites/data-privacy/show', + 'Endpoints/success.json', + '/api/prov/v1/sites/performance/error-page', [ 'site_id' => 12345 ] ); - $result = $this->getEndpoint()->getDataStorageRegion(12345); + $result = $this->getEndpoint()->getErrorPage(12345); - $this->assertIsString($result); - $this->assertEquals('EU', $result); + $this->assertIsObject($result); } - public function testSetDataStorageRegionByGeo() + public function testSetErrorPage() { $this->setAdapter( 'Endpoints/success.json', - '/api/prov/v1/sites/data-privacy/override-by-geo', - [ - 'account_id' => 12345, - 'override_site_regions_by_geo' => true - ] - ); - - $result = $this->getEndpoint()->setDataStorageRegionByGeo(12345, true); - - $this->assertTrue($result); - } - - public function testIsDataStorageRegionByGeoEnabled() - { - $this->setAdapter( - 'Endpoints/Site/isDataStorageRegionByGeoEnabled.json', - '/api/prov/v1/sites/data-privacy/show-override-by-geo', - [ - 'account_id' => 12345, - ] - ); - - $result = $this->getEndpoint()->isDataStorageRegionByGeoEnabled(12345); - - $this->assertTrue($result); - } - - public function testCheckCompliance() - { - $this->setAdapter( - 'Endpoints/Site/checkCompliance.json', - '/api/prov/v1/caa/check-compliance', - [ - 'site_id' => 12345, - ] - ); - - $result = $this->getEndpoint()->checkCompliance(12345); - - $this->assertIsArray($result); - $this->assertCount(1, $result); - $this->assertEquals('*.caa.incaptest.co', $result[0]); - } - - public function testMoveSite() - { - $this->setAdapter( - 'Endpoints/Site/moveSite.json', - '/api/prov/v1/sites/moveSite', + '/api/prov/v1/sites/performance/error-page/modify', [ 'site_id' => 12345, - 'destination_account_id' => 54321 + 'error_page_template' => '' ] ); - $result = $this->getEndpoint()->moveSite(12345, 54321); + $result = $this->getEndpoint()->setErrorPage(12345, ''); $this->assertIsObject($result); - $this->assertObjectHasAttribute('status', $result); - $this->assertEquals('', $result->status); } } diff --git a/tests/Endpoints/Sites/ConfigureTest.php b/tests/Endpoints/Sites/ConfigureTest.php deleted file mode 100755 index 1ed8732..0000000 --- a/tests/Endpoints/Sites/ConfigureTest.php +++ /dev/null @@ -1,111 +0,0 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\Sites\Configure($this->getAdapter(), 12345); - } - return $this->endpoint; - } - - public function testSet() - { - $this->setAdapter( - 'Endpoints/Site/setConfig.json', - '/api/prov/v1/sites/configure', - [ - 'site_id' => 12345, - 'param' => 'domain_email', - 'value' => 'admin@example.com' - ] - ); - - $result = $this->getEndpoint()->set('domain_email', 'admin@example.com'); - - $this->assertTrue($result); - } - - public function testSetSecurity() - { - $this->setAdapter( - 'Endpoints/Site/getStatus.json', - '/api/prov/v1/sites/configure/security', - [ - 'site_id' => 12345, - 'rule_id' => 'api.threats.bot_access_control', - 'block_bad_bots' => true, - 'challenge_suspected_bots' => true - ] - ); - - $result = $this->getEndpoint()->setSecurity( - 'api.threats.bot_access_control', - [ - 'block_bad_bots' => true, - 'challenge_suspected_bots' => true - ] - ); - - $this->assertIsObject($result); - } - - public function testSetACL() - { - $this->setAdapter( - 'Endpoints/Site/getStatus.json', - '/api/prov/v1/sites/configure/acl', - [ - 'site_id' => 12345, - 'rule_id' => 'api.acl.blacklisted_urls', - 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', - 'url_patterns' => 'contains,equals' - ] - ); - - $result = $this->getEndpoint()->setACL( - 'api.acl.blacklisted_urls', - [ - 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', - 'url_patterns' => 'contains,equals' - ] - ); - - $this->assertIsObject($result); - } - - public function testSetWhitelist() - { - $this->setAdapter( - 'Endpoints/Site/getStatus.json', - '/api/prov/v1/sites/configure/whitelists', - [ - 'site_id' => 12345, - 'rule_id' => 'api.threats.sql_injection', - 'whitelist_id' => 12345, - 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', - 'ips' => '1.2.3.4,192.168.1.1-192.168.1.100,192.168.1.1/24', - 'countries' => 'GT,VN' - ] - ); - - $result = $this->getEndpoint()->setWhitelist( - 'api.threats.sql_injection', - 12345, - [ - 'urls' => '%2Fadmin%2Fdashboard%2Fstats%3Fx%3D1%26y%3D2%23z%3D3,%2Fadmin', - 'ips' => '1.2.3.4,192.168.1.1-192.168.1.100,192.168.1.1/24', - 'countries' => 'GT,VN' - ] - ); - - $this->assertIsObject($result); - } -} diff --git a/tests/Endpoints/SubAccountsTest.php b/tests/Endpoints/SubAccountsTest.php deleted file mode 100755 index 2c88a47..0000000 --- a/tests/Endpoints/SubAccountsTest.php +++ /dev/null @@ -1,81 +0,0 @@ -endpoint)) { - $this->endpoint = new \Incapsula\API\Endpoints\SubAccounts($this->getAdapter()); - } - return $this->endpoint; - } - - public function testGetList() - { - $this->setAdapter( - 'Endpoints/Account/getSubAccounts.json', - '/api/prov/v1/accounts/listSubAccounts', - [ - 'account_id' => 12345, - 'page_size' => 100, - 'page_num' => 2 - ] - ); - $subAccounts = $this->getEndpoint()->getList(12345, [ - 'page_size' => 100, - 'page_num' => 2 - ]); - - $this->assertIsArray($subAccounts); - $this->assertCount(2, $subAccounts); - - $this->assertObjectHasAttribute('sub_account_id', $subAccounts[0]); - $this->assertEquals(123456, $subAccounts[0]->sub_account_id); - $this->assertObjectHasAttribute('sub_account_name', $subAccounts[1]); - $this->assertEquals('My super lovely sub account', $subAccounts[1]->sub_account_name); - } - - public function testAdd() - { - $this->setAdapter( - 'Endpoints/Account/addSubAccount.json', - '/api/prov/v1/subaccounts/add', - [ - 'sub_account_name' => 'Sub Account Name', - 'user_name' => 'John Doe' - ] - ); - - $subAccount = $this->getEndpoint()->add('Sub Account Name', [ - 'user_name' => 'John Doe' - ]); - - $this->assertIsObject($subAccount); - - $this->assertObjectHasAttribute('sub_account_id', $subAccount); - $this->assertEquals(123456, $subAccount->sub_account_id); - $this->assertObjectHasAttribute('support_level', $subAccount); - $this->assertEquals('Standard', $subAccount->support_level); - } - - public function testDelete() - { - $this->setAdapter( - 'Endpoints/success.json', - '/api/prov/v1/subaccounts/delete', - [ - 'sub_account_id' => 12345 - ] - ); - - $result = $this->getEndpoint()->delete(12345); - - $this->assertTrue($result); - } -}