175 Commits
1.0.2 ... 1.1.4

Author SHA1 Message Date
Junade
9b9738910d Update README.md 2019-06-07 16:34:38 +01:00
Junade
90a9f51fd6 Update README.md 2019-06-07 16:34:28 +01:00
Junade
b17ae6e7d0 Merge pull request #90 from squeezely/loadbalancers
LoadBalancers + LoadBalancers Pool endpoint integration
2019-06-07 16:27:15 +01:00
Junade
b558622bb5 Merge pull request #92 from exportsmedia/feature-crypto-endpoints
Add Crypto endpoints to crypto.php, update TLS.php
2019-06-07 16:26:32 +01:00
Junade
d913aa827f Merge pull request #94 from exportsmedia/feature-update-security-level
Add Firewall Settings Endpoints, Tests
2019-06-07 16:25:47 +01:00
Junade
6a9a9f55b6 Merge pull request #93 from exportsmedia/feature-get-dns-record-id
Add get DNS record ID
2019-06-07 16:23:10 +01:00
Martijn Smidt
1724b66147 Added check_regions for pool configuration 2019-06-03 11:23:27 +02:00
Michael
7343b7cc46 change param type 2019-05-25 23:02:40 -05:00
Michael
bd10d7f833 fix security endpoint 2019-05-25 22:58:10 -05:00
Michael
598ba5c1d1 add firewall settings endpoints, tests 2019-05-25 22:53:56 -05:00
Michael
ed06650390 move array over 2019-05-25 22:14:00 -05:00
Michael
246925dec2 add get dns record id method, test 2019-05-25 22:10:36 -05:00
Michael Markoski
7a7e6dc364 move array over 2019-05-25 15:39:30 -05:00
Michael Markoski
5f57b871aa remove new lines 2019-05-25 15:37:34 -05:00
Michael Markoski
31453d8184 remove new line 2019-05-25 15:36:29 -05:00
Michael Markoski
21b3f20fb1 add new line after class 2019-05-25 15:32:18 -05:00
Michael Markoski
45834c0709 add new line after class 2019-05-25 15:32:04 -05:00
Michael Markoski
c44a26fa35 remove whitespace at class end 2019-05-25 15:29:12 -05:00
Michael Markoski
1764856f5b remove whitespace after doc return 2019-05-25 15:25:53 -05:00
Michael Markoski
79ca15c066 split methods to another class to pass CI test 2019-05-25 14:59:29 -05:00
Michael Markoski
63ded280d3 Merge branch 'feature-crypto-endpoints' of https://github.com/exportsmedia/cloudflare-php into feature-crypto-endpoints
# Conflicts:
#	src/Endpoints/Crypto.php
#	src/Endpoints/TLS.php
#	tests/Endpoints/CryptoTest.php
2019-05-25 10:31:07 -05:00
Michael Markoski
fb9d75d94a Add Crypto endpoints to crypto.php, update TLS.php
add php docs for methods

add test class

work on crypto tests

add tls tests

finish crypto tests

update doc returns

add type to parameter
2019-05-22 14:24:37 -05:00
Michael Markoski
1cf5963445 work on crypto tests 2019-05-22 10:28:13 -05:00
Michael Markoski
ecb23ccc44 add test class 2019-05-21 17:14:17 -05:00
Michael Markoski
b81c67ddc5 add php docs for methods 2019-05-21 16:20:56 -05:00
Michael Markoski
b46a2f80f5 add new methods 2019-05-21 16:02:08 -05:00
Junade
fab0bc7a12 Merge pull request #91 from easelify/dev
Fix updatePageRule() method
2019-05-18 13:25:16 +01:00
easelify
6a29d75001 Fix updatePageRule() method 2019-05-17 20:18:22 +08:00
Martijn Smidt
99c174bcb3 Added pools class and tests
Small changes in loadbalancer configuration
2019-05-14 11:50:52 +02:00
Martijn Smidt
3cfeedbe4d Added loadbalancers class and tests 2019-05-13 17:05:41 +02:00
Junade
7aa3a118af Merge pull request #78 from linuxjuggler/master
Implementing the User's Account Memberships
2019-05-08 19:56:24 +01:00
Junade
ae2c680e85 Merge pull request #83 from nexxai/patch-1
Feature: Allow creation of ASN access rule
2019-05-08 19:55:33 +01:00
Junade
78eadb9a47 Merge pull request #80 from smalot/smalot-feature-cache-level
Feature: Add cache level methods
2019-05-08 19:55:18 +01:00
Junade
e1c2539d9a Merge pull request #84 from pauladams8/master
Added new TLS & Zone settings Endpoints
2019-05-08 19:52:54 +01:00
Junade
471a42d554 Merge pull request #79 from GetNoticedNL/feature/add-get-zone-by-id-method
Feature: add getZoneById method
2019-05-03 16:46:27 +08:00
Paul Adams
d9c0a27b7d Update ZoneSettings.php
Fixed variable length
2019-03-23 07:46:41 +00:00
Paul Adams
8182aa8810 PSR-2 2019-02-26 20:35:51 +00:00
Paul Adams
df12f7ba6f Updated to PSR-2 2019-02-26 20:20:13 +00:00
Paul Adams
9d434a23b3 Updated to PSR-2 2019-02-26 20:06:07 +00:00
Paul Adams
f105d38d85 updated TLS.php 2019-02-23 00:18:05 +00:00
Paul Adams
910644f88d Removed file created by mistake 2019-02-23 00:13:29 +00:00
Paul Adams
68b9fa3353 Removed additional directory created by mistake 2019-02-23 00:10:26 +00:00
Paul Adams
c394f5ac4d Removed additional directory created by mistake 2019-02-23 00:05:37 +00:00
Paul Adams
e94ab8ddbe Updated TLS.php and added new endpoints to new ZoneSettings.php 2019-02-23 00:02:01 +00:00
Paul Adams
2b25365988 Updated TLS.php and added new endpoints to new ZoneSettings.php 2019-02-22 23:54:14 +00:00
Justin Smith
bd92b2a4c0 Allow creation of ASN access rule
Added setASN() method to allow creation of ASN access rules
2019-02-11 14:44:05 -07:00
Sebastien MALOT
6acf09ba82 Feature: Add cache level methods
Add `getCachingLevel` and `setCachingLevel` methods
2019-01-27 14:53:16 +01:00
Wesley Vestjens
6410f50f6d Add tests for getZoneById() method 2019-01-16 22:09:49 +01:00
Wesley Vestjens
d6f0eada8c Add getZoneById($zoneId) method 2019-01-16 21:43:58 +01:00
Zaher Ghaibeh
6f1ac605f5 adding User's Account Memberships 2019-01-13 12:31:18 +03:00
Zaher Ghaibeh
9311583f43 adding the .idea file 2019-01-13 10:21:37 +03:00
Junade
4694904b38 Merge pull request #69 from levidurfee/body-accessor
Added a `body` property to the endpoint classes with an accessor
2019-01-02 09:07:56 -05:00
Junade
7e3e367f16 Merge pull request #73 from samnela/remove-deprecated-testcase
Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
2019-01-02 09:07:13 -05:00
Junade
97af6a2ca6 Merge pull request #76 from NSpehler/patch-1
Fix typo in README.md
2019-01-02 09:06:49 -05:00
Nicolas Spehler
3da4f053f0 Fix typo in README.md 2018-12-29 19:07:35 +01:00
Junade
1e369bd9cd Merge pull request #74 from pxgamer/bugfix/set-ssl-config
Fix SSL configuration method
2018-12-18 17:34:05 +00:00
pxgamer
5841936f04 Fix SSL configuration method
Closes #72
2018-11-26 11:23:02 +00:00
Samuel NELA
a8017f864b Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase 2018-11-24 15:36:06 +01:00
Junade
ba2c37fe1e Merge pull request #68 from kruisdraad/master
Update DNS.php
2018-10-21 15:42:37 +01:00
Junade
db0f0eed79 Merge pull request #70 from jcoetsie/master
Add EndPoint to manage TLS Settings
2018-10-21 15:41:11 +01:00
Marlin-Ops.com - Jurgen Coetsiers
4e17cc8984 Add changing TLS Zone Settings capability 2018-10-21 16:02:42 +02:00
Jurgen Coetsiers
c1193f7f91 downgrade to php 7.0 2018-10-21 09:38:45 +00:00
Marlin-Ops.com - Jurgen Coetsiers
67a24c5784 Add changing TLS Zone Settings capability 2018-10-21 11:27:07 +02:00
Marlin-Ops.com - Jurgen Coetsiers
8bb2e8a110 Add changing TLS Zone Settings capability 2018-10-21 11:23:41 +02:00
Marlin-Ops.com - Jurgen Coetsiers
9d1750594e Add changing TLS Zone Settings capability 2018-10-21 11:22:10 +02:00
Marlin-Ops.com - Jurgen Coetsiers
ed6b1ec5a2 Add changing TLS Zone Settings capability 2018-10-21 11:19:27 +02:00
Marlin-Ops.com - Jurgen Coetsiers
90e01ff095 Add changing TLS Zone Settings capability 2018-10-21 11:16:57 +02:00
Marlin-Ops.com - Jurgen Coetsiers
8c68295daa Add changing TLS Zone Settings capability 2018-10-21 11:00:32 +02:00
Levi Durfee
57318b2a56 Fix lint error 2018-10-19 11:28:10 -04:00
Levi Durfee
099f383ef3 Add trait to the rest of the endpoints 2018-10-19 11:06:34 -04:00
Levi Durfee
2639331c2b Add BodyAccessorTrait to most classes 2018-10-19 10:48:25 -04:00
Levi Durfee
d871bdd007 Add BodyAccessorTrait to AccessRules 2018-10-19 10:21:38 -04:00
Levi Durfee
c60064e542 Add more assertions for BodyAccessorTrait 2018-10-19 10:18:57 -04:00
Levi Durfee
0492e9b17b Fix id 2018-10-19 10:16:17 -04:00
Levi Durfee
5bea924c76 Set body property in other Zones methods 2018-10-19 10:12:51 -04:00
Levi Durfee
943b0d85d4 Add test using getBody trait method 2018-10-19 10:10:00 -04:00
Levi Durfee
e28fed86d1 Update ID in cachePurge fixture 2018-10-19 10:02:33 -04:00
Levi Durfee
45df26fec3 Add a test for cachePurge 2018-10-19 09:54:38 -04:00
Levi Durfee
a39d6fb170 Run php-cs-fixer 2018-10-19 09:53:51 -04:00
Levi Durfee
4c288c38d7 Add cachePurge fixture 2018-10-19 09:49:01 -04:00
Levi Durfee
2dd4d8f883 Set body property in cachePurge method of Zones 2018-10-19 09:45:10 -04:00
Levi Durfee
59f6d72d0a Create trait for accessing body property 2018-10-19 09:34:17 -04:00
Bart Vrancken
f19f17ea6f Update DNS.php 2018-10-06 23:47:25 +02:00
Junade
a3a346ccb2 Merge pull request #62 from powerkent/fix-refresh-cache
fix: Cloudflare Api doesn't like empty tags
2018-08-28 15:01:57 +01:00
Junade
deb420d087 Update Zones.php 2018-08-28 14:58:25 +01:00
Junade
640b787540 Merge branch 'master' into fix-refresh-cache 2018-08-28 14:53:47 +01:00
Junade
8df0ec5511 Merge pull request #63 from maximivanov/feature/purgeCacheHosts
Add support for host-based cache purge
2018-08-28 14:49:49 +01:00
Junade
938065cdf3 Merge pull request #64 from mjrider/patch-1
Fixes issue with creating a MX record
2018-08-28 14:49:11 +01:00
Robbert Müller
9076d714f4 Fixes problem with creating an MX record
Fixes #60
php api expects a string and cloudflare api expects a int
this keeps everybody happy without changing API's
2018-08-28 08:47:50 +02:00
Max Ivanov
c9d2782b88 Add support for host-based cache purge 2018-08-23 16:13:56 +01:00
Lemoine
1cca3e0724 fix: Cloudflare Api doesn't like empty tags 2018-08-23 14:54:21 +02:00
Junade
63be6cf154 Merge pull request #54 from darinrandal/refactor-clean
Cleanup, refactoring, and removal of duplicate code
2018-05-19 21:23:57 +01:00
Darin Randal
c06fe79ad0 Removed more object casting 2018-04-12 23:19:09 -04:00
Darin Randal
cca073c809 Code cleanup / Quality of Life updates
Adapter::get, post, put, patch and delete all had non-optional parameters for $headers and $query or $body. These have been made optional. I also re-ordered the parameters as $headers was never used while $query/$body were heavily used. I also condensed and removed some duplicate calls so that every call to Adapter::get/post sends that call to Adapter::request. It could use a magic method to do this but it might make it more difficult to test.
2018-04-12 23:11:04 -04:00
Junade
35ce8eadf1 Merge pull request #51 from cloudflare/SOPS-161
SOPS-161 :: Add Custom Hostname endpoints to cloudflare-php
2018-03-18 23:47:42 -07:00
Junade Ali
d95573976e SOPS-161 :: Lint changes 2018-03-18 23:45:06 -07:00
Junade Ali
3bfd5e17f1 SOPS-161 :: Add Custom Hostname endpoints to cloudflare-php 2018-03-18 23:40:09 -07:00
Junade
19a4f481d3 Merge pull request #48 from anthonysterling/fix/issue-46
Nest payload for forwarding_url page rule action in value block
2018-03-05 14:21:59 -06:00
Junade
9c56941516 Merge pull request #49 from darinrandal/add-priority-for-dns-creation
MX records need ability to set priority
2018-03-05 14:20:38 -06:00
Darin Randal
e18a64e7e4 MX records need ability to set priority 2018-03-05 11:38:18 -05:00
Anthony Sterling
3585dde8ea Fixed merge conflict 2018-02-27 09:45:51 +00:00
Anthony Sterling
730b0c97ee Nest payload for forwarding_url page rule action in value block 2018-02-27 09:40:50 +00:00
Junade
dc53414c2a Merge pull request #45 from darinrandal/master
Fix name of jumpstart zone add option to jump_start
2018-01-30 14:30:46 +13:00
Darin Randal
a628cac283 Update phpdoc to match camelCase variable 2018-01-23 10:09:36 -05:00
Darin Randal
0112425a61 Rename $jump_start to $jumpStart to follow camelCase conventions for variables 2018-01-23 10:08:40 -05:00
Darin Randal
fe854e1b21 Update zone tests to reflect correctly named jumpstart option 2018-01-23 10:01:51 -05:00
Darin Randal
45cb8ee539 Fix name of jumpstart zone add option to jump_start 2018-01-23 09:57:14 -05:00
Junade
cd2fd73cc3 Merge pull request #42 from JorgenPhi/master
AnalyticsDashboard params are not headers
2017-12-26 18:52:26 +00:00
Jorgen Phillips
bd83c6d48a Fix test 2017-12-24 12:48:22 -06:00
Jorgen Phillips
4e3d307bdd AnalyticsDashboard params are not headers
Also 'continuous' needs to be a string for the API to process it.
2017-12-24 12:41:38 -06:00
Junade
99d89e7dc3 Merge pull request #39 from MeekLogic/master
Fixed checkError index out of range
2017-11-27 16:50:05 +08:00
Tyler Vigario
55e81fe02c Fixed checkError index out of range 2017-11-26 19:23:31 -08:00
Junade
d00a1d3f44 Merge pull request #38 from kleisauke/cleanup
Cleanup / fixes
2017-11-25 11:49:35 +08:00
Kleis Auke Wolthuizen
c8e85d2582 Add firewall access rules endpoint (#37)
* Add firewall access rules endpoint

* Configuration is an object

Maybe this needs to be defined in a seperate namespace (e.g. Cloudflare\API\Configuration) because it's no longer an array.

* Incorporate review
2017-11-25 11:45:18 +08:00
Kleis Auke Wolthuizen
ff42f334a5 PHP !== Java 2017-11-21 17:57:31 +01:00
Kleis Auke Wolthuizen
dfa299c895 Remove unused imports 2017-11-21 17:54:30 +01:00
Kleis Auke Wolthuizen
e1864a6824 Drop unneeded arguments 2017-11-21 17:52:59 +01:00
Kleis Auke Wolthuizen
c9d21466aa assertCount should be used instead 2017-11-21 17:50:28 +01:00
Kleis Auke Wolthuizen
b15b4ecc51 Class autoloading correctness 2017-11-21 17:49:29 +01:00
Kleis Auke Wolthuizen
0aa9f6c05a Fix null pointer exception 2017-11-21 17:48:03 +01:00
Kleis Auke Wolthuizen
a09478eb2f Return type doesn't match 2017-11-21 17:47:22 +01:00
Kleis Auke Wolthuizen
f6cb9a8e30 Argument PHPDoc missing 2017-11-21 17:46:53 +01:00
Kleis Auke Wolthuizen
bc9e15a557 Required parameter is missing 2017-11-21 17:46:07 +01:00
Kleis Auke Wolthuizen
5caae74370 Use $array[] instead of array_push 2017-11-21 17:43:47 +01:00
Kleis Auke Wolthuizen
ee4a42ea06 Replace alias functions with origin functions 2017-11-21 17:41:21 +01:00
Kleis Auke Wolthuizen
90eaea7be2 Use === null instead 2017-11-21 17:39:42 +01:00
Kleis Auke Wolthuizen
dac1e15e2d Fix loop which doesn't loop 2017-11-21 17:35:58 +01:00
Kleis Auke Wolthuizen
a4224265d8 Switch from stdClass to object casting 2017-11-21 17:35:01 +01:00
Kleis Auke Wolthuizen
4f3f82b1ba Remove redundant parentheses 2017-11-21 17:28:47 +01:00
Kleis Auke Wolthuizen
7c9ea4874d Shorten the fully qualified class names 2017-11-21 17:27:47 +01:00
Kleis Auke Wolthuizen
0920fc48b2 Remove unnecessary double quotes 2017-11-21 17:25:41 +01:00
Junade
65e4f29bc0 Merge pull request #35 from thellimist/patch-2
Add Contribution Document
2017-11-08 21:28:57 +01:00
Tyler Vigario
3453e44158 Added changeDevelopmentMode & getAnalyticsDashboard to Zones (#32)
* Added toggleDevelopmentMode to Zones

* Improved success checking
Added PHPUnit test (I think?)

* Fixed success checking

* Fixed test

* Ran PHP CS Fixer

* Added getAnalyticsDashboard to Zones
Renamed toggleDevelopmentMode to changeDevelopmentMode to be uniform

* Fixed test (hopefully)

* Trying it a different way

* Another attempt

* Lol I guess we are just supressing errors for this one?
2017-11-08 21:26:32 +01:00
Kan Yilmaz
8ee1bbcc6f Update README.md 2017-11-06 09:06:23 -08:00
Kan Yilmaz
d8b2093eed Create CONTRIBUTING.md 2017-11-06 09:04:19 -08:00
Junade
3cfaed1019 Merge pull request #31 from cloudflare/waf_railgun
Readability: railID to railgunID
2017-10-23 14:37:38 -07:00
Junade Ali
84ee7302ca Readibility: railID to railgunID 2017-10-23 14:29:41 -07:00
Junade
f088c67314 Merge pull request #30 from cloudflare/waf_railgun
Add Web Application Firewall and Railgun
2017-10-23 14:21:45 -07:00
Junade Ali
30fc22aa5b Add Web Application Firewall and Railgun. 2017-10-23 14:17:09 -07:00
Junade
0d89f13f9b Merge pull request #27 from cloudflare/phpmd
Enable PHPMD for src and tests
2017-10-13 15:23:15 +01:00
Junade Ali
ca9e5bbc28 Enabled PHPMD for src and tests 2017-10-13 15:18:08 +01:00
Junade Ali
f0213ecf92 Merge branch 'master' of github.com:cloudflare/cloudflare-php 2017-10-13 14:44:46 +01:00
Junade
b4a6237509 Merge pull request #25 from MertOtrk/patch-1
About cache - 1107 Error code
2017-10-12 01:55:32 +01:00
Mert Oturak
a909f3780e About cache - 1107 Error code 2017-10-12 03:42:35 +03:00
Junade
e1cf1ae41f Merge pull request #24 from limenet/master
Don't double JSON-encode the request
2017-10-07 00:03:10 +01:00
Linus Metzler
70ee68f755 fix the test 2017-10-05 14:44:09 +02:00
Linus Metzler
566ab3fc70 Don't run json_encode
Guzzle takes care of this thanks to its JSON middleware
2017-10-03 21:16:58 +02:00
Junade
ca80e2c388 Merge pull request #23 from cloudflare/cacheoncookie-patch
Correct input types for (Bypass) Cache on Cookie
2017-10-03 18:16:07 +01:00
Junade Ali
d49028a31e Updated DNSTest style. 2017-10-03 18:09:07 +01:00
Junade Ali
6a76e1cc3c Updated DNSTest style. 2017-10-03 18:08:32 +01:00
Junade
a5384b7466 Correct input types for (Bypass) Cache on Cookie 2017-10-03 17:59:59 +01:00
Junade
8ffd3e3541 Merge pull request #18 from anthonysterling/feature/page-rules-config
Consolidated some of the config/option creation
2017-10-03 17:57:57 +01:00
Junade
3ce5e1911f Merge pull request #21 from anthonysterling/fix/issue-19
Added test coverage for DNS Update
2017-10-03 17:42:26 +01:00
Junade
1226d35472 Merge pull request #22 from anthonysterling/fix/inconsistent-array-declaration
Inconsistent Array Declaration
2017-10-03 17:42:16 +01:00
Anthony Sterling
cebeae15a3 Inconsistent Array Declaration
This PR normalises the declaration of arrays throughout the project, and adds
this to the php-cs-fixer rules.

I've chosen "short" by default, but happy to change the PR to use "long" if
preferred.
2017-10-02 09:05:05 +01:00
Anthony Sterling
db62f1db8a Added test coverage for DNS Update
I've added a test to cover the updating of a DNS record to help debug Issue #19
2017-10-02 08:48:43 +01:00
Anthony Sterling
b7e70655ce Consolidated some of the config/option creation
I've just added some internal methods to handle the casting and formatting of the
configuration/option creation.
2017-09-28 21:16:27 +01:00
Junade
49ed1c9e8f Merge pull request #17 from cloudflare/issue-16
Move friendsofphp/php-cs-fixer to dev requirement
2017-09-25 16:41:28 +01:00
Junade
68a26e7e77 Comma correction 2017-09-25 15:49:49 +01:00
Junade
b4a13d8e2b Move friendsofphp/php-cs-fixer to dev requirement 2017-09-25 15:48:07 +01:00
Junade
a80747ee06 Merge pull request #15 from anthonysterling/feature/fixtures
Moved JSON API Responses to test fixtures
2017-09-24 18:41:15 +01:00
Anthony Sterling
fbb5aac074 Moved JSON API Responses to test fixtures
This PR moves the JSON API responses used in the tests to fixture files
within the tests folder. This allows reuse and the ability to lint/validate
these fixtures if required - although not covered in this PR.

I've added TestCase::getPsr7StreamForFixture and TestCase::getPsr7JsonResponseForFixture
to reduce code duplication and enable some assertions around the expected fixures/responses.

Thanks,
2017-09-24 15:24:33 +01:00
Junade
471227b96f Merge pull request #14 from anthonysterling/feature/coding-standard
feature/coding standard
2017-09-24 14:07:03 +01:00
Junade
4d17609641 Merge pull request #13 from kelunik/readme-improvements
Remove leading namespace slashes in README
2017-09-24 14:04:09 +01:00
Anthony Sterling
feecc9fcbb Added lint target as php-cs-fixer only returns a non-zero exit code during dry run now 2017-09-23 22:04:26 +01:00
Anthony Sterling
589766e008 Removed the before_script section for Travis CI as this functionality is default now 2017-09-23 19:02:17 +01:00
Anthony Sterling
2faff272df Applied PSR2 formatting to existing files 2017-09-23 18:50:51 +01:00
Anthony Sterling
90196ea836 Added, and configured, php-cs-fixer with a Makefile to invoke fix and test 2017-09-23 18:49:58 +01:00
Anthony Sterling
80c611691b Removed out-of-date composer.lock file - libraries usually do not contain one anyway 2017-09-23 18:39:45 +01:00
Niklas Keller
85385dedf5 Remove leading namespace slashes in README
This makes it consistent with the middle line and is nicer to read.
2017-09-23 11:52:05 +02:00
Junade
b91dd5e684 Merge pull request #5 from typhonius/add-query-to-get
Adds the query parameter to the guzzle call for GET requests.
2017-09-21 23:16:50 +01:00
Junade
77df7ead1e Merge pull request #11 from typhonius/fix-zone-id-verification
Changes sizeof check to throw an error if no zone id is found.
2017-09-21 18:07:55 +01:00
Adam Malone
9939afd0b6 Changes sizeof check to throw an error if no zone id is found. 2017-09-22 02:53:25 +10:00
Adam Malone
7d838d7f5f Adds the query parameter to the guzzle call for GET requests. 2017-09-21 11:45:21 +10:00
Junade
ebe2a9803a Added link to Packagist and the Cloudflare KB 2017-09-20 16:17:49 +01:00
173 changed files with 8425 additions and 1656 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/.idea
/vendor/

15
.php_cs Normal file
View File

@@ -0,0 +1,15 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;

View File

@@ -11,4 +11,5 @@ install:
- travis_retry composer install --no-interaction --prefer-source
script:
- composer test
- make lint
- make test

17
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,17 @@
# Contributing to Cloudflare PHP API Binding
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
## How To Contribute
We welcome community contribution to this repository. To help add functionality or address issues, please take the following steps:
* Fork the repository from the master branch.
* Create a new branch for your features / fixes.
* Make the changes you wish to see.
* Add tests for all changes.
* Run `make fix` command to ensure the code is styled.
* Run `make test` command to ensure the tests pass.
* Create a pull request with details of what changes have been made and explanation of new behaviour.
* Ensure documentation contains the correct information.
* Pull requests will be reviewed and hopefully merged into a release.

17
Makefile Normal file
View File

@@ -0,0 +1,17 @@
THIS := $(realpath $(lastword $(MAKEFILE_LIST)))
HERE := $(shell dirname $(THIS))
.PHONY: all fix lint test
all: lint test
fix:
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs
lint:
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs --dry-run
php $(HERE)/vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
php $(HERE)/vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
test:
php $(HERE)/vendor/bin/phpunit --configuration $(HERE)/phpunit.xml

View File

@@ -4,40 +4,47 @@
## Installation
The recommended way to install this package is via the Packagist Dependency Manager.
The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can get specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
## Cloudflare API version 4
The Cloudflare API can be found [here](https://api.cloudflare.com/).
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
- [x] [DNS Records](https://www.cloudflare.com/dns/)
- [x] Zones
- [x] User Administration (partial)
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [ ] Virtual DNS Management
- [ ] Custom hostnames
- [x] Custom hostnames
- [x] Manage TLS settings
- [x] Zone Lockdown and User-Agent Block rules
- [ ] Organization Administration
- [ ] [Railgun](https://www.cloudflare.com/railgun/) administration
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
- [ ] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/)
- [x] Crypto
- [x] Load Balancers
- [x] Firewall Settings
Note that this repository is currently under development, additional classes and endpoints being actively added.
## Getting Started
```php
$key = new \Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
$key = new Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
$user = new \Cloudflare\API\Endpoints\User($adapter);
$user = new Cloudflare\API\Endpoints\User($adapter);
echo $user->getUserID();
```
## Contributions
We welcome community contribution to this repository. [CONTRIBUTING.md](CONTRIBUTING.md) will help you start contributing.
## Licensing
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.

View File

@@ -5,11 +5,13 @@
"require": {
"guzzlehttp/guzzle": "^6.2.2",
"php": ">=7.0.0",
"psr/http-message": "~1.0"
"psr/http-message": "~1.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "5.7.5",
"phpmd/phpmd" : "@stable"
"phpmd/phpmd" : "@stable",
"friendsofphp/php-cs-fixer": "^2.6"
},
"license": "BSD-3-Clause",
"authors": [
@@ -23,7 +25,14 @@
"Cloudflare\\API\\": "src/"
}
},
"scripts": {
"test": "phpunit"
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}

1602
composer.lock generated

File diff suppressed because it is too large Load Diff

BIN
phpcbf.phar Normal file

Binary file not shown.

BIN
phpcs.phar Normal file

Binary file not shown.

View File

@@ -21,55 +21,56 @@ interface Adapter
* Adapter constructor.
*
* @param Auth $auth
* @param String $baseURI
* @param string $baseURI
*/
public function __construct(Auth $auth, String $baseURI);
public function __construct(Auth $auth, string $baseURI);
/**
* Sends a GET request.
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
* RFCs, it is never useful).
*
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
*
* @return mixed
*/
public function get(String $uri, array $headers): ResponseInterface;
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function post(String $uri, array $headers, array $body): ResponseInterface;
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function put(String $uri, array $headers, array $body): ResponseInterface;
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function patch(String $uri, array $headers, array $body): ResponseInterface;
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function delete(String $uri, array $headers, array $body): ResponseInterface;
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
}

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Adapter;
use Cloudflare\API\Auth\Auth;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
@@ -19,10 +18,10 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function __construct(Auth $auth, String $baseURI = null)
public function __construct(Auth $auth, string $baseURI = null)
{
if ($baseURI === null) {
$baseURI = "https://api.cloudflare.com/client/v4/";
$baseURI = 'https://api.cloudflare.com/client/v4/';
}
$headers = $auth->getHeaders();
@@ -38,76 +37,56 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function get(String $uri, array $headers = array()): ResponseInterface
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->get($uri, ['headers' => $headers]);
$this->checkError($response);
return $response;
return $this->request('get', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function post(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->post($uri, [
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
return $this->request('post', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function put(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$jsonBody = json_encode($body);
$response = $this->client->put($uri, [
'headers' => $headers,
'json' => $jsonBody
]
);
$this->checkError($response);
return $response;
return $this->request('put', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function patch(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$jsonBody = json_encode($body);
$response = $this->client->patch($uri, [
'headers' => $headers,
'json' => $jsonBody
]
);
$this->checkError($response);
return $response;
return $this->request('patch', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function delete(String $uri, array $headers = array(), array $body = array()): ResponseInterface
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->delete($uri, [
return $this->request('delete', $uri, $data, $headers);
}
public function request(string $method, string $uri, array $data = [], array $headers = [])
{
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
}
$response = $this->client->$method($uri, [
'headers' => $headers,
'json' => $body
]
);
($method === 'get' ? 'query' : 'json') => $data,
]);
$this->checkError($response);
return $response;
}
@@ -119,14 +98,12 @@ class Guzzle implements Adapter
throw new JSONException();
}
if (isset($json->errors)) {
foreach ($json->errors as $error) {
throw new ResponseException($error->message, $error->code);
}
if (isset($json->errors) && count($json->errors) >= 1) {
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code);
}
if (isset($json->success) && ($json->success === false)) {
throw new ResponseException("Request was unsuccessful.");
if (isset($json->success) && !$json->success) {
throw new ResponseException('Request was unsuccessful.');
}
}
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Adapter;
class JSONException extends \Exception
{
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Adapter;
class ResponseException extends \Exception
{
}

View File

@@ -7,13 +7,12 @@
namespace Cloudflare\API\Auth;
class APIKey implements Auth
{
private $email;
private $apiKey;
public function __construct(String $email, String $apiKey)
public function __construct(string $email, string $apiKey)
{
$this->email = $email;
$this->apiKey = $apiKey;

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Auth;
interface Auth
{
public function getHeaders(): array;

View File

@@ -8,7 +8,6 @@
namespace Cloudflare\API\Auth;
class None implements Auth
{
public function getHeaders(): array

View File

@@ -7,12 +7,11 @@
namespace Cloudflare\API\Auth;
class UserServiceKey implements Auth
{
private $userServiceKey;
public function __construct(String $userServiceKey)
public function __construct(string $userServiceKey)
{
$this->userServiceKey = $userServiceKey;
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Cloudflare\API\Configurations;
class AccessRules implements Configurations
{
private $config;
public function setIP(string $value)
{
$this->config = ['target' => 'ip', 'value' => $value];
}
public function setIPRange(string $value)
{
$this->config = ['target' => 'ip_range', 'value' => $value];
}
public function setCountry(string $value)
{
$this->config = ['target' => 'country', 'value' => $value];
}
public function setASN(string $value)
{
$this->config = ['target' => 'asn', 'value' => $value];
}
public function getArray(): array
{
return $this->config;
}
}

View File

@@ -8,7 +8,6 @@
namespace Cloudflare\API\Configurations;
interface Configurations
{
public function getArray(): array;

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Configurations;
class ConfigurationsException extends \Exception
{
}

View File

@@ -0,0 +1,178 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
namespace Cloudflare\API\Configurations;
class LoadBalancer implements Configurations
{
private $configs = [];
public function __construct(string $name, array $defaultPools, string $fallbackPool)
{
$this->setName($name);
$this->setDefaultPools($defaultPools);
$this->setFallbackPool($fallbackPool);
}
public function setName(string $name)
{
$this->configs['name'] = $name;
}
public function getName():string
{
return $this->configs['name'] ?? '';
}
public function setDefaultPools(array $defaultPools)
{
$this->configs['default_pools'] = $defaultPools;
}
public function getDefaultPools():array
{
return $this->configs['default_pools'] ?? [];
}
public function setFallbackPool(string $fallbackPool)
{
$this->configs['fallback_pools'] = $fallbackPool;
}
public function getFallbackPool():string
{
return $this->configs['fallback_pools'] ?? '';
}
public function setSteeringPolicy(string $steeringPolicy = '')
{
$allowedOptions = ['off', 'geo', 'random', 'dynamic_latency', ''];
if (!in_array($steeringPolicy, $allowedOptions)) {
throw new ConfigurationsException('Given steering policy value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
}
$this->configs['steering_policy'] = $steeringPolicy;
}
public function getSteeringPolicy():string
{
return $this->configs['steering_policy'] ?? '';
}
public function enable()
{
$this->configs['enabled'] = true;
}
public function isEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function disable()
{
$this->configs['enabled'] = false;
}
public function isDisabled():bool
{
return !$this->configs['enabled'] ?? false;
}
public function getEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function setPopPools(array $popPools)
{
$this->configs['pop_pools'] = $popPools;
}
public function getPopPools():array
{
return $this->configs['pop_pools'] ?? [];
}
public function setTtl(int $ttl)
{
$this->configs['ttl'] = $ttl;
}
public function getTtl():int
{
return $this->configs['ttl'] ?? 30;
}
public function setRegionPools(array $regionPools)
{
$this->configs['region_pools'] = $regionPools;
}
public function getRegionPools():array
{
return $this->configs['region_pools'] ?? [];
}
public function setSessionAffinity(string $sessionAffinity = '')
{
$allowedOptions = ['none', 'cookie', 'ip_cookie', ''];
if (!in_array($sessionAffinity, $allowedOptions)) {
throw new ConfigurationsException('Given session affinity value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
}
$this->configs['session_affinity'] = $sessionAffinity;
}
public function getSessionAffinity():string
{
return $this->configs['session_affinity'] ?? '';
}
public function setDescription(string $description = '')
{
$this->configs['description'] = $description;
}
public function getDescription():string
{
return $this->configs['description'] ?? '';
}
public function enableProxied()
{
$this->configs['proxied'] = true;
}
public function disableProxied()
{
$this->configs['proxied'] = false;
}
public function isProxied():bool
{
return $this->configs['proxied'] ?? true;
}
public function setSessionAffinityTtl(int $sessionAffinityTtl = 82800)
{
if ($sessionAffinityTtl > 604800 || $sessionAffinityTtl < 1800) {
throw new ConfigurationsException('The value of session affinity ttl must be between 1800 and 604800');
}
$this->configs['session_affinity_ttl'] = $sessionAffinityTtl;
}
public function getSessionAffinityTtl():int
{
return $this->configs['session_affinity_ttl'] ?? 82800;
}
public function getArray(): array
{
return $this->configs;
}
}

View File

@@ -10,360 +10,304 @@ namespace Cloudflare\API\Configurations;
class PageRulesActions implements Configurations
{
private $configs = array();
private $configs = [];
public function setAlwaysOnline(bool $active)
{
$object = new \stdClass();
$object->id = "always_online";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('always_online', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAlwaysUseHTTPS(bool $active)
{
$object = new \stdClass();
$object->id = "always_use_https";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('always_use_https', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBrowserCacheTTL(int $ttl)
{
$object = new \stdClass();
$object->id = "browser_cache_ttl";
$object->value = $ttl;
array_push($this->configs, $object);
$this->addConfigurationOption('browser_cache_ttl', [
'value' => $ttl
]);
}
public function setBrowserIntegrityCheck(bool $active)
{
$object = new \stdClass();
$object->id = "browser_check";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('browser_check', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBypassCacheOnCookie(bool $value)
public function setBypassCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
throw new ConfigurationsException('Invalid cookie string.');
}
$object = new \stdClass();
$object->id = "bypass_cache_on_cookie";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('bypass_cache_on_cookie', [
'value' => $value
]);
}
public function setCacheByDeviceType(bool $active)
{
$object = new \stdClass();
$object->id = "cache_by_device_type";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('cache_by_device_type', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setCacheKey(string $value)
{
$object = new \stdClass();
$object->id = "cache_key";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('cache_key', [
'value' => $value
]);
}
public function setCacheLevel(string $value)
{
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
throw new ConfigurationsException("Invalid cache level");
if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) {
throw new ConfigurationsException('Invalid cache level');
}
$object = new \stdClass();
$object->id = "cache_level";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('cache_level', [
'value' => $value
]);
}
public function setCacheOnCookie(bool $value)
public function setCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
throw new ConfigurationsException('Invalid cookie string.');
}
$object = new \stdClass();
$object->id = "cache_on_cookie";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('cache_on_cookie', [
'value' => $value
]);
}
public function setDisableApps(bool $active)
{
$object = new \stdClass();
$object->id = "disable_apps";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('disable_apps', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisablePerformance(bool $active)
{
$object = new \stdClass();
$object->id = "disable_performance";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('disable_performance', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableSecurity(bool $active)
{
$object = new \stdClass();
$object->id = "disable_security";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('disable_security', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setEdgeCacheTTL(int $value)
{
if ($value > 2419200) {
throw new ConfigurationsException("Edge Cache TTL too high.");
throw new ConfigurationsException('Edge Cache TTL too high.');
}
$object = new \stdClass();
$object->id = "edge_cache_ttl";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('edge_cache_ttl', [
'value' => $value
]);
}
public function setEmailObfuscation(bool $active)
{
$object = new \stdClass();
$object->id = "disable_security";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('disable_security', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setForwardingURL(int $statusCode, string $forwardingUrl)
{
if (in_array($statusCode, ['301', '302'])) {
if (!in_array($statusCode, ['301', '302'])) {
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
}
$object = new \stdClass();
$object->id = "forwarding_url";
$object->status_code = $statusCode;
$object->url = $forwardingUrl;
array_push($this->configs, $object);
$this->addConfigurationOption("forwarding_url", [
'value' => [
'status_code' => $statusCode,
'url' => $forwardingUrl,
],
]);
}
public function setHostHeaderOverride(bool $active)
{
$object = new \stdClass();
$object->id = "host_header_override";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('host_header_override', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setHotlinkProtection(bool $active)
{
$object = new \stdClass();
$object->id = "hotlink_protection";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('hotlink_protection', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setIPGeoLocationHeader(bool $active)
{
$object = new \stdClass();
$object->id = "ip_geolocation";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('ip_geolocation', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setMinification(bool $html, bool $css, bool $js)
public function setMinification(bool $html, bool $css, bool $javascript)
{
$object = new \stdClass();
$object->id = "minification";
$object->html = $html === true ? "on" : "off";
$object->css = $css === true ? "on" : "off";
$object->js = $js === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('minification', [
'html' => $this->getBoolAsOnOrOff($html),
'css' => $this->getBoolAsOnOrOff($css),
'js' => $this->getBoolAsOnOrOff($javascript),
]);
}
public function setMirage(bool $active)
{
$object = new \stdClass();
$object->id = "mirage";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('mirage', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOriginErrorPagePassthru(bool $active)
{
$object = new \stdClass();
$object->id = "origin_error_page_pass_thru";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('origin_error_page_pass_thru', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setQueryStringSort(bool $active)
{
$object = new \stdClass();
$object->id = "sort_query_string_for_cache";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('sort_query_string_for_cache', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableRailgun(bool $active)
{
$object = new \stdClass();
$object->id = "disable_railgun";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('disable_railgun', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResolveOverride(bool $value)
{
$object = new \stdClass();
$object->id = "resolve_override";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('resolve_override', [
'value' => $value
]);
}
public function setRespectStrongEtag(bool $active)
{
$object = new \stdClass();
$object->id = "respect_strong_etag";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('respect_strong_etag', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResponseBuffering(bool $active)
{
$object = new \stdClass();
$object->id = "response_buffering";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('response_buffering', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setRocketLoader(string $value)
{
if (!in_array($value, ["off", "manual", "automatic"])) {
if (!in_array($value, ['off', 'manual', 'automatic'])) {
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
}
$object = new \stdClass();
$object->id = "rocket_loader";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('rocket_loader', [
'value' => $value
]);
}
public function setSecurityLevel(string $value)
{
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
if (!in_array($value, ['off', 'essentially_off', 'low', 'medium', 'high', 'under_attack'])) {
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
}
$object = new \stdClass();
$object->id = "security_level";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('security_level', [
'value' => $value
]);
}
public function setServerSideExcludes(bool $active)
{
$object = new \stdClass();
$object->id = "server_side_exclude";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('server_side_exclude', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSmartErrors(bool $active)
{
$object = new \stdClass();
$object->id = "smart_errors";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('smart_errors', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSSL(string $value)
{
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) {
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
}
$object = new \stdClass();
$object->id = "smart_errors";
$object->value = $value;
array_push($this->configs, $object);
$this->addConfigurationOption('ssl', [
'value' => $value
]);
}
public function setTrueClientIpHeader(bool $active)
{
$object = new \stdClass();
$object->id = "true_client_ip_header";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('true_client_ip_header', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setWAF(bool $active)
{
$object = new \stdClass();
$object->id = "waf";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('waf', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAutomatedHTTPSRewrites(bool $active)
{
$object = new \stdClass();
$object->id = "automatic_https_rewrites";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('automatic_https_rewrites', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOpportunisticEncryption(bool $active)
{
$object = new \stdClass();
$object->id = "opportunistic_encryption";
$object->value = $active === true ? "on" : "off";
array_push($this->configs, $object);
$this->addConfigurationOption('opportunistic_encryption', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function getArray(): array
{
return $this->configs;
}
private function addConfigurationOption(string $setting, array $configuration)
{
$configuration['id'] = $setting;
array_push($this->configs, $configuration);
}
private function getBoolAsOnOrOff(bool $value): string
{
return true === $value ? 'on' : 'off';
}
}

View File

@@ -8,20 +8,21 @@
namespace Cloudflare\API\Configurations;
class PageRulesTargets implements Configurations
{
private $targets;
public function __construct(string $queryUrl)
{
$target = new \stdClass();
$target->target = 'url';
$target->constraint = new \stdClass();
$target->constraint->operator = "matches";
$target->constraint->value = $queryUrl;
$this->targets = [$target];
$this->targets = [
[
'target' => 'url',
'constraint' => [
'operator' => 'matches',
'value' => $queryUrl
]
]
];
}
public function getArray(): array

121
src/Configurations/Pool.php Normal file
View File

@@ -0,0 +1,121 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
namespace Cloudflare\API\Configurations;
class Pool implements Configurations
{
private $configs = [];
public function __construct(string $name, array $origins)
{
$this->setName($name);
$this->setOrigins($origins);
}
public function setName(string $name)
{
$this->configs['name'] = $name;
}
public function getName():string
{
return $this->configs['name'] ?? '';
}
public function setOrigins(array $origins)
{
foreach ($origins as $origin) {
if (!isset($origin['name'])) {
throw new ConfigurationsException('name is required for origin');
}
if (!isset($origin['address'])) {
throw new ConfigurationsException('address is required for origin');
}
}
$this->configs['origins'] = $origins;
}
public function getOrigins():array
{
return $this->configs['origins'] ?? [];
}
public function setDescription(string $description = '')
{
$this->configs['description'] = $description;
}
public function getDescription():string
{
return $this->configs['description'] ?? '';
}
public function enable()
{
$this->configs['enabled'] = true;
}
public function isEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function disable()
{
$this->configs['enabled'] = false;
}
public function isDisabled():bool
{
return !$this->configs['enabled'] ?? false;
}
public function getEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function setMonitor(string $monitor)
{
$this->configs['monitor'] = $monitor;
}
public function getMonitor():string
{
return $this->configs['monitor'] ?? '';
}
public function setCheckRegions(array $checkRegions)
{
$this->configs['check_regions'] = $checkRegions;
}
public function getCheckRegions():array
{
return $this->configs['check_regions'] ?? [];
}
public function setNotificationEmail(string $email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
throw new ConfigurationsException('Invalid notification email given');
}
$this->configs['notification_email'] = $email;
}
public function getNotificationEmail():string
{
return $this->configs['notification_email'] ?? '';
}
public function getArray(): array
{
return $this->configs;
}
}

View File

@@ -8,18 +8,13 @@
namespace Cloudflare\API\Configurations;
class UARules implements Configurations
{
private $configs = array();
private $configs = [];
public function addUA(string $value)
{
$object = new \stdClass();
$object->target = "ua";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ua', 'value' => $value];
}
public function getArray(): array

View File

@@ -8,27 +8,18 @@
namespace Cloudflare\API\Configurations;
class ZoneLockdown implements Configurations
{
private $configs = array();
private $configs = [];
public function addIP(string $value)
{
$object = new \stdClass();
$object->target = "ip";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ip', 'value' => $value];
}
public function addIPRange(string $value)
{
$object = new \stdClass();
$object->target = "ip_range";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ip_range', 'value' => $value];
}
public function getArray(): array

View File

@@ -7,7 +7,6 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
interface API

View File

@@ -0,0 +1,156 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Traits\BodyAccessorTrait;
class AccessRules implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @param string $zoneID
* @param string $scopeType
* @param string $mode
* @param string $configurationTarget
* @param string $configurationValue
* @param int $page
* @param int $perPage
* @param string $order
* @param string $direction
* @param string $match
* @param string $notes
* @return \stdClass
*/
public function listRules(
string $zoneID,
string $scopeType = '',
string $mode = '',
string $configurationTarget = '',
string $configurationValue = '',
int $page = 1,
int $perPage = 50,
string $order = '',
string $direction = '',
string $match = 'all',
string $notes = ''
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($scopeType)) {
$query['scope_type'] = $scopeType;
}
if (!empty($mode)) {
$query['mode'] = $mode;
}
if (!empty($configurationTarget)) {
$query['configuration_target'] = $configurationTarget;
}
if (!empty($configurationValue)) {
$query['configuration_value'] = $configurationValue;
}
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
if (!empty($notes)) {
$query['notes'] = $notes;
}
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
$this->body = json_decode($data->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function createRule(
string $zoneID,
string $mode,
Configurations $configuration,
string $notes = null
): bool {
$options = [
'mode' => $mode,
'configuration' => $configuration->getArray()
];
if ($notes !== null) {
$options['notes'] = $notes;
}
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
public function updateRule(
string $zoneID,
string $ruleID,
string $mode,
string $notes = null
): bool {
$options = [
'mode' => $mode
];
if ($notes !== null) {
$options['notes'] = $notes;
}
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'none'): bool
{
$options = [
'cascade' => $cascade
];
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
$this->body = json_decode($data->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

95
src/Endpoints/Crypto.php Normal file
View File

@@ -0,0 +1,95 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class Crypto implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Get the Opportunistic Encryption feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getOpportunisticEncryptionSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/opportunistic_encryption'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get the Onion Routing feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getOnionRoutingSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/opportunistic_onion'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Update the Oppurtunistic Encryption setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateOpportunisticEncryptionSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/opportunistic_encryption',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the Onion Routing setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateOnionRoutingSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/opportunistic_onion',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 18/03/2018
* Time: 21:46
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class CustomHostnames implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $hostname
* @param string $sslMethod
* @param string $sslType
* @return \stdClass
*/
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
{
$options = [
'hostname' => $hostname,
'ssl' => [
'method' => $sslMethod,
'type' => $sslType
]
];
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
$this->body = json_decode($zone->getBody());
return $this->body->result;
}
/**
* @param string $zoneID
* @param string $hostname
* @param string $id
* @param int $page
* @param int $perPage
* @param string $order
* @param string $direction
* @param int $ssl
* @return \stdClass
*/
public function listHostnames(
string $zoneID,
string $hostname = '',
string $hostnameID = '',
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = '',
int $ssl = 0
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'ssl' => $ssl
];
if (!empty($hostname)) {
$query['hostname'] = $hostname;
}
if (!empty($hostnameID)) {
$query['id'] = $hostnameID;
}
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
$this->body = json_decode($zone->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
/**
* @param string $zoneID
* @param string $hostnameID
* @return mixed
*/
public function getHostname(string $zoneID, string $hostnameID)
{
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
$this->body = json_decode($zone->getBody());
return $this->body->result;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $hostnameID
* @param string $sslMethod
* @param string $sslType
* @return \stdClass
*/
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
{
$query = [];
if (!empty($sslMethod)) {
$query['method'] = $sslMethod;
}
if (!empty($sslType)) {
$query['type'] = $sslType;
}
$options = [
'ssl' => $query
];
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
$this->body = json_decode($zone->getBody());
return $this->body->result;
}
/**
* @param string $zoneID
* @param string $hostnameID
* @return \stdClass
*/
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
{
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
$this->body = json_decode($zone->getBody());
return $this->body;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class DNS implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -19,13 +22,28 @@ class DNS implements API
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $type
* @param string $name
* @param string $content
* @param int $ttl
* @param bool $proxied
* @param string $priority
* @param array $data
* @return bool
*/
public function addRecord(
string $zoneID,
string $type,
string $name,
string $content,
int $ttl = 0,
bool $proxied = true
bool $proxied = true,
string $priority = '',
array $data = []
): bool {
$options = [
'type' => $type,
@@ -38,11 +56,19 @@ class DNS implements API
$options['ttl'] = $ttl;
}
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
if (!empty($priority)) {
$options['priority'] = (int)$priority;
}
$body = json_decode($user->getBody());
if (!empty($data)) {
$options['data'] = $data;
}
if (isset($body->result->id)) {
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true;
}
@@ -51,77 +77,80 @@ class DNS implements API
public function listRecords(
string $zoneID,
string $type = "",
string $name = "",
string $content = "",
string $type = '',
string $name = '',
string $content = '',
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($type)) {
$options['type'] = $type;
$query['type'] = $type;
}
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($content)) {
$options['content'] = $content;
$query['content'] = $content;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
if (!empty($direction)) {
$options['direction'] = $direction;
$query['direction'] = $direction;
}
$query = http_build_query($options);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
$this->body = json_decode($user->getBody());
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, []);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
{
$records = $this->listRecords($zoneID, $type, $name);
if (isset($records->result{0}->id)) {
return $records->result{0}->id;
}
return false;
}
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
return json_decode($response->getBody());
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
$this->body = json_decode($response->getBody());
return $this->body;
}
public function deleteRecord(string $zoneID, string $recordID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -8,8 +8,6 @@
namespace Cloudflare\API\Endpoints;
class EndpointException extends \Exception
{
}

View File

@@ -0,0 +1,135 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class FirewallSettings implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Get the Security Level feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getSecurityLevelSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/security_level'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get the Challenge TTL feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return integer|false
*/
public function getChallengeTTLSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/challenge_ttl'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get the Browser Integrity Check feature for a zone.
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getBrowserIntegrityCheckSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/browser_check'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Update the Security Level setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSecurityLevelSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/security_level',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the Challenge TTL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param int $value The value of the zone setting
* @return bool
*/
public function updateChallengeTTLSetting(string $zoneID, int $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/challenge_ttl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the Browser Integrity Check setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateBrowserIntegrityCheckSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/browser_check',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

View File

@@ -8,11 +8,13 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class IPs implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -20,10 +22,11 @@ class IPs implements API
$this->adapter = $adapter;
}
public function listIPs(): \stdClass {
$ips = $this->adapter->get('ips', []);
$body = json_decode($ips->getBody());
public function listIPs(): \stdClass
{
$ips = $this->adapter->get('ips');
$this->body = json_decode($ips->getBody());
return $body->result;
return $this->body->result;
}
}

View File

@@ -0,0 +1,157 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\ConfigurationsException;
use Cloudflare\API\Configurations\LoadBalancer;
use Cloudflare\API\Traits\BodyAccessorTrait;
class LoadBalancers implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @param string $zoneID
* @return mixed
*/
public function listLoadBalancers(string $zoneID)
{
$loadBalancers = $this->adapter->get('zones/' . $zoneID . '/load_balancers');
$this->body = json_decode($loadBalancers->getBody());
return $this->body->result;
}
/**
* @param string $zoneID
* @param string $loadBalancerID
* @return mixed
*/
public function getLoadBalancerDetails(string $zoneID, string $loadBalancerID)
{
$loadBalancer = $this->adapter->get('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
$this->body = json_decode($loadBalancer->getBody());
return $this->body->result;
}
/**
* @param string $zoneID
* @param string $loadBalancerID
* @return LoadBalancer
* @throws ConfigurationsException
*/
public function getLoadBalancerConfiguration(string $zoneID, string $loadBalancerID)
{
$loadBalancer = $this->getLoadBalancerDetails($zoneID, $loadBalancerID);
$lbConfiguration = new LoadBalancer($loadBalancer->name, $loadBalancer->default_pools, $loadBalancer->fallback_pool);
$lbConfiguration->setSteeringPolicy($loadBalancer->steering_policy);
if ($loadBalancer->enabled === true) {
$lbConfiguration->enable();
} elseif ($loadBalancer->enabled === false) {
$lbConfiguration->disable();
}
if (is_array($loadBalancer->pop_pools)) {
$lbConfiguration->setPopPools($loadBalancer->pop_pools);
}
if (isset($loadBalancer->ttl)) {
$lbConfiguration->setTtl($loadBalancer->ttl);
}
if (is_array($loadBalancer->region_pools)) {
$lbConfiguration->setRegionPools($loadBalancer->region_pools);
}
$lbConfiguration->setSessionAffinity($loadBalancer->session_affinity);
$lbConfiguration->setDescription($loadBalancer->description);
if ($loadBalancer->proxied === true) {
$lbConfiguration->enableProxied();
} elseif ($loadBalancer->proxied === false) {
$lbConfiguration->disableProxied();
}
if (isset($loadBalancer->session_affinity_ttl)) {
$lbConfiguration->setSessionAffinityTtl($loadBalancer->session_affinity_ttl);
}
return $lbConfiguration;
}
/**
* @param string $zoneID
* @param string $loadBalancerID
* @param LoadBalancer $lbConfiguration
* @return bool
*/
public function updateLoadBalancer(
string $zoneID,
string $loadBalancerID,
LoadBalancer $lbConfiguration
): bool {
$options = $lbConfiguration->getArray();
$query = $this->adapter->put('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID, $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* @param string $zoneID
* @param LoadBalancer $lbConfiguration
* @return bool
*/
public function createLoadBalancer(
string $zoneID,
LoadBalancer $lbConfiguration
): bool {
$options = $lbConfiguration->getArray();
$query = $this->adapter->post('zones/' . $zoneID . '/load_balancers', $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* @param string $zoneID
* @param string $loadBalancerID
* @return bool
*/
public function deleteLoadBalancer(string $zoneID, string $loadBalancerID): bool
{
$loadBalancer = $this->adapter->delete('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
$this->body = json_decode($loadBalancer->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
/* A list of memberships of accounts this user can access */
class Membership implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listMemberships(
string $name = '',
string $status = '',
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = ''
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage
];
if (!empty($name)) {
$query['account.name'] = $name;
}
if (!empty($status) && in_array($status, ['accepted', 'pending', 'rejected'], true)) {
$query['status'] = $status;
}
if (!empty($order) && in_array($order, ['id', 'account.name', 'status'], true)) {
$query['order'] = $order;
}
if (!empty($direction) && in_array($direction, ['asc', 'desc'], true)) {
$query['direction'] = $direction;
}
$memberships = $this->adapter->get('memberships', $query);
$this->body = json_decode($memberships->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getMembershipDetails(string $membershipId): \stdClass
{
$membership = $this->adapter->get(sprintf('memberships/%s', $membershipId));
$this->body = json_decode($membership->getBody());
return $this->body->result;
}
public function updateMembershipStatus(string $membershipId, string $status): \stdClass
{
$response = $this->adapter->put(sprintf('memberships/%s', $membershipId), ['status' => $status]);
$this->body = json_decode($response->getBody());
return $this->body;
}
public function deleteMembership(string $membershipId): bool
{
$response = $this->adapter->delete(sprintf('memberships/%s', $membershipId));
$this->body = json_decode($response->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -8,13 +8,15 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\PageRulesActions;
use Cloudflare\API\Configurations\PageRulesTargets;
use Cloudflare\API\Traits\BodyAccessorTrait;
class PageRules implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -22,6 +24,16 @@ class PageRules implements API
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param PageRulesTargets $target
* @param PageRulesActions $actions
* @param bool $active
* @param int|null $priority
* @return bool
*/
public function createPageRule(
string $zoneID,
PageRulesTargets $target,
@@ -43,11 +55,11 @@ class PageRules implements API
}
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options);
$body = json_decode($query->getBody());
$this->body = json_decode($query->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -61,46 +73,45 @@ class PageRules implements API
string $direction = null,
string $match = null
): array {
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
if ($status === null && !in_array($status, ['active', 'disabled'])) {
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
}
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
if ($order === null && !in_array($order, ['status', 'priority'])) {
throw new EndpointException('Page Rules can only be ordered by status or priority.');
}
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
if ($direction === null && !in_array($direction, ['asc', 'desc'])) {
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
}
if (is_null($match) && !in_array($match, ['all', 'any'])) {
if ($match === null && !in_array($match, ['all', 'any'])) {
throw new EndpointException('Match can only be any or all.');
}
$options = [
$query = [
'status' => $status,
'order' => $order,
'direction' => $direction,
'match' => $match
];
$query = http_build_query($options);
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
$this->body = json_decode($user->getBody());
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules?' . $query, []);
$body = json_decode($user->getBody());
return $body->result;
return $this->body->result;
}
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function updatePageRule(
string $zoneID,
string $ruleID,
PageRulesTargets $target = null,
PageRulesActions $actions = null,
bool $active = null,
@@ -108,7 +119,7 @@ class PageRules implements API
): bool {
$options = [];
if ($active !== null) {
if ($target !== null) {
$options['targets'] = $target->getArray();
}
@@ -124,12 +135,11 @@ class PageRules implements API
$options['priority'] = $priority;
}
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
$this->body = json_decode($query->getBody());
$body = json_decode($query->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -138,11 +148,11 @@ class PageRules implements API
public function deletePageRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

156
src/Endpoints/Pools.php Normal file
View File

@@ -0,0 +1,156 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\ConfigurationsException;
use Cloudflare\API\Configurations\Pool;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Pools implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @param string $accountID
* @return mixed
*/
public function listPools(string $accountID)
{
$pools = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools');
$this->body = json_decode($pools->getBody());
return $this->body->result;
}
/**
* @param string $accountID
* @param string $poolID
* @return mixed
*/
public function getPoolDetails(string $accountID, string $poolID)
{
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
$this->body = json_decode($pool->getBody());
return $this->body->result;
}
/**
* @param string $accountID
* @param string $poolID
* @return mixed
*/
public function getPoolHealthDetails(string $accountID, string $poolID)
{
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID . '/health');
$this->body = json_decode($pool->getBody());
return $this->body->result;
}
/**
* @param string $accountID
* @param string $poolID
* @return Pool
* @throws ConfigurationsException
*/
public function getPoolConfiguration(string $accountID, string $poolID)
{
$pool = $this->getPoolDetails($accountID, $poolID);
$origins = [];
foreach ($pool->origins as $origin) {
$origins[] = (array)$origin;
}
$poolConfiguration = new Pool($pool->name, $origins);
$poolConfiguration->setDescription($pool->description);
if ($pool->enabled === true) {
$poolConfiguration->enable();
} elseif ($pool->enabled === false) {
$poolConfiguration->disable();
}
$poolConfiguration->setMonitor($pool->monitor);
$poolConfiguration->setNotificationEmail($pool->notification_email);
if (is_array($pool->check_regions)) {
$poolConfiguration->setCheckRegions($pool->check_regions);
}
return $poolConfiguration;
}
/**
* @param string $accountID
* @param string $poolID
* @param Pool $poolConfiguration
* @return bool
*/
public function updatePool(
string $accountID,
string $poolID,
Pool $poolConfiguration
): bool {
$options = $poolConfiguration->getArray();
$query = $this->adapter->put('accounts/' . $accountID . '/load_balancers/pools/' . $poolID, $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* @param string $accountID
* @param Pool $poolConfiguration
* @return bool
*/
public function createPool(
string $accountID,
Pool $poolConfiguration
): bool {
$options = $poolConfiguration->getArray();
$query = $this->adapter->post('accounts/' . $accountID . '/load_balancers/pools', $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* @param string $accountID
* @param string $poolID
* @return bool
*/
public function deletePool(string $accountID, string $poolID): bool
{
$pool = $this->adapter->delete('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
$this->body = json_decode($pool->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

102
src/Endpoints/Railgun.php Normal file
View File

@@ -0,0 +1,102 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 23/10/2017
* Time: 11:15
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Railgun implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function create(
string $name
): \stdClass {
$query = [
'name' => $name,
];
$user = $this->adapter->post('railguns', $query);
$this->body = json_decode($user->getBody());
return $this->body;
}
public function list(
int $page = 1,
int $perPage = 20,
string $direction = ''
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage
];
if (!empty($direction)) {
$query['direction'] = $direction;
}
$user = $this->adapter->get('railguns', $query);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function get(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function getZones(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function update(
string $railgunID,
bool $status
): \stdClass {
$query = [
'enabled' => $status
];
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function delete(
string $railgunID
): bool {
$user = $this->adapter->delete('railguns/' . $railgunID);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
}

153
src/Endpoints/SSL.php Normal file
View File

@@ -0,0 +1,153 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class SSL implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Get the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getSSLSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/ssl'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get SSL Verification Info for a Zone
*
* @param string $zoneID The ID of the zone
* @return array|false
*/
public function getSSLVerificationStatus(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/ssl/verification'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body;
}
return false;
}
/**
* Get the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRedirectSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_use_https'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Get the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRewritesSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Update the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSSLSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/ssl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_use_https',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

121
src/Endpoints/TLS.php Normal file
View File

@@ -0,0 +1,121 @@
<?php
/**
* Created by PhpStorm.
* User: Jurgen Coetsiers
* Date: 21/10/2018
* Time: 09:10
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class TLS implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Get the TLS Client Auth setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getTLSClientAuth($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/tls_client_auth'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Enable TLS 1.3 for the zone
*
* @param string $zoneID The ID of the zone
* @return bool
*/
public function enableTLS13($zoneID)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_1_3',
['value' => 'on']
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Disable TLS 1.3 for the zone
*
* @param string $zoneID The ID of the zone
* @return bool
*/
public function disableTLS13($zoneID)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_1_3',
['value' => 'off']
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the minimum TLS version setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $minimumVersion The version to update to
* @return bool
*/
public function changeMinimumTLSVersion($zoneID, $minimumVersion)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/min_tls_version',
[
'value' => $minimumVersion,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the TLS Client Auth setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateTLSClientAuth($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_client_auth',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

View File

@@ -8,10 +8,14 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class UARules implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -24,49 +28,42 @@ class UARules implements API
int $page = 1,
int $perPage = 20
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage
];
$query = http_build_query($options);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
$this->body = json_decode($user->getBody());
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function createRule(
string $zoneID,
string $mode,
\Cloudflare\API\Configurations\Configurations $configuration,
string $id = null,
Configurations $configuration,
string $ruleID = null,
string $description = null
): bool {
$options = [
'mode' => $mode,
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
if ($ruleID !== null) {
$options['id'] = $ruleID;
}
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -75,9 +72,9 @@ class UARules implements API
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function updateRule(
@@ -87,7 +84,6 @@ class UARules implements API
\Cloudflare\API\Configurations\UARules $configuration,
string $description = null
): bool {
$options = [
'mode' => $mode,
'id' => $ruleID,
@@ -98,11 +94,11 @@ class UARules implements API
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -111,11 +107,11 @@ class UARules implements API
public function deleteRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

View File

@@ -7,11 +7,13 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class User implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -21,24 +23,25 @@ class User implements API
public function getUserDetails(): \stdClass
{
$user = $this->adapter->get('user', []);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->get('user');
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function getUserID(): string
{
return ($this->getUserDetails())->id;
return $this->getUserDetails()->id;
}
public function getUserEmail(): string
{
return ($this->getUserDetails())->email;
return $this->getUserDetails()->email;
}
public function updateUserDetails(array $details): \stdClass
{
$response = $this->adapter->patch("user", [], $details);
return json_decode($response->getBody());
$response = $this->adapter->patch('user', $details);
$this->body = json_decode($response->getBody());
return $this->body;
}
}

183
src/Endpoints/WAF.php Normal file
View File

@@ -0,0 +1,183 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 23/10/2017
* Time: 11:17
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class WAF implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function getPackages(
string $zoneID,
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getPackageInfo(
string $zoneID,
string $packageID
): \stdClass {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function getRules(
string $zoneID,
string $packageID,
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getRuleInfo(
string $zoneID,
string $packageID,
string $ruleID
): \stdClass {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function updateRule(
string $zoneID,
string $packageID,
string $ruleID,
string $status
): \stdClass {
$query = [
'mode' => $status,
];
$user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
$query
);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function getGroups(
string $zoneID,
string $packageID,
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
$user = $this->adapter->get(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
$query
);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getGroupInfo(
string $zoneID,
string $packageID,
string $groupID
): \stdClass {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function updateGroup(
string $zoneID,
string $packageID,
string $groupID,
string $status
): \stdClass {
$query = [
'mode' => $status
];
$user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
$query
);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class ZoneLockdown implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -24,49 +27,42 @@ class ZoneLockdown implements API
int $page = 1,
int $perPage = 20
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage
];
$query = http_build_query($options);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
$this->body = json_decode($user->getBody());
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function createLockdown(
string $zoneID,
array $urls,
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
string $id = null,
string $lockdownID = null,
string $description = null
): bool {
$options = [
'urls' => $urls,
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
if ($lockdownID !== null) {
$options['id'] = $lockdownID;
}
if ($description !== null) {
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', $options);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -75,9 +71,9 @@ class ZoneLockdown implements API
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function updateLockdown(
@@ -87,7 +83,6 @@ class ZoneLockdown implements API
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
string $description = null
): bool {
$options = [
'urls' => $urls,
'id' => $lockdownID,
@@ -98,11 +93,11 @@ class ZoneLockdown implements API
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, $options);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
@@ -111,11 +106,11 @@ class ZoneLockdown implements API
public function deleteLockdown(string $zoneID, string $lockdownID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

View File

@@ -0,0 +1,180 @@
<?php
/**
* Created by PhpStorm.
* User: paul.adams
* Date: 2019-02-22
* Time: 23:28
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class ZoneSettings implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function getMinifySetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/minify'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function getRocketLoaderSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/rocket_loader'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function getAlwaysOnlineSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_online'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function getEmailObfuscationSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/email_obfuscation'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function getHotlinkProtectionSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/hotlink_protection'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function updateMinifySetting($zoneID, $html, $css, $javascript)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/minify',
[
'value' => [
'html' => $html,
'css' => $css,
'js' => $javascript,
],
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
public function updateRocketLoaderSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/rocket_loader',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
public function updateAlwaysOnlineSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_online',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
public function updateEmailObfuscationSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/email_obfuscation',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
public function updateHotlinkProtectionSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/hotlink_protection',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Zones implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
@@ -19,90 +22,170 @@ class Zones implements API
$this->adapter = $adapter;
}
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $name
* @param bool $jumpStart
* @param string $organizationID
* @return \stdClass
*/
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
{
$options = [
'name' => $name,
'jumpstart' => $jumpstart
'jump_start' => $jumpStart
];
if (!empty($organizationID)) {
$organization = new \stdClass();
$organization->id = $organizationID;
$options["organization"] = $organization;
$options['organization'] = ['id' => $organizationID];
}
$user = $this->adapter->post('zones', [], $options);
$body = json_decode($user->getBody());
return $body->result;
$user = $this->adapter->post('zones', $options);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
public function activationCheck(string $zoneID): bool
{
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
$body = json_decode($user->getBody());
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
return false;
}
public function getZoneById(
string $zoneId
): \stdClass {
$user = $this->adapter->get('zones/' . $zoneId);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result];
}
public function listZones(
string $name = "",
string $status = "",
string $name = '',
string $status = '',
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($status)) {
$options['status'] = $status;
$query['status'] = $status;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
if (!empty($direction)) {
$options['direction'] = $direction;
$query['direction'] = $direction;
}
$query = http_build_query($options);
$user = $this->adapter->get('zones', $query);
$this->body = json_decode($user->getBody());
$user = $this->adapter->get('zones?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getZoneID(string $name = ""): string
public function getZoneID(string $name = ''): string
{
$zones = $this->listZones($name);
if (sizeof($zones) < 1) {
throw new EndpointException("Could not find zones with specified name.");
if (count($zones->result) < 1) {
throw new EndpointException('Could not find zones with specified name.');
}
return $zones->result[0]->id;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $since
* @param string $until
* @param bool $continuous
* @return \stdClass
*/
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass
{
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]);
$this->body = $response->getBody();
return json_decode($this->body)->result;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param bool $enable
* @return bool
*/
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
{
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']);
$this->body = json_decode($response->getBody());
if ($this->body->success) {
return true;
}
return false;
}
/**
* Return caching level settings
* @param string $zoneID
* @return string
*/
public function getCachingLevel(string $zoneID): string
{
$response = $this->adapter->get('zones/' . $zoneID . '/settings/cache_level');
$this->body = json_decode($response->getBody());
return $this->body->result->value;
}
/**
* Change caching level settings
* @param string $zoneID
* @param string $level (aggressive | basic | simplified)
* @return bool
*/
public function setCachingLevel(string $zoneID, string $level = 'aggressive'): bool
{
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/cache_level', ['value' => $level]);
$this->body = json_decode($response->getBody());
if ($this->body->success) {
return true;
}
return false;
}
/**
* Purge Everything
* @param string $zoneID
@@ -110,33 +193,41 @@ class Zones implements API
*/
public function cachePurgeEverything(string $zoneID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());
if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}
return false;
}
public function cachePurge(string $zoneID, array $files = [], array $tags = []): bool
public function cachePurge(string $zoneID, array $files = null, array $tags = null, array $hosts = null): bool
{
if (empty($files) && empty($tags)) {
throw new EndpointException("No files or tags to purge.");
if ($files === null && $tags === null && $hosts === null) {
throw new EndpointException('No files, tags or hosts to purge.');
}
$options = [
'files' => $files,
'tags' => $tags
];
$options = [];
if (!is_null($files)) {
$options['files'] = $files;
}
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
if (!is_null($tags)) {
$options['tags'] = $tags;
}
$body = json_decode($user->getBody());
if (!is_null($hosts)) {
$options['hosts'] = $hosts;
}
if (isset($body->result->id)) {
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', $options);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true;
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Cloudflare\API\Traits;
trait BodyAccessorTrait
{
private $body;
public function getBody()
{
return $this->body;
}
}

View File

@@ -8,7 +8,7 @@
use GuzzleHttp\Psr7\Response;
class GuzzleTest extends PHPUnit_Framework_TestCase
class GuzzleTest extends TestCase
{
private $client;
@@ -29,60 +29,64 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$response = $this->client->get('https://httpbin.org/get');
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Test", $body->headers->{"X-Testing"});
$this->assertEquals('Test', $body->headers->{'X-Testing'});
$response = $this->client->get('https://httpbin.org/get', ['X-Another-Test' => 'Test2']);
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
$body = json_decode($response->getBody());
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
$this->assertEquals('Test2', $body->headers->{'X-Another-Test'});
}
public function testPost()
{
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
$response = $this->client->post('https://httpbin.org/post', ['X-Post-Test' => 'Testing a POST request.']);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
$this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'});
}
public function testPut()
{
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
$response = $this->client->put('https://httpbin.org/put', ['X-Put-Test' => 'Testing a PUT request.']);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PUT request.", json_decode($body->json)->{"X-Put-Test"});
$this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'});
}
public function testPatch()
{
$response = $this->client->patch('https://httpbin.org/patch', [],
['X-Patch-Test' => 'Testing a PATCH request.']);
$response = $this->client->patch(
'https://httpbin.org/patch',
['X-Patch-Test' => 'Testing a PATCH request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PATCH request.", json_decode($body->json)->{"X-Patch-Test"});
$this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'});
}
public function testDelete()
{
$response = $this->client->delete('https://httpbin.org/delete', [],
['X-Delete-Test' => 'Testing a DELETE request.']);
$response = $this->client->delete(
'https://httpbin.org/delete',
['X-Delete-Test' => 'Testing a DELETE request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
}
public function testErrors()
@@ -124,9 +128,9 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$method->invokeArgs($this->client, [$response]);
}
public function testNotFound() {
public function testNotFound()
{
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
$response = $this->client->get('https://httpbin.org/status/404');
$this->client->get('https://httpbin.org/status/404');
}
}

View File

@@ -5,7 +5,7 @@
* Date: 13/01/2017
* Time: 17:15
*/
class APIKeyTest extends PHPUnit_Framework_TestCase
class APIKeyTest extends TestCase
{
public function testGetHeaders()
{
@@ -18,7 +18,6 @@ class APIKeyTest extends PHPUnit_Framework_TestCase
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
$this->assertEquals(2, sizeof($headers));
$this->assertCount(2, $headers);
}
}

View File

@@ -6,9 +6,7 @@
* Time: 20:08
*/
use Cloudflare\API\Auth\None;
class NoneTest extends PHPUnit_Framework_TestCase
class NoneTest extends TestCase
{
public function testGetHeaders()
{

View File

@@ -5,19 +5,20 @@
* Date: 13/01/2017
* Time: 18:03
*/
class UserServiceKeyTest extends PHPUnit_Framework_TestCase
class UserServiceKeyTest extends TestCase
{
public function testGetHeaders()
{
$auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a");
$auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a');
$headers = $auth->getHeaders();
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
$this->assertEquals('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
$headers['X-Auth-User-Service-Key']);
$this->assertEquals(1, sizeof($headers));
$this->assertEquals(
'v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
$headers['X-Auth-User-Service-Key']
);
$this->assertCount(1, $headers);
}
}

View File

@@ -6,7 +6,7 @@
* Date: 19/09/2017
* Time: 15:24
*/
class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
class ConfigurationsUARulesTest extends TestCase
{
public function testGetArray()
{
@@ -14,12 +14,14 @@ class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertCount(1, $array);
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ua', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
$array[0]->value);
$this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ua', $array[0]['target']);
$this->assertArrayHasKey('value', $array[0]);
$this->assertEquals(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
$array[0]['value']
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:50
*/
class ConfigurationsZoneLockdownTest extends TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
$configuration->addIP('1.2.3.4');
$array = $configuration->getArray();
$this->assertCount(1, $array);
$this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ip', $array[0]['target']);
$this->assertArrayHasKey('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]['value']);
$configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray();
$this->assertCount(2, $array);
$this->assertArrayHasKey('target', $array[1]);
$this->assertEquals('ip_range', $array[1]['target']);
$this->assertArrayHasKey('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]['value']);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
use Cloudflare\API\Configurations\ConfigurationsException;
use Cloudflare\API\Configurations\LoadBalancer;
class LoadBalancerTest extends TestCase
{
/**
* @dataProvider testArgumentsDataProvider
*/
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
{
$loadBalancer = new LoadBalancer('bogus', [], 'bogus');
foreach ($arguments as $argument) {
if ($invalid === true) {
try {
$loadBalancer->{$setFunction}($argument);
} catch (ConfigurationsException $e) {
$this->assertNotEquals($argument, $loadBalancer->{$getFunction}());
}
} elseif ($invalid === false) {
$loadBalancer->{$setFunction}($argument);
$this->assertEquals($argument, $loadBalancer->{$getFunction}());
}
}
}
public function testArgumentsDataProvider()
{
return [
'steeringPolicy arguments valid' => [
'setSteeringPolicy', ['off', 'geo', 'random', 'dynamic_latency', ''], 'getSteeringPolicy', false
],
'sessionAffinity arguments valid' => [
'setSessionAffinity', ['none', 'cookie', 'ip_cookie', ''], 'getSessionAffinity', false
],
'sessionAffinityTtl arguments valid' => [
'setSessionAffinityTtl', [3600], 'getSessionAffinityTtl', false
],
'steeringPolicy arguments invalid' => [
'setSteeringPolicy', ['invalid'], 'getSteeringPolicy', true
],
'sessionAffinity arguments invalid' => [
'setSessionAffinity', ['invalid'], 'getSessionAffinity', true
],
'sessionAffinityTtl arguments invalid' => [
'setSessionAffinityTtl', [1337], 'getSessionAffinityTtl', true
],
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
use Cloudflare\API\Configurations\PageRulesActions;
class PageRulesActionTest extends TestCase
{
public function testForwardingURLConfigurationIsApplied()
{
$identifier = 'forwarding_url';
$statusCode = 301;
$forwardingURL = 'https://www.example.org/';
$actions = new PageRulesActions();
$actions->setForwardingURL($statusCode, $forwardingURL);
$configuration = $actions->getArray();
$this->assertCount(1, $configuration);
$this->assertEquals($identifier, $configuration[0]['id']);
$this->assertEquals($statusCode, $configuration[0]['value']['status_code']);
$this->assertEquals($forwardingURL, $configuration[0]['value']['url']);
}
}

View File

@@ -8,14 +8,15 @@
use Cloudflare\API\Configurations\PageRulesTargets;
class PageRulesTargetTest extends PHPUnit_Framework_TestCase
class PageRulesTargetTest extends TestCase
{
public function testGetArray()
{
public function testGetArray() {
$targets = new PageRulesTargets('junade.com/*');
$array = $targets->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
$this->assertEquals("matches", $array[0]->constraint->operator);
$this->assertCount(1, $array);
$this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
$this->assertEquals('matches', $array[0]['constraint']['operator']);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
use Cloudflare\API\Configurations\ConfigurationsException;
use Cloudflare\API\Configurations\Pool;
class PoolTest extends TestCase
{
/**
* @dataProvider testArgumentsDataProvider
*/
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
{
$pool = new Pool('bogus', []);
foreach ($arguments as $argument) {
if ($invalid) {
try {
$pool->{$setFunction}($argument);
} catch (ConfigurationsException $e) {
$this->assertNotEquals($argument, $pool->{$getFunction}());
}
} elseif ($invalid === false) {
$pool->{$setFunction}($argument);
$this->assertEquals($argument, $pool->{$getFunction}());
}
}
}
public function testArgumentsDataProvider()
{
return [
'origins arguments valid' => [
'setOrigins', [[['name' => 'test', 'address' => 'server1.example.com']]], 'getOrigins', false
],
'setNotificationEmail arguments valid' => [
'setNotificationEmail', ['user@example.com'], 'getNotificationEmail', false
],
'origins arguments invalid no address' => [
'setOrigins', [['name' => 'test']], 'getOrigins', true
],
'origins arguments invalid no name' => [
'setOrigins', [['address' => 'server1.example.com']], 'getOrigins', true
],
'setNotificationEmail arguments invalid' => [
'setNotificationEmail', ['userexample.com'], 'getNotificationEmail', true
]
];
}
}

View File

@@ -1,34 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:50
*/
class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
$configuration->addIP('1.2.3.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ip', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]->value);
$configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray();
$this->assertEquals(2, sizeof($array));
$this->assertObjectHasAttribute('target', $array[1]);
$this->assertEquals('ip_range', $array[1]->target);
$this->assertObjectHasAttribute('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]->value);
}
}

View File

@@ -0,0 +1,112 @@
<?php
class AccessRulesTest extends TestCase
{
public function testListRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccessRules.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
$this->equalTo([
'page' => 1,
'per_page' => 50,
'match' => 'all'
])
);
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $zones->getBody()->result[0]->id);
}
public function testCreateRule()
{
$config = new \Cloudflare\API\Configurations\AccessRules();
$config->setIP('1.2.3.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
$this->equalTo([
'mode' => 'challenge',
'configuration' => $config->getArray(),
'notes' => 'This rule is on because of an event that occured on date X',
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->createRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'challenge',
$config,
'This rule is on because of an event that occured on date X'
);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
}
public function testUpdateRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([
'mode' => 'challenge',
'notes' => 'This rule is on because of an event that occured on date X',
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->updateRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'92f17202ed8bd63d69a66b86a49a8f6b',
'challenge',
'This rule is on because of an event that occured on date X'
);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
}
public function testDeleteRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([
'cascade' => 'none'
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
}
}

View File

@@ -0,0 +1,82 @@
<?php
class CryptoTest extends TestCase
{
public function testGetOpportunisticEncryptionSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOpportunisticEncryptionSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetOnionRoutingSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOnionRoutingSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testUpdateOpportunisticEncryptionSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption'),
$this->equalTo(['value' => 'off'])
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
public function testUpdateOnionRoutingSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion'),
$this->equalTo(['value' => 'off'])
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 18/03/2018
* Time: 22:23
*/
use Cloudflare\API\Endpoints\CustomHostnames;
class CustomHostnamesTest extends TestCase
{
public function testAddHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
$this->equalTo([
'hostname' => 'app.example.com',
'ssl' => [
'method' => 'http',
'type' => 'dv'
]
])
);
$hostname = new CustomHostnames($mock);
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id);
}
public function testListHostnames()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listHostnames.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
$this->equalTo([
'hostname' => 'app.example.com',
'id' => '0d89c70d-ad9f-4843-b99f-6cc0252067e9',
'page' => 1,
'per_page' => 20,
'order' => 'ssl',
'direction' => 'desc',
'ssl' => 0
])
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->listHostnames('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 1, 20, 'ssl', 'desc', 0);
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result[0]->id);
}
public function testGetHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->getHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
$this->assertObjectHasAttribute('id', $result);
$this->assertObjectHasAttribute('hostname', $result);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
}
public function testUpdateHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
$this->equalTo([
'ssl' => [
'method' => 'http',
'type' => 'dv'
]
])
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
$this->assertObjectHasAttribute('id', $result);
$this->assertObjectHasAttribute('hostname', $result);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
}
public function testDeleteHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id);
}
}

View File

@@ -6,38 +6,19 @@
* Date: 09/06/2017
* Time: 15:31
*/
class DNSTest extends PHPUnit_Framework_TestCase
class DNSTest extends TestCase
{
public function testAddRecord()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), $this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([
'type' => 'A',
'name' => 'example.com',
@@ -53,91 +34,107 @@ class DNSTest extends PHPUnit_Framework_TestCase
public function testListRecords()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records?page=1&per_page=20&match=all&type=A&name=example.com&content=127.0.0.1&order=type&direction=desc'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'order' => 'type',
'direction' => 'desc',
])
);
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353","A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
$result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
}
public function testGetRecordDetails()
public function testGetDNSRecordDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getDNSRecordDetails.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
}
public function testGetRecordID()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordId.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records')
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->getRecordID('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result);
}
public function testUpdateDNSRecord()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$details = [
'type' => 'A',
'name' => 'example.com',
'content' => '1.2.3.4',
'ttl' => 120,
'proxied' => false,
];
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo($details)
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $property }, $value);
}
}
}

View File

@@ -0,0 +1,121 @@
<?php
class FirewallSettingsTest extends TestCase
{
public function testGetSecurityLevelSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSecurityLevelSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level')
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->getSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('medium', $result);
}
public function testGetChallengeTTLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getChallengeTTLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/challenge_ttl')
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->getChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals(1800, $result);
}
public function testGetBrowserIntegrityCheckSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserIntegrityCheckSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check')
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->getBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('on', $result);
}
public function testUpdateSecurityLevelSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSecurityLevelSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level'),
$this->equalTo(['value' => 'medium'])
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->updateSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'medium');
$this->assertTrue($result);
}
public function testUpdateChallengeTTLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateChallengeTTLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/challenge_ttl'),
$this->equalTo(['value' => 1800])
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->updateChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 1800);
$this->assertTrue($result);
}
public function testUpdateBrowserIntegrityCheckSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserIntegrityCheckSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check'),
$this->equalTo(['value' => 'on'])
);
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
$result = $firewallSettingsMock->updateBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'on');
$this->assertTrue($result);
}
}

View File

@@ -6,37 +6,26 @@
* Time: 20:16
*/
use Cloudflare\API\Endpoints\IPs;
class IPsTest extends TestCase
{
public function testListIPs()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listIPs.json');
class IPsTest extends PHPUnit_Framework_TestCase
{
public function testListIPs() {
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"ipv4_cidrs": [
"199.27.128.0/21"
],
"ipv6_cidrs": [
"2400:cb00::/32"
]
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('ips'), $this->equalTo([])
->with(
$this->equalTo('ips')
);
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
$ips = $ips->listIPs();
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
$ipsMock = new \Cloudflare\API\Endpoints\IPs($mock);
$ips = $ipsMock->listIPs();
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
$this->assertObjectHasAttribute('ipv4_cidrs', $ipsMock->getBody()->result);
$this->assertObjectHasAttribute('ipv6_cidrs', $ipsMock->getBody()->result);
}
}

View File

@@ -0,0 +1,128 @@
<?php
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\LoadBalancer;
use Cloudflare\API\Endpoints\LoadBalancers;
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
class LoadBalancersTest extends TestCase
{
public function testCreateLoadBalancer()
{
$pools = [
'17b5962d775c646f3f9725cbc7a53df4',
'9290f38c5d07c2e2f4df57b1f61d4196',
'00920f38ce07c2e2f4df50b1f61d4194'
];
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createLoadBalancer.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers'),
$lbConfiguration->getArray()
);
$loadBalancers = new LoadBalancers($mock);
$result = $loadBalancers->createLoadBalancer('699d98642c564d2e855e9661899b7252', $lbConfiguration);
$this->assertTrue($result);
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
}
public function testListLoadBalancer()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLoadBalancers.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers')
);
$loadBalancers = new LoadBalancers($mock);
$loadBalancers->listLoadBalancers('699d98642c564d2e855e9661899b7252');
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result[0]->id);
}
public function testGetLoadBalancerDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getLoadBalancerDetails.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
);
$loadBalancers = new LoadBalancers($mock);
$loadBalancers->getLoadBalancerDetails('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
}
public function testUpdateLoadBalancer()
{
$pools = [
'17b5962d775c646f3f9725cbc7a53df4',
'9290f38c5d07c2e2f4df57b1f61d4196',
'00920f38ce07c2e2f4df50b1f61d4194'
];
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLoadBalancer.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252'),
$this->equalTo($lbConfiguration->getArray())
);
$loadBalancers = new LoadBalancers($mock);
$result = $loadBalancers->updateLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252', $lbConfiguration);
$this->assertTrue($result);
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
}
public function testDeleteLoadBalancer()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLoadBalancer.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
);
$loadBalancers = new LoadBalancers($mock);
$result = $loadBalancers->deleteLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
$this->assertTrue($result);
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
}
}

View File

@@ -0,0 +1,93 @@
<?php
class MembershipTest extends TestCase
{
public function testListMemberships()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listMemberships.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('memberships'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'account.name' => 'Demo Account',
'status' => 'accepted',
'order' => 'status',
'direction' => 'desc',
])
);
$zones = new \Cloudflare\API\Endpoints\Membership($mock);
$result = $zones->listMemberships('Demo Account', 'accepted', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $zones->getBody()->result[0]->id);
}
public function testGetMembershipDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getMembershipDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
$details = $membership->getMembershipDetails('4536bcfad5faccb111b47003c79917fa');
$this->assertObjectHasAttribute('id', $details);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $details->id);
$this->assertObjectHasAttribute('code', $details);
$this->assertEquals('05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0', $details->code);
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
}
public function testUpdateMembershipDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateMembershipStatus.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'),
$this->equalTo([
'status' => 'accepted'
])
);
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
$membership->updateMembershipStatus('4536bcfad5faccb111b47003c79917fa', 'accepted');
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
}
public function testDeleteMembership()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteMembership.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with($this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'));
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
$membership->deleteMembership('4536bcfad5faccb111b47003c79917fa');
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
}
}

View File

@@ -6,54 +6,23 @@
* Time: 19:25
*/
use Cloudflare\API\Adapter\PageRules;
class PageRulesTest extends PHPUnit_Framework_TestCase
class PageRulesTest extends TestCase
{
public function testCreatePageRule()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}');
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
$action = new \Cloudflare\API\Configurations\PageRulesActions();
$action->setAlwaysOnline(true);
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
@@ -62,158 +31,70 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
}
public function testListPageRules()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPageRules.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules?status=active&order=status&direction=desc&match=all'), $this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([
'status' => 'active',
'order' => 'status',
'direction' => 'desc',
'match' => 'all'
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id);
}
public function testGetPageRuleDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPageRuleDetails.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
}
public function testUpdatePageRule()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}');
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
$action = new \Cloudflare\API\Configurations\PageRulesActions();
$action->setAlwaysOnline(true);
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
@@ -222,40 +103,30 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac', $target, $action, true, 1);
$this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
}
public function testDeletePageRule()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac"
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePageRule.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([]),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
}
}

View File

@@ -0,0 +1,133 @@
<?php
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\Pools;
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
class PoolsTest extends TestCase
{
public function testCreatePool()
{
$origins = [
[
'name' => 'app-server-1',
'address' => '0.0.0.0',
'enabled' => true,
'weight' => 0.56
]
];
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPool.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools'),
$poolConfiguration->getArray()
);
$pools = new Pools($mock);
$result = $pools->createPool('01a7362d577a6c3019a474fd6f485823', $poolConfiguration);
$this->assertTrue($result);
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
}
public function testListPools()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPools.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools')
);
$pools = new Pools($mock);
$pools->listPools('01a7362d577a6c3019a474fd6f485823');
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result[0]->id);
}
public function testGetPoolDetails()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPoolDetails.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
);
$pools = new Pools($mock);
$pools->getPoolDetails('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
}
public function testUpdatePool()
{
$origins = [
[
'name' => 'app-server-1',
'address' => '0.0.0.0',
'enabled' => true,
'weight' => 0.56
]
];
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePool.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4'),
$this->equalTo($poolConfiguration->getArray())
);
$pools = new Pools($mock);
$result = $pools->updatePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4', $poolConfiguration);
$this->assertTrue($result);
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
}
public function testDeletePool()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePool.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
);
$pools = new Pools($mock);
$result = $pools->deletePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
$this->assertTrue($result);
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
}
}

View File

@@ -0,0 +1,149 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 23/10/2017
* Time: 11:20
*/
class RailgunTest extends TestCase
{
public function testcreate()
{
$details = [
'name' => 'My Railgun',
];
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('railguns'),
$this->equalTo(['name' => $details['name']])
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->create($details['name']);
$this->assertObjectHasAttribute('result', $result);
foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $property }, $value);
}
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
}
public function testlist()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailguns.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('railguns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'direction' => 'desc'
])
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->list(1, 20, 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id);
}
public function testget()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRailgun.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->get('e928d310693a83094309acf9ead50448');
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
}
public function testgetZones()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailgunZones.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->getZones('e928d310693a83094309acf9ead50448');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id);
}
public function testupdate()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRailgun.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$details = [
'enabled' => true,
];
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
}
public function testdelete()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRailgun.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
);
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
$waf->delete('e928d310693a83094309acf9ead50448');
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
}
}

141
tests/Endpoints/SSLTest.php Normal file
View File

@@ -0,0 +1,141 @@
<?php
class SSLTest extends TestCase
{
public function testGetSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetSSLVerificationStatus()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertObjectHasAttribute('result', $result);
$this->assertEquals('active', $result->result{0}->certificate_status);
}
public function testGetHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testUpdateSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl'),
$this->equalTo(['value' => 'full'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
$this->assertTrue($result);
}
public function testUpdateHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https'),
$this->equalTo(['value' => 'off'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
public function testUpdateHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites'),
$this->equalTo(['value' => 'off'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
}

110
tests/Endpoints/TLSTest.php Normal file
View File

@@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: Jurgen Coetsiers
* Date: 21/10/2018
* Time: 09:09
*/
class TLSTest extends TestCase
{
public function testGetTLSClientAuth()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getTLSClientAuth.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth')
);
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $tlsMock->getTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testEnableTLS13()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/enableTLS13.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
$this->equalTo(['value' => 'on'])
);
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $tlsMock->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result);
}
public function testDisableTLS13()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/disableTLS13.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
$this->equalTo(['value' => 'off'])
);
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $tlsMock->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result);
}
public function testChangeMinimimTLSVersion()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeMinimumTLSVersion.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/min_tls_version'),
$this->equalTo(['value' => '1.1'])
);
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $tlsMock->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
$this->assertTrue($result);
}
public function testUpdateTLSClientAuth()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateTLSClientAuth.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth'),
$this->equalTo(['value' => 'off'])
);
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $tlsMock->updateTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
}

View File

@@ -6,57 +6,34 @@
* Time: 15:19
*/
use Cloudflare\API\Endpoints\UARules;
class UARulesTest extends PHPUnit_Framework_TestCase
class UARulesTest extends TestCase
{
public function testListRules()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRules.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules?page=1&per_page=20'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
])
);
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
}
public function testCreateRule()
@@ -64,32 +41,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
$config = new \Cloudflare\API\Configurations\UARules();
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -98,47 +58,35 @@ class UARulesTest extends PHPUnit_Framework_TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->createRule('023e105f4ecef8ad9ca31a8372d0c353', 'js_challenge', $config,
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->createRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'js_challenge',
$config,
'372e67954025e0ba6aaa6d586b9e0b59',
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack');
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
}
public function getRuleDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRuleDetails.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
);
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
}
public function testUpdateRule()
@@ -146,33 +94,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
$config = new \Cloudflare\API\Configurations\UARules();
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -181,38 +111,32 @@ class UARulesTest extends PHPUnit_Framework_TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->updateRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
'js_challenge', $config,
'Restrict access to these endpoints to requests from a known IP address');
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->updateRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
'js_challenge',
$config,
'Restrict access to these endpoints to requests from a known IP address'
);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
}
public function testDeleteRule()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
}
}

View File

@@ -5,132 +5,64 @@
* Date: 01/02/2017
* Time: 12:50
*/
class UserTest extends PHPUnit_Framework_TestCase
class UserTest extends TestCase
{
public function testGetUserDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$user = new \Cloudflare\API\Endpoints\User($mock);
$details = $user->getUserDetails();
$this->assertObjectHasAttribute("id", $details);
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id);
$this->assertObjectHasAttribute("email", $details);
$this->assertEquals("user@example.com", $details->email);
$this->assertObjectHasAttribute('id', $details);
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
$this->assertObjectHasAttribute('email', $details);
$this->assertEquals('user@example.com', $details->email);
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
}
public function testGetUserID()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$user = new \Cloudflare\API\Endpoints\User($mock);
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID());
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
}
public function testGetUserEmail()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())->method('get');
$user = new \Cloudflare\API\Endpoints\User($mock);
$this->assertEquals("user@example.com", $user->getUserEmail());
$this->assertEquals('user@example.com', $user->getUserEmail());
$this->assertEquals('user@example.com', $user->getBody()->result->email);
}
public function testUpdateUserDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"first_name": "John",
"last_name": "Appleseed",
"username": "cfuser12345",
"telephone": "+1 123-123-1234",
"country": "US",
"zipcode": "12345",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z",
"two_factor_authentication_enabled": false
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
$user = new \Cloudflare\API\Endpoints\User($mock);
$user->updateUserDetails(['email' => "user2@example.com"]);
$user->updateUserDetails(['email' => 'user2@example.com']);
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
}
}

221
tests/Endpoints/WAFTest.php Normal file
View File

@@ -0,0 +1,221 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 23/10/2017
* Time: 13:34
*/
class WAFTest extends TestCase
{
public function testgetPackages()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackages.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id);
}
public function testgetPackageInfo()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageInfo.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id);
}
public function testgetRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageRules.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id);
}
public function testgetRuleInfo()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageRuleInfo.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
}
public function testupdateRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$details = [
'mode' => 'on',
];
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on');
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value);
}
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
}
public function getGroups()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageGroups.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id);
}
public function testgetGroupInfo()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageGroupInfo.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
}
public function testupdateGroup()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageGroup.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$details = [
'mode' => 'off',
];
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off');
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value);
}
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
}
}

View File

@@ -6,55 +6,34 @@
* Date: 04/09/2017
* Time: 21:23
*/
class ZoneLockdownTest extends PHPUnit_Framework_TestCase
class ZoneLockdownTest extends TestCase
{
public function testListLockdowns()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLockdowns.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns?page=1&per_page=20'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
])
);
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
}
public function testAddLockdown()
@@ -62,85 +41,52 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addLockdown.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->createLockdown('023e105f4ecef8ad9ca31a8372d0c353', ["api.mysite.com/some/endpoint*"], $config,
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->createLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
['api.mysite.com/some/endpoint*'],
$config,
'372e67954025e0ba6aaa6d586b9e0b59',
'Restrict access to these endpoints to requests from a known IP address');
'Restrict access to these endpoints to requests from a known IP address'
);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
}
public function testGetRecordDetails()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordDetails.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
);
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
}
public function testUpdateLockdown()
@@ -148,49 +94,32 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLockdown.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->updateLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
["api.mysite.com/some/endpoint*"], $config,
'Restrict access to these endpoints to requests from a known IP address');
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->updateLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
['api.mysite.com/some/endpoint*'],
$config,
'Restrict access to these endpoints to requests from a known IP address'
);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
}
public function testDeleteLockdown()
@@ -198,31 +127,19 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$config = new \Cloudflare\API\Configurations\ZoneLockdown();
$config->addIP('1.2.3.4');
$stream = GuzzleHttp\Psr7\stream_for('
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLockdown.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
}
}

View File

@@ -6,314 +6,260 @@
* Date: 06/06/2017
* Time: 16:01
*/
class ZonesTest extends PHPUnit_Framework_TestCase
class ZonesTest extends TestCase
{
public function testAddZone()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
->with(
$this->equalTo('zones'),
$this->equalTo(['name' => 'example.com', 'jump_start' => false])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->addZone("example.com");
$result = $zones->addZone('example.com');
$this->assertObjectHasAttribute("id", $result);
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id);
$this->assertObjectHasAttribute('id', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->id);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$org = new stdClass();
$org->id = "01a7362d577a6c3019a474fd6f485823";
$mock->expects($this->once())
->method('post')
->with($this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org])
->with(
$this->equalTo('zones'),
$this->equalTo([
'name' => 'example.com',
'jump_start' => true,
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823");
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
}
public function testActivationTest()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$mock->expects($this->once())
->method('put')
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
$this->equalTo([]),
$this->equalTo([])
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check')
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testListZones()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listZones.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com&status=active&order=status&direction=desc'),
$this->equalTo([])
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc',
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
$result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
}
public function testGetZoneID()
public function testGetZoneByID()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneById.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com'),
$this->equalTo([])
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353'));
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneById('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertInstanceOf(\stdClass::class, $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
$this->assertEquals('example.com', $zones->getBody()->result->name);
}
public function testGetZoneID()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneId.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneID("example.com");
$result = $zones->getZoneID('example.com');
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
}
public function testGetAnalyticsDashboard()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getAnalyticsDashboard.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$analytics = $zones->getAnalyticsDashboard('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertObjectHasAttribute('since', $analytics->totals);
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
}
public function testChangeDevelopmentMode()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
$this->equalTo(['value' => 'on'])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result);
$this->assertEquals('development_mode', $zones->getBody()->result->id);
}
public function testCachePurgeEverything()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}');
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo([]),
$this->equalTo(["purge_everything" => true])
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['purge_everything' => true])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurgeHost()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(
[
'files' => [],
'tags' => [],
'hosts' => ['dash.cloudflare.com']
]
)
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
public function testCachePurge()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(['files' => [
'https://example.com/file.jpg',
]
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
'https://example.com/file.jpg',
]);
$this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Restrict access to these endpoints to requests from a known IP address",
"urls": [
"api.mysite.com/some/endpoint*"
],
"configurations": [
{
"target": "ip",
"value": "1.2.3.4"
}
]
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"type": "A",
"name": "example.com",
"content": "1.2.3.4",
"proxiable": true,
"proxied": false,
"ttl": 120,
"locked": false,
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
"zone_name": "example.com",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"data": {}
}
}

View File

@@ -0,0 +1,54 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
],
"owner": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"owner_type": "user"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full"
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,12 @@
{
"result": {
"id": "development_mode",
"value": "on",
"modified_on": "2017-11-06T05:16:42.864300Z",
"time_remaining": 10800,
"editable": true
},
"success": true,
"errors": [],
"messages": []
}

View File

@@ -0,0 +1,6 @@
{
"success": true,
"errors": [],
"messages": [],
"result": "1.1"
}

View File

@@ -0,0 +1,30 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
"notes": "This rule is on because of an event that occured on date X",
"allowed_modes": [
"whitelist",
"block",
"challenge"
],
"mode": "challenge",
"configuration": {
"target": "ip",
"value": "1.2.3.4"
},
"scope": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"type": "user"
},
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
"hostname": "app.example.com",
"ssl": {
"status": "pending_validation",
"method": "http",
"type": "dv",
"cname_target": "dcv.digicert.com",
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
}
}
}

View File

@@ -0,0 +1,46 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "699d98642c564d2e855e9661899b7252",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"description": "Load Balancer for www.example.com",
"name": "www.example.com",
"enabled": true,
"ttl": 30,
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"region_pools": {
"WNAM": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"ENAM": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"pop_pools": {
"LAX": [
"de90f38ced07c2e2f4df50b1f61d4194",
"9290f38c5d07c2e2f4df57b1f61d4196"
],
"LHR": [
"abd90f38ced07c2e2f4df50b1f61d4194",
"f9138c5d07c2e2f4df57b1f61d4196"
],
"SJC": [
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"proxied": true,
"steering_policy": "dynamic_latency",
"session_affinity": "cookie",
"session_affinity_ttl": 5000
}
}

View File

@@ -0,0 +1,31 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac",
"targets": [
{
"target": "url",
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
}
}
],
"actions": [
{
"id": "always_online",
"value": "on"
}
],
"priority": 1,
"status": "active",
"modified_on": "2014-01-01T05:20:00.12345Z",
"created_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,28 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "17b5962d775c646f3f9725cbc7a53df4",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"description": "Primary data center - Provider XYZ",
"name": "primary-dc-1",
"enabled": true,
"minimum_origins": 2,
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"check_regions": [
"WEU",
"ENAM"
],
"origins": [
{
"name": "app-server-1",
"address": "0.0.0.0",
"enabled": true,
"weight": 0.56
}
],
"notification_email": "someone@example.com"
}
}

View File

@@ -0,0 +1,23 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "e928d310693a83094309acf9ead50448",
"name": "My Railgun",
"status": "active",
"enabled": true,
"zones_connected": 2,
"build": "b1234",
"version": "2.1",
"revision": "123",
"activation_key": "e4edc00281cb56ebac22c81be9bac8f3",
"activated_on": "2014-01-02T02:20:00Z",
"created_on": "2014-01-01T05:20:00Z",
"modified_on": "2014-01-01T05:20:00Z"
}
}

View File

@@ -0,0 +1,18 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59",
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
"mode": "js_challenge",
"configuration": {
"target": "ua",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "92f17202ed8bd63d69a66b86a49a8f6b"
}
}

View File

@@ -0,0 +1,3 @@
{
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "699d98642c564d2e855e9661899b7252"
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "372e67954025e0ba6aaa6d586b9e0b59"
}
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "4536bcfad5faccb111b47003c79917fa"
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "9a7806061c88ada191ed06f989cc3dac"
}
}

Some files were not shown because too many files have changed in this diff Show More