228 Commits

Author SHA1 Message Date
Fabio Giacomoni
4df937f767 Modifiche ad aggiunta record DNS 2021-11-02 15:46:49 +01:00
Armando Caprio
30f7fc050e Implementata richiesta multipart 2021-07-09 10:28:38 +02:00
Armando Caprio
9f6be70d92 try minor guzzle version 2021-07-09 10:09:01 +02:00
Armando Caprio
250bf77605 Fix conflitti master 2021-07-09 10:04:19 +02:00
Jacob Bednarz
d97cf24ee2 Merge pull request #180 from phily245/179-missing-support-for-custom-hostname-update-properties
Missing Support For Custom Hostname Update Properties
2021-06-23 10:17:15 +10:00
Phil Young
ba875c32ca Update tests/Endpoints/CustomHostnamesTest.php 2021-06-22 16:21:55 +01:00
Phil Young
1b80a3bae7 Update tests/Endpoints/CustomHostnamesTest.php 2021-06-22 12:21:59 +01:00
Phil Young
f88a145785 Update tests/Endpoints/CustomHostnamesTest.php 2021-06-22 12:05:30 +01:00
Phil Young
e7cc9e067f Fix A PHP 7.0 Backwards Incompatibility
Too new, that was
2021-06-22 11:39:12 +01:00
Phil Young
fd55a526b3 Merge branch '179-missing-support-for-custom-hostname-update-properties' of github.com:phily245/cloudflare-php into 179-missing-support-for-custom-hostname-update-properties 2021-06-22 11:32:10 +01:00
Phil Young
bfb24200d5 Merge branch 'master' into 179-missing-support-for-custom-hostname-update-properties 2021-06-22 11:32:02 +01:00
Phil Young
3b167bab04 Add PHPMD Suppressions
I'm unsure as to how best to refactor this in the way that the SDK is
written. I'm going to commit this and ask on the PR how the maintainers
want it
2021-06-22 11:28:46 +01:00
Phil Young
c66022e7bf Add A Default Variable Value
This is always set now
2021-06-22 11:27:41 +01:00
Jacob Bednarz
a73da76e73 Merge pull request #178 from phily245/177-missing-support=for=custom-hostname-properties 2021-06-22 20:18:37 +10:00
Phil Young
aa43a1ea36 Move To Shorthand False Checks
This seems to be the preferred way to do them
2021-06-22 11:16:25 +01:00
Phil Young
63b11374f2 Move SSL Setting To An Array
This will match the add function and help with PHPMD errors
2021-06-22 11:13:53 +01:00
Phil Young
410b8bebff Merge remote-tracking branch 'origin' into 179-missing-support-for-custom-hostname-update-properties 2021-06-22 11:06:10 +01:00
Phil Young
60cdacdfcf Merge pull request #1 from cloudflare/master
Update My Fork
2021-06-22 11:05:57 +01:00
Phil Young
dfbc5a10d2 Revert "Revert "Move An LoC""
This reverts commit 969fc8cb59.
2021-06-22 11:01:09 +01:00
Phil Young
969fc8cb59 Revert "Move An LoC"
This reverts commit ed822d19ff.
2021-06-22 10:57:05 +01:00
Phil Young
a281dd11e7 Merge branch '177-missing-support=for=custom-hostname-properties' of github.com:phily245/cloudflare-php into 177-missing-support=for=custom-hostname-properties 2021-06-22 10:52:32 +01:00
Phil Young
ed822d19ff Move An LoC
I needed to trigger a github action after a network timeout
2021-06-22 10:51:41 +01:00
Phil Young
3e605dfa53 Merge branch 'master' into 177-missing-support=for=custom-hostname-properties 2021-06-22 10:44:00 +01:00
Phil Young
d9958973e0 Appease PHPMD
This was a good spot, as I can reuse this declaration in another PR
2021-06-22 10:42:20 +01:00
Phil Young
fd34eaf813 Move The Custom SSL To An Array
This kinda kicks the can down the road, but allows me to appease PHPMD
(for now)
2021-06-22 10:34:28 +01:00
Phil Young
be886c36cb Correct Some Bad Spacing
This was my bad
2021-06-22 10:07:14 +01:00
Phil Young
1a2d2ae708 Loosen Empty Check Strictness
This was asked for in a CR
2021-06-22 09:29:08 +01:00
Jacob Bednarz
2030e29593 Merge pull request #182 from phily245/181-add-support-for-custom-hostname-fallback-origin-retrieval
Add Custom Hostname Fallback Origin Retrieval
2021-06-21 09:55:44 +10:00
Phil Young
5394ec3cc8 Add Cuystom Hostname Fallback Origin Retrieval
I would like to surface this endpoint via the SDK
2021-06-15 13:55:41 +01:00
Phil Young
aea57e4994 Update A Docblock
I missed adding the new properties in earlier
2021-06-15 11:12:57 +01:00
Phil Young
f8124e76cb Shorten Longer Lines
The properties I've added have made these some pretty long lines
2021-06-15 11:12:37 +01:00
Phil Young
da3d10c4ee Add More Properties To Custom Hostname Updating
These are documented but not provided by the SDK
2021-06-15 11:10:23 +01:00
Phil Young
135b9a6813 Update A Docblock
PHPStorm pointed out that this was missing
2021-06-15 11:02:17 +01:00
Phil Young
f473e5f73c Correct A Request Parameter Namespace
This wasn't taking affect before as it wasn't in the object the API was
expecting it to be in
2021-06-15 10:52:44 +01:00
Phil Young
9955166ae8 Tidy Up Longer Method/Function Signatures/Calls
I've added a few new parameters which has made these lines rather long
2021-06-15 00:56:23 +01:00
Phil Young
c639f20cea Add More Custom Hostname Creation Parameters
This now matches what is available as per the documentation
2021-06-15 00:49:14 +01:00
Jacob Bednarz
1e58a65888 Merge pull request #164 from cloudflare/apalaistras/fix-request-error-handling
Adapter/Guzzle: Fix error handling for v4 API
2021-05-28 10:49:26 +10:00
Jacob Bednarz
658ab3fe47 Merge pull request #96 from rbayliss/remove_phars
Remove phar files
2021-05-28 10:37:53 +10:00
Jacob Bednarz
d2c4d225e0 suppress warnings on static access 2021-05-28 10:32:02 +10:00
Alex Palaistras
c58f340633 Adapter/Guzzle: Fix error handling for v4 API
This commit represents a partial overhaul of error handling for requests
made against the v4 Cloudflare API, with an aim of unifying disparate
kinds of exceptions under a single `ResponseException` type, and the
covering of additional cases where errors were unhandled. Specifically:

  - The `Guzzle::request()` function will now catch Guzzle exceptions
    normally thrown in cases of client and server errors (4xx and 5xx)
    response codes, and convert these to `ResponseException` types
    before re-throwing. These types of errors were previously not caught
    and were instead returned verbatim, expecting downstream clients to
    be aware of internal details of how these functions operate.

  - Conversely, we no longer assume that all responses are JSON-encoded,
    and no longer try to derive errors from non-4xx or 5xx responses.
    All public endpoints under the v4 API are expected to be
    well-behaved in that regard, and never return an error response
    where none is indicated in the HTTP code.

Code has been moved around and test-cases added in support of these
changes. In most cases, these changes won't break any existing
expectations and won't require any changes to downstream code, but users
of the Cloudflare SDK should ensure that they are indeed set up for
catching `ResponseException` instances thrown during requests, and
should not expect to see Guzzle exceptions directly (though these are
still available in calls to `ResponseException::getPrevious()`).

Fixes: #152
2021-05-28 10:23:50 +10:00
Jacob Bednarz
6fbf95f480 Merge pull request #176 from cloudflare/move-to-github-actions
move test and lint workflows to GitHub Actions
2021-05-28 10:22:57 +10:00
Jacob Bednarz
af14a5f003 move test and lint workflows to GitHub Actions 2021-05-28 10:21:16 +10:00
Keith Brink
7db3d6e62c Update to Guzzle 7 (#143) 2020-09-14 16:53:51 +01:00
Ha Phan
6d9b4ddffe [RFR]: Added Origin CA Certificate endpoint (#123)
* Added Certificate endpoint

* Implement all calls in /certificates endpoint

* Added to travis more php versions

* Fix package compatibility

* Added CertificateTest

* Added test for Certificate endpoint

* Added more tests

* Updated README

Co-authored-by: haphan <thanhha.phan@myrepublic.net>
2020-07-07 11:19:15 +01:00
bnalonezi
fab493d2d3 Add Browser Cache TTL endpoint (#127)
Co-authored-by: bnalonezi <b.alenezi@zid.sa>
2020-07-07 11:18:40 +01:00
kamilsolarczyk
afd332a747 Maximum value of Edge Cache TTL (#125)
It is possible to choose a month value, so the value parameter can be greater
2020-07-07 11:18:10 +01:00
Constantin Cuciurcă
ffc3989607 Dns analytics report (#121)
* Add DNS Analytics report endpoint


Add DNS Analytics report endpoint


Add DNS Analytics report endpoint

* Remove useless response error test

* Add tests for DNS analytics report class methods

* Implement methods for listing grouped by time metrics report
2020-07-07 11:17:48 +01:00
bubbleupdotnet
06de5b0c04 Add custom hostname options (#131)
* Add ability to set additional SSL settings

* Add ability to specify a custom origin server

* Add ability to set wildcard

* Fix json parsing error with empty 'ssl' key

Co-authored-by: Craig Menning <craig@bubbleup.net>
2020-07-07 11:16:24 +01:00
Junade
8879ba4c0a Merge pull request #135 from pjjonesnz/pjjonesnz-fix-mx-priority-0
Fix for MX with priority 0
2020-07-07 11:15:18 +01:00
Junade
d1b6dd577f Merge pull request #138 from NathanStrobbe/fix/purge_cache
Fix purge cache
2020-07-07 11:14:43 +01:00
Nathan S
c575b3bc9b Replace DELETE method by POST according to the Cloudflare [documentation](https://api.cloudflare.com/#zone-purge-all-files) 2020-06-21 14:52:11 +02:00
Paul Jones
251ab5247d Fix for MX with priority 0
Author:    Paul Jones <info@beyondthebox.co.nz>
Date:      Sun Jun 21 07:42:38 2020 +0000
2020-06-21 07:47:06 +00:00
SVDIGITAL
eaa390497e Correction on README 2020-06-19 14:31:09 +02:00
Tobia Zanarella
59e8506a45 Edited README 2020-06-19 14:30:07 +02:00
Tobia Zanarella
66a2c6ebd7 Merge remote-tracking branch 'upstream/master' 2020-06-19 14:20:19 +02:00
SVDIGITAL
544ef73299 Update composer.json - new repository name, organization renaming 2020-06-19 12:07:04 +02:00
Junade
694342f718 Merge pull request #98 from llbbl/firewall-rules
Adding new Firewall rules Class
2020-02-03 17:23:45 +00:00
Junade
ca426abc32 Merge pull request #101 from ProfiCloS/feature/api-token
feature/api-token
2020-02-03 17:22:40 +00:00
Junade
2a83d24954 Merge pull request #102 from umbrellio/add_endpoints_zones_settings
add endpoint for server-side exclude setting
2020-02-03 17:22:17 +00:00
Junade
445bc30be7 Merge pull request #114 from Pezhvak/patch-1
Fixing fatal error in PHP 7.4
2020-02-03 17:21:31 +00:00
Junade
2dc59ddcca Merge pull request #115 from kanasite/master
Add Domain Registrar and pause zone
2020-02-03 17:21:12 +00:00
Junade
54545a371e Merge pull request #118 from axelabhay/cf-new-page-rules-action
Adding new function setOriginCacheControl as a new page rule action.
2020-02-03 17:19:48 +00:00
Junade
27ae3718d4 Merge pull request #119 from axelabhay/cf-new-edit-page-rule-function
New function editPageRule to allow PUT method supporting removal of rule action items
2020-02-03 17:19:24 +00:00
Abhay Saraf
f2e0d6cbe3 Adding new function editPageRule to allow put method to support removal of rule settings or rule action items from the page rule which is not supported by updatePageRule. 2020-01-28 15:26:35 +05:30
Abhay Saraf
ed91e639be Adding new function setOriginCacheControl as a new page rule action. 2020-01-28 11:11:05 +05:30
Pezhvak
adfb6d28d2 Update SSLTest.php
fixed curly braces in this file as @aaronhuisinga reported
2019-12-20 17:12:58 +03:30
Kyle Yee
9d0df44838 remove test 2019-12-16 18:02:49 +08:00
Kyle Yee
6e6a850d62 fix test case 2019-12-16 17:58:04 +08:00
Kyle Yee
b9051fc1f2 fix lint 2019-12-16 17:55:48 +08:00
Kyle Yee
b54c3481a3 fix typo in test case 2019-12-16 17:39:38 +08:00
Kyle Yee
8310111b11 Merge branch 'master' into master 2019-12-16 17:32:56 +08:00
Kyle Yee
f0892ac64f fix return type 2019-12-14 15:40:29 +08:00
Kyle Yee
d918f7b99e fix typo 2019-12-14 15:36:38 +08:00
Kyle Yee
f4c2f546b0 Feature: add lock and unlock domain 2019-12-14 15:24:43 +08:00
Pezhvak
1be0e794d9 Update DNS.php
fixing php 7.4 deprecation of curly braces
2019-12-03 17:29:32 +03:30
ArmandoCaprio
9b9984d5fd Fix tipo di ritorno 2019-10-23 12:31:12 +02:00
ArmandoCaprio
c0198f352a Aggiornato composer dopo il fork 2019-10-23 12:26:44 +02:00
ArmandoCaprio
39ec310026 Modifica creazione record: ritorno del oggetto record 2019-10-23 12:07:59 +02:00
Junade
7276b61e20 Merge pull request #106 from beltofte/ssl-status-retry-option
Add retry option to getSSLVerificationStatus()
2019-09-20 02:45:40 +01:00
Junade
4e1a12bdea Merge pull request #107 from beltofte/ssl-change-verify-method
Add method to change SSL certificate pack validation method
2019-09-20 02:45:08 +01:00
Junade
61e80bd25f Merge pull request #99 from benedict-erwin/master
Add Method Delete Zone
2019-09-20 02:44:22 +01:00
Junade
ffefe1480a Merge pull request #109 from indeed-a-genius/patch-1
Incorrect listPageRules() conditions for optional parameters
2019-09-20 02:43:43 +01:00
Junade
f7d9f511ab Merge pull request #110 from a1comms/master
Fix PageRulesActions: setResolveOverride,setHostHeaderOverride
2019-09-20 02:43:19 +01:00
Samuel Melrose
639be12f7a Fix PageRulesActions: setResolveOverride,setHostHeaderOverride 2019-09-18 14:38:32 +00:00
indeed-a-genius
2ba05a3ba5 Incorrect listPageRules() conditions for optional parameters 2019-09-17 14:29:22 +02:00
Jens Beltofte
1211b644e0 Change validation method to txt as in the CF API documentation + change response json file 2019-09-12 15:10:22 +02:00
Jens Beltofte
58ba140930 Add method to change SSL certificate pack validation method 2019-09-12 14:50:24 +02:00
Benedict E. Pranata
56b760bb06 Remove new line
line 265
2019-09-12 14:39:52 +07:00
Benedict E. Pranata
469d66e92a Remove trailing space
line 18
2019-09-12 14:38:58 +07:00
Benedict E. Pranata
171c6689af Remove trailing space
line 20
2019-09-12 14:38:28 +07:00
Benedict E. Pranata
fd17c57b62 Remove tab character
Line 249
2019-09-12 14:36:55 +07:00
Jens Beltofte
647705b852 Adding comment to suppress boolean argument warning 2019-09-09 21:13:04 +02:00
Jens Beltofte
28e1378506 Add retry option to getSSLVerificationStatus() 2019-09-09 20:56:06 +02:00
dave
39b2f2fd2a add endpoint for server-side exclude setting 2019-08-12 15:02:10 +03:00
dave
c49409b978 add endpoint for server-side exclude setting 2019-08-12 15:00:34 +03:00
dave
d895b50e47 add endpoint for server-side exclude setting 2019-08-12 14:25:33 +03:00
Martin Pecha
efae17f29d add api token support 2019-07-30 23:26:16 +02:00
martin
ecbe2fe552 fix codestyle 2019-07-30 23:19:31 +02:00
Martin Pecha
6a80cb69e2 add api token support 2019-07-30 23:06:59 +02:00
Benedict E. Pranata
8e279f2217 Update ZoneDeleteTest.php 2019-07-24 09:27:07 +07:00
Benedict E. Pranata
274517553c Create ZoneDeleteTest.php 2019-07-24 09:22:27 +07:00
Benedict E. Pranata
4cb9eb228e Rollback ZonesTest.php 2019-07-24 09:21:06 +07:00
Benedict E. Pranata
c525cef45c Refactor ZonesTest
Refactoring ZonesTest to keep number of public methods under 10
2019-07-24 09:12:59 +07:00
Benedict E. Pranata
818e6e4505 Update method testDeleteTest 2019-07-23 15:07:58 +07:00
Benedict E. Pranata
440492e41c Rename deleteTest.json to deleteZoneTest.json 2019-07-23 15:07:16 +07:00
Benedict E. Pranata
cb24d2c77f Add deleteZone test 2019-07-23 13:42:06 +07:00
Benedict E. Pranata
9561740484 Create deleteTest.json
For testing deleteZone method
2019-07-23 13:39:40 +07:00
Benedict E. Pranata
1e2b630964 Add Delete Zone Method 2019-07-23 13:34:58 +07:00
Vitaliy Dotsenko
8364249fbb Added unit tests to check Firewall rules 2019-07-08 21:20:48 +03:00
Vitaliy Dotsenko
22a87e1b91 Moved the action type and paused or not from the signature to the separate class 2019-07-08 21:20:32 +03:00
Vitaliy Dotsenko
68d862f7da Changed return value of the "createFirewallRules" method 2019-07-08 21:16:05 +03:00
Vitaliy Dotsenko
66ec1b318f Changed return value of the "listFirewallRules" method 2019-07-08 14:09:42 +03:00
Vitaliy Dotsenko
29ab101130 Fixed enable the firewall rule by default 2019-06-27 18:26:23 +03:00
Vitaliy Dotsenko
48404cd0ac Added update to Firewall rules 2019-06-27 18:20:34 +03:00
Vitaliy Dotsenko
c5b6bceecb Fixed passing the description and priority of the createFirewallRule method 2019-06-27 18:19:24 +03:00
Vitaliy Dotsenko
89986cfb02 Added Firewall rules endpoints 2019-06-25 11:54:56 +03:00
Rob Bayliss
b7dfc9e0f1 Remove phar files 2019-06-17 16:14:19 -04:00
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
Kyle Yee
b04abe73bc Feature: add pause 2019-06-06 15:00:57 +08: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
Kyle Yee
44eb77f9ca cast response as array instead of object 2019-01-28 11:39:49 +08:00
Kyle Yee
fb45932677 cast result as object 2019-01-28 11:35:58 +08:00
Kyle Yee
dde2de4495 Feature: add accounts end point, add get domains 2019-01-28 11:24:45 +08: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
145 changed files with 9460 additions and 511 deletions

40
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Lint
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
uses: php-actions/composer@v5
with:
command: install
args: --prefer-dist --no-progress --no-suggest --verbose
php_version: ${{ matrix.php-versions }}
version: 1
- name: Run lint
run: make lint

40
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Test
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
uses: php-actions/composer@v5
with:
command: install
args: --prefer-dist --no-progress --no-suggest --verbose
php_version: ${{ matrix.php-versions }}
version: 1
- name: Run tests
run: make test

4
.gitignore vendored Normal file → Executable file
View File

@@ -1 +1,3 @@
/vendor/ /.idea
/vendor/
/nbproject/

View File

@@ -1,15 +0,0 @@
language: php
php:
- 7.0
- 7.1
before_install:
- composer self-update
install:
- travis_retry composer install --no-interaction --prefer-source
script:
- make lint
- make test

View File

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

75
README.md Normal file → Executable file
View File

@@ -2,45 +2,48 @@
[![Build Status](https://travis-ci.org/cloudflare/cloudflare-php.svg?branch=master)](https://travis-ci.org/cloudflare/cloudflare-php) [![Build Status](https://travis-ci.org/cloudflare/cloudflare-php.svg?branch=master)](https://travis-ci.org/cloudflare/cloudflare-php)
## Installation See: [cloudflare/cloudflare-php](https://github.com/cloudflare/cloudflare-php)
The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191) # Cloudflare SDK: added by Shellrent
## Cloudflare API version 4 - DNS Record is returned on creation:
The Cloudflare API can be found [here](https://api.cloudflare.com/). `Class: Cloudflare\API\Endpoints\DNS`
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-)
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [ ] Virtual DNS Management
- [ ] Custom hostnames
- [x] Zone Lockdown and User-Agent Block rules
- [ ] Organization 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/)
Note that this repository is currently under development, additional classes and endpoints being actively added.
## Getting Started
```php ```php
$key = new Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey'); public function addRecord(
$adapter = new Cloudflare\API\Adapter\Guzzle($key); string $zoneID,
$user = new Cloudflare\API\Endpoints\User($adapter); string $type,
string $name,
echo $user->getUserID(); string $content,
int $ttl = 0,
bool $proxied = true,
string $priority = '',
array $data = []
): \stdClass {
$options = [
'type' => $type,
'name' => $name,
'content' => $content,
'proxied' => $proxied
];
if ($ttl > 0) {
$options['ttl'] = $ttl;
}
if (!empty($priority)) {
$options['priority'] = (int)$priority;
}
if (!empty($data)) {
$options['data'] = $data;
}
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
``` ```
## 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

@@ -1,14 +1,15 @@
{ {
"name": "cloudflare/sdk", "name": "shellrent/cloudflare-php",
"description": "PHP binding for v4 of the Cloudflare Client API.", "description": "PHP binding for v4 of the Cloudflare Client API.",
"type": "library", "type": "library",
"require": { "require": {
"guzzlehttp/guzzle": "^6.2.2", "guzzlehttp/guzzle": "~6.0",
"php": ">=7.0.0", "php": ">=7.2.5",
"psr/http-message": "~1.0" "psr/http-message": "~1.0",
"ext-json": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "5.7.5", "phpunit/phpunit": "^5.7",
"phpmd/phpmd" : "@stable", "phpmd/phpmd" : "@stable",
"friendsofphp/php-cs-fixer": "^2.6" "friendsofphp/php-cs-fixer": "^2.6"
}, },
@@ -28,5 +29,10 @@
"classmap": [ "classmap": [
"tests/" "tests/"
] ]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
} }
} }

3060
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -31,46 +31,46 @@ interface Adapter
* RFCs, it is never useful). * RFCs, it is never useful).
* *
* @param string $uri * @param string $uri
* @param array $query * @param array $data
* @param array $headers * @param array $headers
* *
* @return mixed * @return mixed
*/ */
public function get(string $uri, array $query, array $headers): ResponseInterface; public function get(string $uri, array $data = [], array $headers = []): ResponseInterface;
/** /**
* @param string $uri * @param string $uri
* @param array $data
* @param array $headers * @param array $headers
* @param array $body
* *
* @return mixed * @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 $headers
* @param array $body
* *
* @return mixed * @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 $headers
* @param array $body
* *
* @return mixed * @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 $headers
* @param array $body
* *
* @return mixed * @return mixed
*/ */
public function delete(string $uri, array $headers, array $body): ResponseInterface; public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
} }

View File

@@ -1,14 +1,10 @@
<?php <?php
/**
* User: junade
* Date: 13/01/2017
* Time: 18:26
*/
namespace Cloudflare\API\Adapter; namespace Cloudflare\API\Adapter;
use Cloudflare\API\Auth\Auth; use Cloudflare\API\Auth\Auth;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
class Guzzle implements Adapter class Guzzle implements Adapter
@@ -37,96 +33,89 @@ class Guzzle implements Adapter
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function get(string $uri, array $query = [], array $headers = []): ResponseInterface public function get(string $uri, array $data = [], array $headers = []): ResponseInterface
{ {
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]); return $this->request('get', $uri, $data, $headers);
$this->checkError($response);
return $response;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function post(string $uri, array $headers = [], array $body = []): ResponseInterface public function post(string $uri, array $data = [], array $headers = []): ResponseInterface
{ {
$response = $this->client->post( return $this->request('post', $uri, $data, $headers);
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function put(string $uri, array $headers = [], array $body = []): ResponseInterface public function put(string $uri, array $data = [], array $headers = []): ResponseInterface
{ {
$response = $this->client->put( return $this->request('put', $uri, $data, $headers);
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function patch(string $uri, array $headers = [], array $body = []): ResponseInterface public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface
{ {
$response = $this->client->patch( return $this->request('patch', $uri, $data, $headers);
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function delete(string $uri, array $headers = [], array $body = []): ResponseInterface public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface
{ {
$response = $this->client->delete( return $this->request('delete', $uri, $data, $headers);
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
} }
private function checkError(ResponseInterface $response) /**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function request(string $method, string $uri, array $data = [], array $headers = [])
{ {
$json = json_decode($response->getBody()); if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
if (json_last_error() !== JSON_ERROR_NONE) {
throw new JSONException();
} }
if (isset($json->errors) && count($json->errors) >= 1) { try {
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code); $response = $this->client->$method($uri, [
'headers' => $headers,
($method === 'get' ? 'query' : 'json') => $data,
]);
} catch (RequestException $err) {
throw ResponseException::fromRequestException($err);
} }
if (isset($json->success) && !$json->success) { return $response;
throw new ResponseException('Request was unsuccessful.'); }
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function requestMultiPart(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');
} }
$multipart = [];
foreach( $data as $key => $value ) {
$multipart[] = [
'name' => $key,
'contents' => $value
];
}
try {
$response = $this->client->$method($uri, [
'headers' => $headers,
'multipart' => $multipart
]);
} catch (RequestException $err) {
throw ResponseException::fromRequestException($err);
}
return $response;
} }
} }

View File

@@ -8,6 +8,37 @@
namespace Cloudflare\API\Adapter; namespace Cloudflare\API\Adapter;
use GuzzleHttp\Exception\RequestException;
class ResponseException extends \Exception class ResponseException extends \Exception
{ {
/**
* Generates a ResponseException from a Guzzle RequestException.
*
* @param RequestException $err The client request exception (typicall 4xx or 5xx response).
* @return ResponseException
*/
public static function fromRequestException(RequestException $err): self
{
if (!$err->hasResponse()) {
return new ResponseException($err->getMessage(), 0, $err);
}
$response = $err->getResponse();
$contentType = $response->getHeaderLine('Content-Type');
// Attempt to derive detailed error from standard JSON response.
if (strpos($contentType, 'application/json') !== false) {
$json = json_decode($response->getBody());
if (json_last_error() !== JSON_ERROR_NONE) {
return new ResponseException($err->getMessage(), 0, new JSONException(json_last_error_msg(), 0, $err));
}
if (isset($json->errors) && count($json->errors) >= 1) {
return new ResponseException($json->errors[0]->message, $json->errors[0]->code, $err);
}
}
return new ResponseException($err->getMessage(), 0, $err);
}
} }

25
src/Auth/APIToken.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/**
* User: czPechy
* Date: 30/07/2018
* Time: 22:42
*/
namespace Cloudflare\API\Auth;
class APIToken implements Auth
{
private $apiToken;
public function __construct(string $apiToken)
{
$this->apiToken = $apiToken;
}
public function getHeaders(): array
{
return [
'Authorization' => 'Bearer ' . $this->apiToken
];
}
}

View File

@@ -21,6 +21,11 @@ class AccessRules implements Configurations
$this->config = ['target' => 'country', 'value' => $value]; $this->config = ['target' => 'country', 'value' => $value];
} }
public function setASN(string $value)
{
$this->config = ['target' => 'asn', 'value' => $value];
}
public function getArray(): array public function getArray(): array
{ {
return $this->config; return $this->config;

View File

@@ -0,0 +1,58 @@
<?php
namespace Cloudflare\API\Configurations;
class Certificate implements Configurations
{
const ORIGIN_RSA = 'origin-rsa';
const ORIGIN_ECC = 'origin-ecc';
const KEYLESS_CERTIFICATE = 'keyless-certificate';
private $config = [];
public function getArray(): array
{
return $this->config;
}
/**
* Array of hostnames or wildcard names (e.g., *.example.com) bound to the certificate
* Example: $hostnames = ["example.com", "foo.example.com"]
* @param array $hostnames
*/
public function setHostnames(array $hostnames)
{
$this->config['hostnames'] = $hostnames;
}
/**
* The number of days for which the certificate should be valid
* Default value: 5475
* Valid values: 7, 30, 90, 365, 730, 1095, 5475
* @param int $validity
*/
public function setRequestedValidity(int $validity)
{
$this->config['requested_validity'] = $validity;
}
/**
* Signature type desired on certificate ("origin-rsa" (rsa), "origin-ecc" (ecdsa), or "keyless-certificate" (for Keyless SSL servers)
* Valid values: origin-rsa, origin-ecc, keyless-certificate
* @param string $type
*/
public function setRequestType(string $type)
{
$this->config['request_type'] = $type;
}
/**
* The Certificate Signing Request (CSR). Must be newline-encoded.
*
* @param string $csr
*/
public function setCsr(string $csr)
{
$this->config['csr'] = $csr;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Cloudflare\API\Configurations;
class DNSAnalytics implements Configurations
{
protected $configs = [];
public function getArray(): array
{
return $this->configs;
}
public function setDimensions(array $dimensions)
{
if (count($dimensions) !== 0) {
$this->configs['dimensions'] = implode(',', $dimensions);
}
}
public function setMetrics(array $metrics)
{
if (count($metrics) !== 0) {
$this->configs['metrics'] = implode(',', $metrics);
}
}
public function setSince(string $since)
{
if ($since) {
$this->configs['since'] = $since;
}
}
public function setUntil(string $until)
{
if ($until) {
$this->configs['until'] = $until;
}
}
public function setSorting(array $sorting)
{
if (count($sorting) !== 0) {
$this->configs['sort'] = implode(',', $sorting);
}
}
public function setFilters(string $filters)
{
if ($filters) {
$this->configs['filters'] = $filters;
}
}
public function setLimit(int $limit)
{
if ($limit) {
$this->configs['limit'] = $limit;
}
}
public function setTimeDelta(string $timeDelta)
{
if ($timeDelta) {
$this->configs['time_delta'] = $timeDelta;
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Cloudflare\API\Configurations;
class FirewallRuleOptions implements Configurations
{
protected $configs = [
'paused' => false,
'action' => 'block'
];
public function getArray(): array
{
return $this->configs;
}
public function setPaused(bool $paused)
{
$this->configs['paused'] = $paused;
}
public function setActionBlock()
{
$this->configs['action'] = 'block';
}
public function setActionAllow()
{
$this->configs['action'] = 'allow';
}
public function setActionChallenge()
{
$this->configs['action'] = 'challenge';
}
public function setActionJsChallenge()
{
$this->configs['action'] = 'js_challenge';
}
public function setActionLog()
{
$this->configs['action'] = 'log';
}
}

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;
}
}

27
src/Configurations/PageRulesActions.php Normal file → Executable file
View File

@@ -33,6 +33,13 @@ class PageRulesActions implements Configurations
]); ]);
} }
public function setOriginCacheControl(bool $active)
{
$this->addConfigurationOption('explicit_cache_control', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBrowserIntegrityCheck(bool $active) public function setBrowserIntegrityCheck(bool $active)
{ {
$this->addConfigurationOption('browser_check', [ $this->addConfigurationOption('browser_check', [
@@ -110,7 +117,7 @@ class PageRulesActions implements Configurations
public function setEdgeCacheTTL(int $value) public function setEdgeCacheTTL(int $value)
{ {
if ($value > 2419200) { if ($value > 2678400) {
throw new ConfigurationsException('Edge Cache TTL too high.'); throw new ConfigurationsException('Edge Cache TTL too high.');
} }
@@ -132,16 +139,18 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException('Status Codes can only be 301 or 302.'); throw new ConfigurationsException('Status Codes can only be 301 or 302.');
} }
$this->addConfigurationOption('forwarding_url', [ $this->addConfigurationOption("forwarding_url", [
'status_code' => $statusCode, 'value' => [
'url' => $forwardingUrl, 'status_code' => $statusCode,
'url' => $forwardingUrl,
],
]); ]);
} }
public function setHostHeaderOverride(bool $active) public function setHostHeaderOverride(string $value)
{ {
$this->addConfigurationOption('host_header_override', [ $this->addConfigurationOption('host_header_override', [
'value' => $this->getBoolAsOnOrOff($active) 'value' => $value
]); ]);
} }
@@ -196,7 +205,7 @@ class PageRulesActions implements Configurations
]); ]);
} }
public function setResolveOverride(bool $value) public function setResolveOverride(string $value)
{ {
$this->addConfigurationOption('resolve_override', [ $this->addConfigurationOption('resolve_override', [
'value' => $value 'value' => $value
@@ -259,7 +268,7 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.'); throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
} }
$this->addConfigurationOption('smart_errors', [ $this->addConfigurationOption('ssl', [
'value' => $value 'value' => $value
]); ]);
} }
@@ -301,7 +310,7 @@ class PageRulesActions implements Configurations
{ {
$configuration['id'] = $setting; $configuration['id'] = $setting;
$this->configs[] = (object) $configuration; array_push($this->configs, $configuration);
} }
private function getBoolAsOnOrOff(bool $value): string private function getBoolAsOnOrOff(bool $value): string

View File

@@ -15,9 +15,9 @@ class PageRulesTargets implements Configurations
public function __construct(string $queryUrl) public function __construct(string $queryUrl)
{ {
$this->targets = [ $this->targets = [
(object)[ [
'target' => 'url', 'target' => 'url',
'constraint' => (object)[ 'constraint' => [
'operator' => 'matches', 'operator' => 'matches',
'value' => $queryUrl 'value' => $queryUrl
] ]

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

@@ -14,7 +14,7 @@ class UARules implements Configurations
public function addUA(string $value) public function addUA(string $value)
{ {
$this->configs[] = (object)['target' => 'ua', 'value' => $value]; $this->configs[] = ['target' => 'ua', 'value' => $value];
} }
public function getArray(): array public function getArray(): array

View File

@@ -14,12 +14,12 @@ class ZoneLockdown implements Configurations
public function addIP(string $value) public function addIP(string $value)
{ {
$this->configs[] = (object)['target' => 'ip', 'value' => $value]; $this->configs[] = ['target' => 'ip', 'value' => $value];
} }
public function addIPRange(string $value) public function addIPRange(string $value)
{ {
$this->configs[] = (object)['target' => 'ip_range', 'value' => $value]; $this->configs[] = ['target' => 'ip_range', 'value' => $value];
} }
public function getArray(): array public function getArray(): array

View File

@@ -4,9 +4,12 @@ namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\Configurations; use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Traits\BodyAccessorTrait;
class AccessRules implements API class AccessRules implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -77,10 +80,10 @@ class AccessRules implements API
$query['notes'] = $notes; $query['notes'] = $notes;
} }
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query, []); $data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
$body = json_decode($data->getBody()); $this->body = json_decode($data->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function createRule( public function createRule(
@@ -91,18 +94,18 @@ class AccessRules implements API
): bool { ): bool {
$options = [ $options = [
'mode' => $mode, 'mode' => $mode,
'configuration' => (object) $configuration->getArray() 'configuration' => $configuration->getArray()
]; ];
if ($notes !== null) { if ($notes !== null) {
$options['notes'] = $notes; $options['notes'] = $notes;
} }
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', [], $options); $query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $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; return true;
} }
@@ -123,11 +126,11 @@ class AccessRules implements API
$options['notes'] = $notes; $options['notes'] = $notes;
} }
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options); $query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $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; return true;
} }
@@ -140,11 +143,11 @@ class AccessRules implements API
'cascade' => $cascade 'cascade' => $cascade
]; ];
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options); $data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
$body = json_decode($data->getBody()); $this->body = json_decode($data->getBody());
if (isset($body->result->id)) { if (isset($this->body->result->id)) {
return true; return true;
} }

View File

@@ -0,0 +1,75 @@
<?php
/**
* User: kanasite
* Date: 01/28/2019
* Time: 10:00
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Accounts implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listAccounts(
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('accounts', $query);
$this->body = json_decode($user->getBody());
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}
public function getDomains(string $accountID): array
{
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains');
$this->body = json_decode($response->getBody());
return $this->body->result;
}
public function getDomainDetails(string $accountID, string $domainName): \stdClass
{
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains/' . $domainName);
$this->body = json_decode($response->getBody());
return $this->body->result;
}
public function lockDomain(string $accountID, string $domainName): \stdClass
{
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => true]);
$this->body = json_decode($response->getBody());
return $this->body;
}
public function unlockDomain(string $accountID, string $domainName): \stdClass
{
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => false]);
$this->body = json_decode($response->getBody());
return $this->body;
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\Certificate as CertificateConfig;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Certificates implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* List all existing Origin CA certificates for a given zone
*
* @param string $zoneID
* @return array
*/
public function listCertificates(string $zoneID): \stdClass
{
$certificates = $this->adapter->get('certificates', ['zone_id' => $zoneID]);
$this->body = json_decode($certificates->getBody());
return (object)['result' => $this->body->result];
}
/**
* Get an existing Origin CA certificate by its serial number
*
* @param string $certificateID
* @param string $zoneID
* @return mixed
*/
public function getCertificate(string $certificateID, string $zoneID)
{
$certificates = $this->adapter->get('certificates/'.$certificateID, ['zone_id' => $zoneID]);
$this->body = json_decode($certificates->getBody());
return (object)['result' => $this->body->result];
}
/**
* Revoke an existing Origin CA certificate by its serial number
*
* @param string $certificateID
* @param string $zoneID
* @return bool
*/
public function revokeCertificate(string $certificateID, string $zoneID): bool
{
$certificates = $this->adapter->delete('certificates/'.$certificateID, ['zone_id' => $zoneID]);
$this->body = json_decode($certificates->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* Create an Origin CA certificate
*
* @param CertificateConfig $config
* @return bool
*/
public function createCertificate(CertificateConfig $config): bool
{
$certificate = $this->adapter->post('certificates', $config->getArray());
$this->body = json_decode($certificate->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,240 @@
<?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
* @param array $sslSettings
* @param string $customOriginServer
* @param bool $wildcard
* @param string $bundleMethod
* @param array $customSsl
* @return \stdClass
*/
public function addHostname(
string $zoneID,
string $hostname,
string $sslMethod = 'http',
string $sslType = 'dv',
array $sslSettings = [],
string $customOriginServer = '',
bool $wildcard = false,
string $bundleMethod = '',
array $customSsl = []
): \stdClass {
$options = [
'hostname' => $hostname,
'ssl' => [
'method' => $sslMethod,
'type' => $sslType,
'settings' => $sslSettings,
'wildcard' => $wildcard,
],
];
if (!empty($customOriginServer)) {
$options['custom_origin_server'] = $customOriginServer;
}
if (!empty($bundleMethod)) {
$options['ssl']['bundle_method'] = $bundleMethod;
}
if (!empty($customSsl['key'])) {
$options['ssl']['custom_key'] = $customSsl['key'];
}
if (!empty($customSsl['certificate'])) {
$options['ssl']['custom_certificate'] = $customSsl['certificate'];
}
$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)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @param string $zoneID
* @param string $hostnameID
* @param string $sslMethod
* @param string $sslType
* @param array $sslSettings
* @param string $customOriginServer
* @param bool|null $wildcard
* @param string $bundleMethod
* @param array $customSsl
* @return \stdClass
*/
public function updateHostname(
string $zoneID,
string $hostnameID,
string $sslMethod = '',
string $sslType = '',
array $sslSettings = [],
string $customOriginServer = '',
bool $wildcard = null,
string $bundleMethod = '',
array $customSsl = []
): \stdClass {
$query = [];
$options = [];
if (!empty($sslMethod)) {
$query['method'] = $sslMethod;
}
if (!empty($sslType)) {
$query['type'] = $sslType;
}
if (!empty($sslSettings)) {
$query['settings'] = $sslSettings;
}
if (!is_null($wildcard)) {
$query['wildcard'] = $wildcard;
}
if (!empty($bundleMethod)) {
$query['bundle_method'] = $bundleMethod;
}
if (!empty($customSsl['key'])) {
$query['custom_key'] = $customSsl['key'];
}
if (!empty($customSsl['certificate'])) {
$query['custom_certificate'] = $customSsl['certificate'];
}
if (!empty($query)) {
$options = [
'ssl' => $query
];
}
if (!empty($customOriginServer)) {
$options['custom_origin_server'] = $customOriginServer;
}
$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;
}
/**
* @param string $zoneID
* @return \stdClass
*/
public function getFallbackOrigin(string $zoneID): \stdClass
{
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/fallback_origin');
$this->body = json_decode($zone->getBody());
return $this->body->result;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class DNS implements API class DNS implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -28,7 +31,9 @@ class DNS implements API
* @param string $content * @param string $content
* @param int $ttl * @param int $ttl
* @param bool $proxied * @param bool $proxied
* @return bool * @param string $priority
* @param array $data
* @return \stdClass
*/ */
public function addRecord( public function addRecord(
string $zoneID, string $zoneID,
@@ -36,8 +41,10 @@ class DNS implements API
string $name, string $name,
string $content, string $content,
int $ttl = 0, int $ttl = 0,
bool $proxied = true bool $proxied = true,
): bool { string $priority = '',
array $data = []
): \stdClass {
$options = [ $options = [
'type' => $type, 'type' => $type,
'name' => $name, 'name' => $name,
@@ -49,15 +56,34 @@ class DNS implements API
$options['ttl'] = $ttl; $options['ttl'] = $ttl;
} }
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options); if (is_numeric($priority)) {
$options['priority'] = (int)$priority;
$body = json_decode($user->getBody()); }
if (isset($body->result->id)) { if (!empty($data)) {
return true; $options['data'] = $data;
} }
return false; $user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
$this->body = json_decode($user->getBody());
$result = $this->body->result;
if( !( $result instanceof \stdClass ) ) {
$errorMessage = '';
if( is_array( $result ) ) {
$errorMessage.= implode( $result );
} elseif( is_string( $result ) ) {
$errorMessage.= $result;
}
throw new EndpointException( sprintf( 'Unexpected add record result. %s', $errorMessage ) );
}
return $result;
} }
public function listRecords( public function listRecords(
@@ -97,32 +123,42 @@ class DNS implements API
$query['direction'] = $direction; $query['direction'] = $direction;
} }
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function getRecordDetails(string $zoneID, string $recordID): \stdClass public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []); $user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; 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 public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{ {
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details); $response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
return json_decode($response->getBody()); $this->body = json_decode($response->getBody());
return $this->body;
} }
public function deleteRecord(string $zoneID, string $recordID): bool public function deleteRecord(string $zoneID, string $recordID): bool
{ {
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []); $user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
if (isset($body->result->id)) { if (isset($this->body->result->id)) {
return true; return true;
} }

View File

@@ -0,0 +1,144 @@
<?php
/**
* Created by Visual Studio Code.
* User: elliot.alderson
* Date: 2020-02-06
* Time: 03:40 AM
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
use Cloudflare\API\Configurations\DNSAnalytics as Configs;
class DNSAnalytics implements API
{
use BodyAccessorTrait;
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Retrieves a list of summarised aggregate metrics over a given time period.
*
* @param string $zoneID ID of zone to get report for
* @param string $dimensions Comma separated names of dimensions
* @param string $metrics Comma separated names of dimension to get metrics for
* @param string $sort Comma separated names of dimension to sort by prefixed by order - (descending) or + (ascending)
* @param string $filters Segmentation filter in 'attribute operator value' format
* @param string $since Start date and time of requesting data period in the ISO8601 format
* @param string $until End date and time of requesting data period in the ISO8601 format
* @param string $limit Limit number of returned metrics
* @return array
*/
public function getReportTable(
string $zoneID,
array $dimensions = [],
array $metrics = [],
array $sort = [],
string $filters = '',
string $since = '',
string $until = '',
int $limit = 100
): \stdClass {
if (count($dimensions) === 0) {
throw new EndpointException(
'At least one dimension is required for getting a report.'
);
}
if (count($metrics) === 0) {
throw new EndpointException(
'At least one metric is required for getting a report.'
);
}
if (!$since) {
throw new EndpointException(
'Start date is required for getting a report.'
);
}
if (!$until) {
throw new EndpointException(
'End date is required for getting a report.'
);
}
$options = [
'dimensions' => implode(',', $dimensions),
'metrics' => implode(',', $metrics),
'since' => $since,
'until' => $until
];
if (count($sort) !== 0) {
$options['sort'] = implode(',', $sort);
}
if ($filters) {
$options['filters'] = $filters;
}
if ($limit) {
$options['limit'] = $limit;
}
$endpoint = 'zones/' . $zoneID . '/dns_analytics/report';
$report = $this->adapter->get($endpoint, $options);
$this->body = json_decode($report->getBody());
return $this->body->result;
}
/**
* Retrieves a list of aggregate metrics grouped by time interval.
*
* @param string $zoneID ID of zone to get report for
* @param string $dimensions Comma separated names of dimensions
* @param string $metrics Comma separated names of dimension to get metrics for
* @param string $sort Comma separated names of dimension to sort by prefixed by order - (descending) or + (ascending)
* @param string $filters Segmentation filter in 'attribute operator value' format
* @param string $since Start date and time of requesting data period in the ISO8601 format
* @param string $until End date and time of requesting data period in the ISO8601 format
* @param string $limit Limit number of returned metrics
* @param string $timeDelta Unit of time to group data by
* @return array
*/
public function getReportByTime(
string $zoneID,
array $dimensions = [],
array $metrics = [],
array $sort = [],
string $filters = '',
string $since = '',
string $until = '',
int $limit = 100,
string $timeDelta = ''
): \stdClass {
$options = new Configs();
$options->setDimensions($dimensions);
$options->setMetrics($metrics);
$options->setSince($since);
$options->setUntil($until);
$options->setSorting($sort);
$options->setFilters($filters);
$options->setLimit($limit);
$options->setTimeDelta($timeDelta);
$endpoint = 'zones/' . $zoneID . '/dns_analytics/report/bytime';
$report = $this->adapter->get($endpoint, $options->getArray());
$this->body = json_decode($report->getBody());
return $this->body->result;
}
}

120
src/Endpoints/Firewall.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\FirewallRuleOptions;
class Firewall implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function createFirewallRules(
string $zoneID,
array $rules
): bool {
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/rules', $rules);
$body = json_decode($query->getBody());
foreach ($body->result as $result) {
if (!isset($result->id)) {
return false;
}
}
return true;
}
public function createFirewallRule(
string $zoneID,
string $expression,
FirewallRuleOptions $options,
string $description = null,
int $priority = null
): bool {
$rule = array_merge([
'filter' => [
'expression' => $expression,
'paused' => false
]
], $options->getArray());
if ($description !== null) {
$rule['description'] = $description;
}
if ($priority !== null) {
$rule['priority'] = $priority;
}
return $this->createFirewallRules($zoneID, [$rule]);
}
public function listFirewallRules(
string $zoneID,
int $page = 1,
int $perPage = 50
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
];
$rules = $this->adapter->get('zones/' . $zoneID . '/firewall/rules', $query);
$body = json_decode($rules->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function deleteFirewallRule(
string $zoneID,
string $ruleID
): bool {
$rule = $this->adapter->delete('zones/' . $zoneID . '/firewall/rules/' . $ruleID);
$body = json_decode($rule->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function updateFirewallRule(
string $zoneID,
string $ruleID,
string $filterID,
string $expression,
FirewallRuleOptions $options,
string $description = null,
int $priority = null
): \stdClass {
$rule = array_merge([
'id' => $ruleID,
'filter' => [
'id' => $filterID,
'expression' => $expression,
'paused' => false
]
], $options->getArray());
if ($description !== null) {
$rule['description'] = $description;
}
if ($priority !== null) {
$rule['priority'] = $priority;
}
$rule = $this->adapter->put('zones/' . $zoneID . '/firewall/rules/' . $ruleID, $rule);
$body = json_decode($rule->getBody());
return $body->result;
}
}

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

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class IPs implements API class IPs implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -21,9 +24,9 @@ class IPs implements API
public function listIPs(): \stdClass public function listIPs(): \stdClass
{ {
$ips = $this->adapter->get('ips', [], []); $ips = $this->adapter->get('ips');
$body = json_decode($ips->getBody()); $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

@@ -11,9 +11,12 @@ namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\PageRulesActions; use Cloudflare\API\Configurations\PageRulesActions;
use Cloudflare\API\Configurations\PageRulesTargets; use Cloudflare\API\Configurations\PageRulesTargets;
use Cloudflare\API\Traits\BodyAccessorTrait;
class PageRules implements API class PageRules implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -52,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; return true;
} }
@@ -70,19 +73,19 @@ class PageRules implements API
string $direction = null, string $direction = null,
string $match = null string $match = null
): array { ): array {
if ($status === null && !in_array($status, ['active', 'disabled'])) { if ($status != null && !in_array($status, ['active', 'disabled'])) {
throw new EndpointException('Page Rules can only be listed by status of active or disabled.'); throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
} }
if ($order === null && !in_array($order, ['status', 'priority'])) { if ($order != null && !in_array($order, ['status', 'priority'])) {
throw new EndpointException('Page Rules can only be ordered by status or priority.'); throw new EndpointException('Page Rules can only be ordered by status or priority.');
} }
if ($direction === null && !in_array($direction, ['asc', 'desc'])) { if ($direction != null && !in_array($direction, ['asc', 'desc'])) {
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.'); throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
} }
if ($match === null && !in_array($match, ['all', 'any'])) { if ($match != null && !in_array($match, ['all', 'any'])) {
throw new EndpointException('Match can only be any or all.'); throw new EndpointException('Match can only be any or all.');
} }
@@ -93,21 +96,53 @@ class PageRules implements API
'match' => $match 'match' => $match
]; ];
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []); $user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
}
public function editPageRule(
string $zoneID,
string $ruleID,
PageRulesTargets $target,
PageRulesActions $actions,
bool $active = null,
int $priority = null
): bool {
$options = [];
$options['targets'] = $target->getArray();
$options['actions'] = $actions->getArray();
if ($active !== null) {
$options['status'] = $active == true ? 'active' : 'disabled';
}
if ($priority !== null) {
$options['priority'] = $priority;
}
$query = $this->adapter->put('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
$this->body = json_decode($query->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
} }
public function updatePageRule( public function updatePageRule(
string $zoneID, string $zoneID,
string $ruleID,
PageRulesTargets $target = null, PageRulesTargets $target = null,
PageRulesActions $actions = null, PageRulesActions $actions = null,
bool $active = null, bool $active = null,
@@ -131,12 +166,11 @@ class PageRules implements API
$options['priority'] = $priority; $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($this->body->result->id)) {
if (isset($body->result->id)) {
return true; return true;
} }
@@ -145,11 +179,11 @@ class PageRules implements API
public function deletePageRule(string $zoneID, string $ruleID): bool 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; 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;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Railgun implements API class Railgun implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -26,10 +29,10 @@ class Railgun implements API
'name' => $name, 'name' => $name,
]; ];
$user = $this->adapter->post('railguns', [], $query); $user = $this->adapter->post('railguns', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body; return $this->body;
} }
public function list( public function list(
@@ -46,28 +49,28 @@ class Railgun implements API
$query['direction'] = $direction; $query['direction'] = $direction;
} }
$user = $this->adapter->get('railguns', $query, []); $user = $this->adapter->get('railguns', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function get( public function get(
string $railgunID string $railgunID
): \stdClass { ): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID, [], []); $user = $this->adapter->get('railguns/' . $railgunID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function getZones( public function getZones(
string $railgunID string $railgunID
): \stdClass { ): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []); $user = $this->adapter->get('railguns/' . $railgunID . '/zones');
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function update( public function update(
@@ -78,19 +81,19 @@ class Railgun implements API
'enabled' => $status 'enabled' => $status
]; ];
$user = $this->adapter->patch('railguns/' . $railgunID, [], $query); $user = $this->adapter->patch('railguns/' . $railgunID, $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function delete( public function delete(
string $railgunID string $railgunID
): bool { ): bool {
$user = $this->adapter->delete('railguns/' . $railgunID, [], []); $user = $this->adapter->delete('railguns/' . $railgunID);
$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 true;
} }

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

@@ -0,0 +1,183 @@
<?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;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* Get SSL Verification Info for a Zone
*
* @param string $zoneID The ID of the zone
* @param bool $retry Immediately retry SSL Verification
* @return array|false
*/
public function getSSLVerificationStatus(string $zoneID, bool $retry = false)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/ssl/verification',
[
'retry' => $retry
]
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body;
}
return false;
}
/**
* Get the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRedirectSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_use_https'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Get the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRewritesSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Update the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSSLSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/ssl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_use_https',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the SSL certificate pack validation method
*
* @param string $zoneID The ID of the zone
* @param string $certPackUUID The certificate pack UUID
* @param string $validationMethod The verification method
* @return bool
*/
public function updateSSLCertificatePackValidationMethod(string $zoneID, string $certPackUUID, string $validationMethod)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/ssl/verification/' . $certPackUUID,
[
'validation_method' => $validationMethod,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

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

@@ -10,9 +10,12 @@ namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Configurations\Configurations; use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class UARules implements API class UARules implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -30,10 +33,10 @@ class UARules implements API
'per_page' => $perPage 'per_page' => $perPage
]; ];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function createRule( public function createRule(
@@ -56,11 +59,11 @@ class UARules implements API
$options['description'] = $description; $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; return true;
} }
@@ -69,9 +72,9 @@ class UARules implements API
public function getRuleDetails(string $zoneID, string $blockID): \stdClass public function getRuleDetails(string $zoneID, string $blockID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, [], []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function updateRule( public function updateRule(
@@ -91,11 +94,11 @@ class UARules implements API
$options['description'] = $description; $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; return true;
} }
@@ -104,11 +107,11 @@ class UARules implements API
public function deleteRule(string $zoneID, string $ruleID): bool 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; return true;
} }

View File

@@ -8,9 +8,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class User implements API class User implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -20,9 +23,9 @@ class User implements API
public function getUserDetails(): \stdClass public function getUserDetails(): \stdClass
{ {
$user = $this->adapter->get('user', [], []); $user = $this->adapter->get('user');
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function getUserID(): string public function getUserID(): string
@@ -37,7 +40,8 @@ class User implements API
public function updateUserDetails(array $details): \stdClass public function updateUserDetails(array $details): \stdClass
{ {
$response = $this->adapter->patch('user', [], $details); $response = $this->adapter->patch('user', $details);
return json_decode($response->getBody()); $this->body = json_decode($response->getBody());
return $this->body;
} }
} }

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class WAF implements API class WAF implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -41,10 +44,10 @@ class WAF implements API
$query['direction'] = $direction; $query['direction'] = $direction;
} }
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
@@ -52,10 +55,10 @@ class WAF implements API
string $zoneID, string $zoneID,
string $packageID string $packageID
): \stdClass { ): \stdClass {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID, [], []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function getRules( public function getRules(
@@ -80,10 +83,10 @@ class WAF implements API
if (!empty($direction)) { if (!empty($direction)) {
$query['direction'] = $direction; $query['direction'] = $direction;
} }
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function getRuleInfo( public function getRuleInfo(
@@ -91,14 +94,10 @@ class WAF implements API
string $packageID, string $packageID,
string $ruleID string $ruleID
): \stdClass { ): \stdClass {
$user = $this->adapter->get( $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID, $this->body = json_decode($user->getBody());
[],
[]
);
$body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function updateRule( public function updateRule(
@@ -113,12 +112,11 @@ class WAF implements API
$user = $this->adapter->patch( $user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID, 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
[],
$query $query
); );
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function getGroups( public function getGroups(
@@ -146,12 +144,11 @@ class WAF implements API
$user = $this->adapter->get( $user = $this->adapter->get(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups', 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
$query, $query
[]
); );
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function getGroupInfo( public function getGroupInfo(
@@ -159,14 +156,10 @@ class WAF implements API
string $packageID, string $packageID,
string $groupID string $groupID
): \stdClass { ): \stdClass {
$user = $this->adapter->get( $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID, $this->body = json_decode($user->getBody());
[],
[]
);
$body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function updateGroup( public function updateGroup(
@@ -181,11 +174,10 @@ class WAF implements API
$user = $this->adapter->patch( $user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID, 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
[],
$query $query
); );
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
} }

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class ZoneLockdown implements API class ZoneLockdown implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -29,10 +32,10 @@ class ZoneLockdown implements API
'per_page' => $perPage 'per_page' => $perPage
]; ];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function createLockdown( public function createLockdown(
@@ -55,11 +58,11 @@ class ZoneLockdown implements API
$options['description'] = $description; $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; return true;
} }
@@ -68,9 +71,9 @@ class ZoneLockdown implements API
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function updateLockdown( public function updateLockdown(
@@ -90,11 +93,11 @@ class ZoneLockdown implements API
$options['description'] = $description; $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; return true;
} }
@@ -103,11 +106,11 @@ class ZoneLockdown implements API
public function deleteLockdown(string $zoneID, string $lockdownID): bool 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; return true;
} }

View File

@@ -0,0 +1,245 @@
<?php
/**
* Created by PhpStorm.
* User: paul.adams
* Date: 2019-02-22
* Time: 23:28
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class ZoneSettings implements API
{
use BodyAccessorTrait;
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 getServerSideExcludeSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/server_side_exclude'
);
$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 getBrowserCacheTtlSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/browser_cache_ttl'
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
public function updateBrowserCacheTtlSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/browser_cache_ttl',
[
'value' => $value
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
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;
}
public function updateServerSideExcludeSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/server_side_exclude',
[
'value' => $value
]
);
$body = json_decode($return->getBody());
if ($body->success) {
return $body->result->value;
}
return false;
}
}

View File

@@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;
class Zones implements API class Zones implements API
{ {
use BodyAccessorTrait;
private $adapter; private $adapter;
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
@@ -23,38 +26,71 @@ class Zones implements API
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* *
* @param string $name * @param string $name
* @param bool $jumpstart * @param bool $jumpStart
* @param string $organizationID * @param string $organizationID
* @return \stdClass * @return \stdClass
*/ */
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
{ {
$options = [ $options = [
'name' => $name, 'name' => $name,
'jumpstart' => $jumpstart 'jump_start' => $jumpStart
]; ];
if (!empty($organizationID)) { if (!empty($organizationID)) {
$options['organization'] = (object)['id' => $organizationID]; $options['organization'] = ['id' => $organizationID];
} }
$user = $this->adapter->post('zones', [], $options); $user = $this->adapter->post('zones', $options);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return $body->result; return $this->body->result;
} }
public function activationCheck(string $zoneID): bool public function activationCheck(string $zoneID): bool
{ {
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []); $user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
$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 true;
} }
return false; return false;
} }
public function pause(string $zoneID): bool
{
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => true]);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
public function unpause(string $zoneID): bool
{
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => false]);
$this->body = json_decode($user->getBody());
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( public function listZones(
string $name = '', string $name = '',
string $status = '', string $status = '',
@@ -86,10 +122,10 @@ class Zones implements API
$query['direction'] = $direction; $query['direction'] = $direction;
} }
$user = $this->adapter->get('zones', $query, []); $user = $this->adapter->get('zones', $query);
$body = json_decode($user->getBody()); $this->body = json_decode($user->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info]; return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
} }
public function getZoneID(string $name = ''): string public function getZoneID(string $name = ''): string
@@ -114,9 +150,11 @@ class Zones implements API
*/ */
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \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)], []); $response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]);
return json_decode($response->getBody())->result; $this->body = $response->getBody();
return json_decode($this->body)->result;
} }
/** /**
@@ -128,17 +166,49 @@ class Zones implements API
*/ */
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
{ {
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => $enable ? 'on' : 'off']); $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']);
$body = json_decode($response->getBody()); $this->body = json_decode($response->getBody());
if ($body->success) { if ($this->body->success) {
return true; return true;
} }
return false; 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 * Purge Everything
@@ -147,33 +217,55 @@ class Zones implements API
*/ */
public function cachePurgeEverything(string $zoneID): bool public function cachePurgeEverything(string $zoneID): bool
{ {
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ['purge_everything' => true]); $user = $this->adapter->post('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 true;
} }
return false; return false;
} }
public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool public function cachePurge(string $zoneID, array $files = null, array $tags = null, array $hosts = null): bool
{ {
if ($files === null && $tags === null) { if ($files === null && $tags === null && $hosts === null) {
throw new EndpointException('No files or tags to purge.'); throw new EndpointException('No files, tags or hosts to purge.');
} }
$options = [ $options = [];
'files' => $files, if (!is_null($files)) {
'tags' => $tags $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->post('zones/' . $zoneID . '/purge_cache', $options);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true;
}
return false;
}
/**
* Delete Zone
*/
public function deleteZone(string $identifier): bool
{
$user = $this->adapter->delete('zones/' . $identifier);
$this->body = json_decode($user->getBody());
if (isset($this->body->result->id)) {
return true; return true;
} }

View File

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

View File

@@ -1,12 +1,6 @@
<?php <?php
/** use Cloudflare\API\Adapter\ResponseException;
* User: junade
* Date: 13/01/2017
* Time: 23:35
*/
use GuzzleHttp\Psr7\Response;
class GuzzleTest extends TestCase class GuzzleTest extends TestCase
{ {
@@ -41,7 +35,7 @@ class GuzzleTest extends TestCase
public function testPost() 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(); $headers = $response->getHeaders();
$this->assertEquals('application/json', $headers['Content-Type'][0]); $this->assertEquals('application/json', $headers['Content-Type'][0]);
@@ -52,7 +46,7 @@ class GuzzleTest extends TestCase
public function testPut() 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(); $headers = $response->getHeaders();
$this->assertEquals('application/json', $headers['Content-Type'][0]); $this->assertEquals('application/json', $headers['Content-Type'][0]);
@@ -65,7 +59,6 @@ class GuzzleTest extends TestCase
{ {
$response = $this->client->patch( $response = $this->client->patch(
'https://httpbin.org/patch', 'https://httpbin.org/patch',
[],
['X-Patch-Test' => 'Testing a PATCH request.'] ['X-Patch-Test' => 'Testing a PATCH request.']
); );
@@ -80,7 +73,6 @@ class GuzzleTest extends TestCase
{ {
$response = $this->client->delete( $response = $this->client->delete(
'https://httpbin.org/delete', 'https://httpbin.org/delete',
[],
['X-Delete-Test' => 'Testing a DELETE request.'] ['X-Delete-Test' => 'Testing a DELETE request.']
); );
@@ -91,48 +83,15 @@ class GuzzleTest extends TestCase
$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()
{
$class = new ReflectionClass(\Cloudflare\API\Adapter\Guzzle::class);
$method = $class->getMethod('checkError');
$method->setAccessible(true);
$body =
'{
"result": null,
"success": false,
"errors": [{"code":1003,"message":"Invalid or missing zone id."}],
"messages": []
}'
;
$response = new Response(200, [], $body);
$this->expectException(\Cloudflare\API\Adapter\ResponseException::class);
$method->invokeArgs($this->client, [$response]);
$body =
'{
"result": null,
"success": false,
"errors": [],
"messages": []
}'
;
$response = new Response(200, [], $body);
$this->expectException(\Cloudflare\API\Adapter\ResponseException::class);
$method->invokeArgs($this->client, [$response]);
$body = 'this isnt json.';
$response = new Response(200, [], $body);
$this->expectException(\Cloudflare\API\Adapter\JSONException::class);
$method->invokeArgs($this->client, [$response]);
}
public function testNotFound() public function testNotFound()
{ {
$this->expectException(\GuzzleHttp\Exception\RequestException::class); $this->expectException(ResponseException::class);
$this->client->get('https://httpbin.org/status/404'); $this->client->get('https://httpbin.org/status/404');
} }
public function testServerError()
{
$this->expectException(ResponseException::class);
$this->client->get('https://httpbin.org/status/500');
}
} }

View File

@@ -0,0 +1,81 @@
<?php
use Cloudflare\API\Adapter\ResponseException;
use Cloudflare\API\Adapter\JSONException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
class ResponseExceptionTest extends TestCase
{
public function testFromRequestExceptionNoResponse()
{
$reqErr = new RequestException('foo', new Request('GET', '/test'));
$respErr = ResponseException::fromRequestException($reqErr);
$this->assertInstanceOf(ResponseException::class, $respErr);
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
$this->assertEquals(0, $respErr->getCode());
$this->assertEquals($reqErr, $respErr->getPrevious());
}
public function testFromRequestExceptionEmptyContentType()
{
$resp = new Response(404);
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
$respErr = ResponseException::fromRequestException($reqErr);
$this->assertInstanceOf(ResponseException::class, $respErr);
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
$this->assertEquals(0, $respErr->getCode());
$this->assertEquals($reqErr, $respErr->getPrevious());
}
public function testFromRequestExceptionUnknownContentType()
{
$resp = new Response(404, ['Content-Type' => ['application/octet-stream']]);
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
$respErr = ResponseException::fromRequestException($reqErr);
$this->assertInstanceOf(ResponseException::class, $respErr);
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
$this->assertEquals(0, $respErr->getCode());
$this->assertEquals($reqErr, $respErr->getPrevious());
}
public function testFromRequestExceptionJSONDecodeError()
{
$resp = new Response(404, ['Content-Type' => ['application/json; charset=utf-8']], '[what]');
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
$respErr = ResponseException::fromRequestException($reqErr);
$this->assertInstanceOf(ResponseException::class, $respErr);
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
$this->assertEquals(0, $respErr->getCode());
$this->assertInstanceOf(JSONException::class, $respErr->getPrevious());
$this->assertEquals($reqErr, $respErr->getPrevious()->getPrevious());
}
public function testFromRequestExceptionJSONWithErrors()
{
$body = '{
"result": null,
"success": false,
"errors": [{"code":1003, "message":"This is an error"}],
"messages": []
}';
$resp = new Response(404, ['Content-Type' => ['application/json; charset=utf-8']], $body);
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
$respErr = ResponseException::fromRequestException($reqErr);
$this->assertInstanceOf(ResponseException::class, $respErr);
$this->assertEquals('This is an error', $respErr->getMessage());
$this->assertEquals(1003, $respErr->getCode());
$this->assertEquals($reqErr, $respErr->getPrevious());
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* User: czPechy
* Date: 30/07/2018
* Time: 23:25
*/
class APITokenTest extends TestCase
{
public function testGetHeaders()
{
$auth = new \Cloudflare\API\Auth\APIToken('zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy');
$headers = $auth->getHeaders();
$this->assertArrayHasKey('Authorization', $headers);
$this->assertEquals('Bearer zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy', $headers['Authorization']);
$this->assertCount(1, $headers);
}
}

View File

@@ -0,0 +1,22 @@
<?php
use PHPUnit\Framework\TestCase;
use Cloudflare\API\Configurations\Certificate;
class CertificateTest extends TestCase
{
public function testGetArray()
{
$certificate = new Certificate();
$certificate->setHostnames(['foo.com', '*.bar.com']);
$certificate->setRequestType(Certificate::ORIGIN_ECC);
$certificate->setRequestedValidity(365);
$certificate->setCsr('some-csr-encoded-text');
$array = $certificate->getArray();
$this->assertEquals(['foo.com', '*.bar.com'], $array['hostnames']);
$this->assertEquals('origin-ecc', $array['request_type']);
$this->assertEquals(365, $array['requested_validity']);
$this->assertEquals('some-csr-encoded-text', $array['csr']);
}
}

View File

@@ -16,12 +16,12 @@ class ConfigurationsUARulesTest extends TestCase
$array = $configuration->getArray(); $array = $configuration->getArray();
$this->assertCount(1, $array); $this->assertCount(1, $array);
$this->assertObjectHasAttribute('target', $array[0]); $this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ua', $array[0]->target); $this->assertEquals('ua', $array[0]['target']);
$this->assertObjectHasAttribute('value', $array[0]); $this->assertArrayHasKey('value', $array[0]);
$this->assertEquals( $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', '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 $array[0]['value']
); );
} }
} }

View File

@@ -16,19 +16,19 @@ class ConfigurationsZoneLockdownTest extends TestCase
$array = $configuration->getArray(); $array = $configuration->getArray();
$this->assertCount(1, $array); $this->assertCount(1, $array);
$this->assertObjectHasAttribute('target', $array[0]); $this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ip', $array[0]->target); $this->assertEquals('ip', $array[0]['target']);
$this->assertObjectHasAttribute('value', $array[0]); $this->assertArrayHasKey('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]->value); $this->assertEquals('1.2.3.4', $array[0]['value']);
$configuration->addIPRange('1.2.3.4/24'); $configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray(); $array = $configuration->getArray();
$this->assertCount(2, $array); $this->assertCount(2, $array);
$this->assertObjectHasAttribute('target', $array[1]); $this->assertArrayHasKey('target', $array[1]);
$this->assertEquals('ip_range', $array[1]->target); $this->assertEquals('ip_range', $array[1]['target']);
$this->assertObjectHasAttribute('value', $array[1]); $this->assertArrayHasKey('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]->value); $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

@@ -16,7 +16,7 @@ class PageRulesTargetTest extends TestCase
$array = $targets->getArray(); $array = $targets->getArray();
$this->assertCount(1, $array); $this->assertCount(1, $array);
$this->assertEquals('junade.com/*', $array[0]->constraint->value); $this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
$this->assertEquals('matches', $array[0]->constraint->operator); $this->assertEquals('matches', $array[0]['constraint']['operator']);
} }
} }

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

@@ -17,8 +17,7 @@ class AccessRulesTest extends TestCase
'page' => 1, 'page' => 1,
'per_page' => 50, 'per_page' => 50,
'match' => 'all' 'match' => 'all'
]), ])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock); $zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
@@ -29,6 +28,7 @@ class AccessRulesTest extends TestCase
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id); $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $zones->getBody()->result[0]->id);
} }
public function testCreateRule() public function testCreateRule()
@@ -45,10 +45,9 @@ class AccessRulesTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'mode' => 'challenge', 'mode' => 'challenge',
'configuration' => (object) $config->getArray(), 'configuration' => $config->getArray(),
'notes' => 'This rule is on because of an event that occured on date X', 'notes' => 'This rule is on because of an event that occured on date X',
]) ])
); );
@@ -60,6 +59,7 @@ class AccessRulesTest extends TestCase
$config, $config,
'This rule is on because of an event that occured on date X' 'This rule is on because of an event that occured on date X'
); );
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
} }
public function testUpdateRule() public function testUpdateRule()
@@ -73,7 +73,6 @@ class AccessRulesTest extends TestCase
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'mode' => 'challenge', 'mode' => 'challenge',
'notes' => 'This rule is on because of an event that occured on date X', 'notes' => 'This rule is on because of an event that occured on date X',
@@ -87,6 +86,7 @@ class AccessRulesTest extends TestCase
'challenge', 'challenge',
'This rule is on because of an event that occured on date X' 'This rule is on because of an event that occured on date X'
); );
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
} }
public function testDeleteRule() public function testDeleteRule()
@@ -100,7 +100,6 @@ class AccessRulesTest extends TestCase
->method('delete') ->method('delete')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'cascade' => 'none' 'cascade' => 'none'
]) ])
@@ -108,5 +107,6 @@ class AccessRulesTest extends TestCase
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock); $rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b'); $rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
} }
} }

View File

@@ -0,0 +1,37 @@
<?php
/**
* User: kanasite
* Date: 01/28/2019
* Time: 10:00
*/
class AccountsTest extends TestCase
{
public function testListZones()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccounts.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'direction' => 'desc',
])
);
$accounts = new \Cloudflare\API\Endpoints\Accounts($mock);
$result = $accounts->listAccounts(1, 20, 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
}
}

View File

@@ -0,0 +1,120 @@
<?php
use Cloudflare\API\Endpoints\Certificates;
class CertificatesTest extends TestCase
{
public function testListCertificates()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listCertificates.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('certificates'),
$this->equalTo(
[
'zone_id' => '023e105f4ecef8ad9ca31a8372d0c353',
]
)
);
$certEndpoint = new Certificates($mock);
$result = $certEndpoint->listCertificates('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$cert = $result->result[0];
$this->assertEquals('328578533902268680212849205732770752308931942346', $cert->id);
$this->assertEquals('origin-rsa', $cert->request_type);
$this->assertEquals(5475, $cert->requested_validity);
$this->assertEquals(['example.com', '*.example.com'], $cert->hostnames);
$this->assertEquals('some-cert-data', $cert->certificate);
$this->assertEquals('some-csr-data', $cert->csr);
}
public function testGetCertificate()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('certificates/6666699999996666699999999966666666'),
$this->equalTo(['zone_id' => '023e105f4ecef8ad9ca31a8372d0c353']),
$this->equalTo([])
);
$certEndpoint = new Certificates($mock);
$response = $certEndpoint->getCertificate(
'6666699999996666699999999966666666',
'023e105f4ecef8ad9ca31a8372d0c353'
);
$this->assertObjectHasAttribute('result', $response);
$cert = $response->result;
$this->assertEquals('6666699999996666699999999966666666', $cert->id);
$this->assertEquals('origin-ecc', $cert->request_type);
$this->assertEquals(5475, $cert->requested_validity);
$this->assertEquals(['foo.example.com', 'bar.example.com'], $cert->hostnames);
$this->assertEquals('some-cert-data-foobar', $cert->certificate);
$this->assertEquals('some-csr-data-foobar', $cert->csr);
}
public function testRevokeCertificate()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('certificates/11112222233333444455555'),
$this->equalTo(['zone_id' => '023e105f4ecef8ad9ca31a8372d0c353']),
$this->equalTo([])
);
$certEndpoint = new Certificates($mock);
$result = $certEndpoint->revokeCertificate(
'11112222233333444455555',
'023e105f4ecef8ad9ca31a8372d0c353'
);
$this->assertTrue($result);
}
public function testCreateCertificate()
{
$certificate = new \Cloudflare\API\Configurations\Certificate();
$certificate->setHostnames(['foo.example.com', 'bar.exapmle.com']);
$certificate->setRequestType(\Cloudflare\API\Configurations\Certificate::ORIGIN_ECC);
$certificate->setRequestedValidity(365);
$certificate->setCsr('some-csr-data-barbar');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('certificates'),
$this->equalTo($certificate->getArray()),
$this->equalTo([])
);
$certEndpoint = new Certificates($mock);
$result = $certEndpoint->createCertificate($certificate);
$this->assertTrue($result);
}
}

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,282 @@
<?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');
$customSsl = $this->getCustomSsl();
$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',
'custom_origin_server' => 'origin.example.com',
'ssl' => [
'method' => 'http',
'type' => 'dv',
'settings' => [
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2',
],
'bundle_method' => 'optimal',
'custom_key' => $customSsl['key'],
'custom_certificate' => $customSsl['certificate'],
'wildcard' => true,
],
])
);
$hostname = new CustomHostnames($mock);
$sslSettings = [
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2'
];
$hostname->addHostname(
'023e105f4ecef8ad9ca31a8372d0c353',
'app.example.com',
'http',
'dv',
$sslSettings,
'origin.example.com',
true,
'optimal',
$customSsl
);
$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');
$customSsl = $this->getCustomSsl();
$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([
'custom_origin_server' => 'origin.example.com',
'ssl' => [
'method' => 'http',
'type' => 'dv',
'settings' => [
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2'
],
'bundle_method' => 'optimal',
'custom_key' => $customSsl['key'],
'custom_certificate' => $customSsl['certificate'],
'wildcard' => true,
]
])
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$sslSettings = [
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2'
];
$result = $zones->updateHostname(
'023e105f4ecef8ad9ca31a8372d0c353',
'0d89c70d-ad9f-4843-b99f-6cc0252067e9',
'http',
'dv',
$sslSettings,
'origin.example.com',
true,
'optimal',
[
'key' => $customSsl['key'],
'certificate' => $customSsl['certificate'],
]
);
$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);
}
public function testGetHostnameFallbackOrigin()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCustomHostnameFallbackOrigin.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/fallback_origin')
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->getFallbackOrigin('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('origin', $result);
$this->assertObjectHasAttribute('status', $result);
}
private function getCustomSsl(): array
{
$customKey = <<<KEY
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDZfoCUkzkZLCzo
OFTtlXU9OYqNFx06J/GOKCwDCyfkY5RY1x6BVrVpTqf/JaU42DZmCjIiEugBg4bu
eu9/w21prIWgRKEe8mjrw83+3QSIyQrs+78rqwDptUfL+IyhYln6SBjqPQ569Y0w
x6A896PDMYPHgnWtclGwsxDNKJ2eWsH+C4UkLUeVM4BILEJ00YUjayowL/0sflTJ
yY58c9fVV27aGBJ4znreYkBojPQ0fzVZ3HJfYD+DgYUUkuzN/WohOLTNTxvzt/i2
GNxP8tZzi0E/t4KtGTsIVmROKaCXnmozQyv0VES5TNZL1nxLvVuPca9DKXwVst2o
v5czEM8fAgMBAAECggEBANgG/aIVpWYqaaRyp3CgviWE7Oh9J+um1xgzMJwJTaNd
gXDIoyUmweQKW3Vjp/uRTl8GC4uqqcUvJivj8dU+gIOw970bzcmWT7616vsV/rX6
sp524wh1vt9jzx97DfwSW3rsd8rZwHNDSO1FqxRDiOaNXO4i183iud8/zRVqHTy1
5girngsGl7ebTt3LDHDQQ86kND2nVr8xZuFaqs8Td41AsF6DGbB709wMUqoM/obO
iUtXCZ5Rrm2a78OUi0cqWsuxdhJjtOW0PBvrPTlSq+1EuQWAWV8HN1JI58YnLcLy
SKZpsu5wxWdKMgX0NCkfLjDZCAPlBaZLPPp986GHavECgYEA8hM6tIfGBnXuxBvI
y2lJG3sHGs83pnCqYg9dDrr+m3JOPQu6l9MEPEtsrOiI0Ktu/L+kV5uyBDRvB6ff
BD6BJ2CiG86UvMpKojBeAlZBLXr1SnWzIPC+3fBzkVSo1MiRs3nTNRfeblkRxC3e
LWtl96obA1GOgpifrh6ZB2RfvrcCgYEA5gFL4+oDUDcRtc1Pw+AFwPTey+3rkVU+
FHvRGeU+m6dtxXF+BYFpDs/ONfmHzsdBSwkYxta/x8rKP5uyjl9p0QSdhysrJibO
sWsoux35QxEZiyplCV2+zMK/79EhS2CuiudAidF6NxK+/g9EwXRlGDDlnFDB2epe
kyL97K4zCtkCgYEA68Bgbsq/xzD5XFG2xqr9wN6a97gQ+W5F8QQHW74vEZJLsdYH
Xa7rNBE8gFRiUd5zU4EL+yotPz0VWH5bilWZEJFirvQMFKRp9PRnyZzZEwLpeh+Q
WSc8qwZudn3dgoTmqMSfNdjODed+jvEgrFkoz/8BGcVGpdcfw8IWxIUzXZcCgYAY
/OsRx8q0XEdASR3xWdVGMVRDM4X0NB6aexkshwtWPcpfOQVH89dGFK2Cj6mBfYRK
cqKOd6Y+Pnnajz/G1/bXDnlOxhHaAz1RaSLzsT3zW1g7FlADxHuGI2JW25GSbt6H
mLgaQPfWI+M8FsyRd+PDzQwk/2EQG7ZKpfKQVByXgQKBgQDkKciB6Wb2hLNTKzK8
Kr42U70H++QT8AqZX2F79PjgYcRFZqGXLuq/hEuiOhXfl8DFur3fC5JN8AeLC5/j
bsrBsljYfVvtLQzilugs1oEe94LTrYjR2oQt0W24bqpGQHuv1ILuUBuodERkxSFL
/cMkj3wSfC341hFaJEuG1+PcxA==
-----END PRIVATE KEY-----
KEY;
$customCertificate = <<<CERTIFICATE
-----BEGIN CERTIFICATE-----
MIIDmTCCAoGgAwIBAgIULyaeNqp0tOut/wvuxNyKmUxOGYEwDQYJKoZIhvcNAQEL
BQAwXDELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UE
CgwTRGVmYXVsdCBDb21wYW55IEx0ZDEYMBYGA1UEAwwPYXBwLmV4YW1wbGUuY29t
MB4XDTIxMDYxNDIzMzU0MVoXDTIyMDYxNDIzMzU0MVowXDELMAkGA1UEBhMCWFgx
FTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBDb21wYW55
IEx0ZDEYMBYGA1UEAwwPYXBwLmV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEA2X6AlJM5GSws6DhU7ZV1PTmKjRcdOifxjigsAwsn5GOU
WNcegVa1aU6n/yWlONg2ZgoyIhLoAYOG7nrvf8NtaayFoEShHvJo68PN/t0EiMkK
7Pu/K6sA6bVHy/iMoWJZ+kgY6j0OevWNMMegPPejwzGDx4J1rXJRsLMQzSidnlrB
/guFJC1HlTOASCxCdNGFI2sqMC/9LH5UycmOfHPX1Vdu2hgSeM563mJAaIz0NH81
WdxyX2A/g4GFFJLszf1qITi0zU8b87f4thjcT/LWc4tBP7eCrRk7CFZkTimgl55q
M0Mr9FREuUzWS9Z8S71bj3GvQyl8FbLdqL+XMxDPHwIDAQABo1MwUTAdBgNVHQ4E
FgQUbAfyBm0wpM7FqUb1yqeaF4voY/gwHwYDVR0jBBgwFoAUbAfyBm0wpM7FqUb1
yqeaF4voY/gwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAO2Dd
k/seFjp83caYE/NVdDy5B7l5JeVtruaUdlGbb0xtVhiIdoY43ukhHFw8zuWMW9RX
SUbrzwacfKLDBikcefk9go6cMimqYIRF8Hntph1gjjqB0papUm2WVYbsBRv2okys
ej0dGSeUEsWjKRTSMkJsbbiEv6oveeSki069zl+tln0UhbHedkIY3rJsFIyoddSu
g96r5HPHksnObm1JCym0xd09+msliDkBmq87mxok9m5aEqWX4XvdGfYERV/eD5vC
KcW4DoM1KZd8E6tlniglc1jC0pzKfho7Uoe6UtObgHZGNwRYwYy+BHvHYY46ctSI
NdZ7G/lUyrBFhsRrhw==
-----END CERTIFICATE-----
CERTIFICATE;
return [
'key' => $customKey,
'certificate' => $customCertificate,
];
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Created by Visual Studio Code.
* User: elliot.alderson
* Date: 10/02/2020
* Time: 04:28 AM
*/
class DNSAnalyticsTest extends TestCase
{
public function testGetDNSAnalyticsReportTable()
{
$response = $this->getPsr7JsonResponseForFixture(
'Endpoints/getDNSAnalyticsReportTable.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_analytics/report'
)
);
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
$since = '2020-02-01T00:00:00Z';
$until = '2020-02-28T23:59:59Z';
$filters = 'responseCode==NOERROR AND queryType==A';
$result = $analytics->getReportTable(
'023e105f4ecef8ad9ca31a8372d0c353',
['queryName', 'queryType', 'responseCode'],
['queryCount'],
['-queryCount'],
$filters,
$since,
$until
);
$this->assertEquals(1, $result->rows);
$this->assertEquals($since, $result->query->since);
$this->assertEquals($until, $result->query->until);
}
public function testGetDNSAnalyticsReportByTime()
{
$response = $this->getPsr7JsonResponseForFixture(
'Endpoints/getDNSAnalyticsReportByTime.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_analytics/report/bytime'
)
);
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
$since = '2020-02-01T00:00:00Z';
$until = '2020-02-28T23:59:59Z';
$filters = 'responseCode==NOERROR AND queryType==A';
$result = $analytics->getReportByTime(
'023e105f4ecef8ad9ca31a8372d0c353',
['queryName', 'queryType', 'responseCode'],
['queryCount'],
['-queryCount'],
$filters,
$since,
$until,
2
);
$this->assertEquals(2, $result->rows);
$this->assertEquals($since, $result->query->since);
$this->assertEquals($until, $result->query->until);
}
}

View File

@@ -19,7 +19,6 @@ class DNSTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'type' => 'A', 'type' => 'A',
'name' => 'example.com', 'name' => 'example.com',
@@ -33,6 +32,57 @@ class DNSTest extends TestCase
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', '120', false); $dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', '120', false);
} }
public function testAddMXRecordPriority10()
{
$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([
'type' => 'MX',
'name' => 'example.com',
'content' => '127.0.0.1',
'ttl' => 120,
'proxied' => false,
'priority' => 10,
])
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 10);
}
public function testAddMXRecordPriority0()
{
$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([
'type' => 'MX',
'name' => 'example.com',
'content' => '127.0.0.1',
'ttl' => 120,
'proxied' => false,
'priority' => 0,
])
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 0);
}
public function testListRecords() public function testListRecords()
{ {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json'); $response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');
@@ -44,16 +94,16 @@ class DNSTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([ $this->equalTo([
'page' => 1, 'page' => 1,
'per_page' => 20, 'per_page' => 20,
'match' => 'all', 'match' => 'all',
'type' => 'A', 'type' => 'A',
'name' => 'example.com', 'name' => 'example.com',
'content' => '127.0.0.1', 'content' => '127.0.0.1',
'order' => 'type', 'order' => 'type',
'direction' => 'desc']), 'direction' => 'desc',
$this->equalTo([]) ])
); );
$zones = new \Cloudflare\API\Endpoints\DNS($mock); $zones = new \Cloudflare\API\Endpoints\DNS($mock);
@@ -64,6 +114,7 @@ class DNSTest extends TestCase
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
} }
public function testGetDNSRecordDetails() public function testGetDNSRecordDetails()
@@ -76,14 +127,33 @@ class DNSTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
$this->equalTo([])
); );
$dns = new \Cloudflare\API\Endpoints\DNS($mock); $dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$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() public function testUpdateDNSRecord()
@@ -105,7 +175,6 @@ class DNSTest extends TestCase
->method('put') ->method('put')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo($details) $this->equalTo($details)
); );
@@ -113,6 +182,7 @@ class DNSTest extends TestCase
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details); $result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
foreach ($details as $property => $value) { foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $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

@@ -0,0 +1,177 @@
<?php
class FirewallTest extends TestCase
{
public function testCreatePageRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRules.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/rules'),
$this->equalTo([
[
'action' => 'block',
'description' => 'Foo',
'filter' => [
'expression' => 'http.cookie eq "foo"',
'paused' => false
],
],
[
'action' => 'block',
'description' => 'Bar',
'filter' => [
'expression' => 'http.cookie eq "bar"',
'paused' => false
],
]
])
);
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
$result = $firewall->createFirewallRules(
'023e105f4ecef8ad9ca31a8372d0c353',
[
[
'filter' => [
'expression' => 'http.cookie eq "foo"',
'paused' => false
],
'action' => 'block',
'description' => 'Foo'
],
[
'filter' => [
'expression' => 'http.cookie eq "bar"',
'paused' => false
],
'action' => 'block',
'description' => 'Bar'
],
]
);
$this->assertTrue($result);
}
public function testCreatePageRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRule.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/rules'),
$this->equalTo([
[
'action' => 'block',
'description' => 'Foobar',
'filter' => [
'expression' => 'http.cookie eq "foobar"',
'paused' => false
],
'paused' => false
]
])
);
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
$options->setActionBlock();
$result = $firewall->createFirewallRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'http.cookie eq "foobar"',
$options,
'Foobar'
);
$this->assertTrue($result);
}
public function testListFirewallRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listFirewallRules.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/rules'),
$this->equalTo([
'page' => 1,
'per_page' => 50
])
);
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
$result = $firewall->listFirewallRules('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->result[0]->id);
}
public function testDeleteFirewallRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteFirewallRule.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/rules/970b10321e3f4adda674c912b5f76591')
);
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
$firewall->deleteFirewallRule('023e105f4ecef8ad9ca31a8372d0c353', '970b10321e3f4adda674c912b5f76591');
}
public function testUpdateFirewallRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateFirewallRule.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/rules/970b10321e3f4adda674c912b5f76591'),
$this->equalTo([
'id' => '970b10321e3f4adda674c912b5f76591',
'action' => 'block',
'description' => 'Foo',
'filter' => [
'id' => '5def9c4297e0466cb0736b838345d910',
'expression' => 'http.cookie eq "foo"',
'paused' => false
],
'paused' => false
])
);
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
$options->setActionBlock();
$result = $firewall->updateFirewallRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'970b10321e3f4adda674c912b5f76591',
'5def9c4297e0466cb0736b838345d910',
'http.cookie eq "foo"',
$options,
'Foo'
);
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->id);
}
}

View File

@@ -18,13 +18,14 @@ class IPsTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('ips'), $this->equalTo('ips')
$this->equalTo([])
); );
$ips = new \Cloudflare\API\Endpoints\IPs($mock); $ipsMock = new \Cloudflare\API\Endpoints\IPs($mock);
$ips = $ips->listIPs(); $ips = $ipsMock->listIPs();
$this->assertObjectHasAttribute('ipv4_cidrs', $ips); $this->assertObjectHasAttribute('ipv4_cidrs', $ips);
$this->assertObjectHasAttribute('ipv6_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

@@ -23,7 +23,6 @@ class PageRulesTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'targets' => $target->getArray(), 'targets' => $target->getArray(),
'actions' => $action->getArray(), 'actions' => $action->getArray(),
@@ -36,6 +35,7 @@ class PageRulesTest extends TestCase
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1); $result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
} }
public function testListPageRules() public function testListPageRules()
@@ -49,17 +49,17 @@ class PageRulesTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([ $this->equalTo([
'status' => 'active', 'status' => 'active',
'order' => 'status', 'order' => 'status',
'direction' => 'desc', 'direction' => 'desc',
'match' => 'all' 'match' => 'all'
]), ])
$this->equalTo([])
); );
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all'); $pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id);
} }
public function testGetPageRuleDetails() public function testGetPageRuleDetails()
@@ -72,12 +72,12 @@ class PageRulesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
$this->equalTo([])
); );
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac'); $pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
} }
public function testUpdatePageRule() public function testUpdatePageRule()
@@ -94,8 +94,7 @@ class PageRulesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'targets' => $target->getArray(), 'targets' => $target->getArray(),
'actions' => $action->getArray(), 'actions' => $action->getArray(),
@@ -105,9 +104,10 @@ class PageRulesTest extends TestCase
); );
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1); $result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac', $target, $action, true, 1);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
} }
public function testDeletePageRule() public function testDeletePageRule()
@@ -120,14 +120,13 @@ class PageRulesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('delete') ->method('delete')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
$this->equalTo([]),
$this->equalTo([])
); );
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac'); $result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertTrue($result); $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

@@ -23,7 +23,6 @@ class RailgunTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('railguns'), $this->equalTo('railguns'),
$this->equalTo([]),
$this->equalTo(['name' => $details['name']]) $this->equalTo(['name' => $details['name']])
); );
@@ -35,6 +34,7 @@ class RailgunTest extends TestCase
foreach ($details as $property => $value) { foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $property }, $value); $this->assertEquals($result->result->{ $property }, $value);
} }
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
} }
public function testlist() public function testlist()
@@ -52,8 +52,7 @@ class RailgunTest extends TestCase
'page' => 1, 'page' => 1,
'per_page' => 20, 'per_page' => 20,
'direction' => 'desc' 'direction' => 'desc'
]), ])
$this->equalTo([])
); );
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
@@ -61,6 +60,7 @@ class RailgunTest extends TestCase
$this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result); $this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id);
} }
public function testget() public function testget()
@@ -73,14 +73,14 @@ class RailgunTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'), $this->equalTo('railguns/e928d310693a83094309acf9ead50448')
$this->equalTo([])
); );
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->get('e928d310693a83094309acf9ead50448'); $result = $railgun->get('e928d310693a83094309acf9ead50448');
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
} }
public function testgetZones() public function testgetZones()
@@ -93,9 +93,7 @@ class RailgunTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones'), $this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
$this->equalTo([]),
$this->equalTo([])
); );
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
@@ -103,6 +101,7 @@ class RailgunTest extends TestCase
$this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result); $this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id);
} }
public function testupdate() public function testupdate()
@@ -120,7 +119,6 @@ class RailgunTest extends TestCase
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'), $this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
$this->equalTo([]),
$this->equalTo($details) $this->equalTo($details)
); );
@@ -128,6 +126,7 @@ class RailgunTest extends TestCase
$result = $waf->update('e928d310693a83094309acf9ead50448', true); $result = $waf->update('e928d310693a83094309acf9ead50448', true);
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
} }
public function testdelete() public function testdelete()
@@ -140,12 +139,11 @@ class RailgunTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('delete') ->method('delete')
->with( ->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'), $this->equalTo('railguns/e928d310693a83094309acf9ead50448')
$this->equalTo([]),
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\Railgun($mock); $waf = new \Cloudflare\API\Endpoints\Railgun($mock);
$waf->delete('e928d310693a83094309acf9ead50448'); $waf->delete('e928d310693a83094309acf9ead50448');
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
} }
} }

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

@@ -0,0 +1,161 @@
<?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);
}
public function testUpdateSSLCertificatePackValidationMethod()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLCertificatePackValidationMethod.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification/a77f8bd7-3b47-46b4-a6f1-75cf98109948'),
$this->equalTo(['validation_method' => 'txt'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'txt');
$this->assertTrue($result);
}
}

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

@@ -19,11 +19,10 @@ class UARulesTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([ $this->equalTo([
'page' => 1, 'page' => 1,
'per_page' => 20 'per_page' => 20
]), ])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\UARules($mock); $zones = new \Cloudflare\API\Endpoints\UARules($mock);
@@ -34,6 +33,7 @@ class UARulesTest extends TestCase
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
} }
public function testCreateRule() public function testCreateRule()
@@ -50,7 +50,6 @@ class UARulesTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'mode' => 'js_challenge', 'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -67,6 +66,7 @@ class UARulesTest extends TestCase
'372e67954025e0ba6aaa6d586b9e0b59', '372e67954025e0ba6aaa6d586b9e0b59',
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack' 'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
); );
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
} }
public function getRuleDetails() public function getRuleDetails()
@@ -79,14 +79,14 @@ class UARulesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
$this->equalTo([])
); );
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock); $lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
} }
public function testUpdateRule() public function testUpdateRule()
@@ -103,7 +103,6 @@ class UARulesTest extends TestCase
->method('put') ->method('put')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'mode' => 'js_challenge', 'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -120,6 +119,7 @@ class UARulesTest extends TestCase
$config, $config,
'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', $rules->getBody()->result->id);
} }
public function testDeleteRule() public function testDeleteRule()
@@ -132,12 +132,11 @@ class UARulesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('delete') ->method('delete')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
$this->equalTo([]),
$this->equalTo([])
); );
$rules = new \Cloudflare\API\Endpoints\UARules($mock); $rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
} }
} }

View File

@@ -21,6 +21,7 @@ class UserTest extends TestCase
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id); $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
$this->assertObjectHasAttribute('email', $details); $this->assertObjectHasAttribute('email', $details);
$this->assertEquals('user@example.com', $details->email); $this->assertEquals('user@example.com', $details->email);
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
} }
public function testGetUserID() public function testGetUserID()
@@ -32,6 +33,7 @@ class UserTest extends TestCase
$user = new \Cloudflare\API\Endpoints\User($mock); $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() public function testGetUserEmail()
@@ -45,6 +47,7 @@ class UserTest extends TestCase
$user = new \Cloudflare\API\Endpoints\User($mock); $user = new \Cloudflare\API\Endpoints\User($mock);
$this->assertEquals('user@example.com', $user->getUserEmail()); $this->assertEquals('user@example.com', $user->getUserEmail());
$this->assertEquals('user@example.com', $user->getBody()->result->email);
} }
public function testUpdateUserDetails() public function testUpdateUserDetails()
@@ -56,9 +59,10 @@ class UserTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('patch') ->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 = 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);
} }
} }

View File

@@ -25,8 +25,7 @@ class WAFTest extends TestCase
'match' => 'all', 'match' => 'all',
'order' => 'status', 'order' => 'status',
'direction' => 'desc' 'direction' => 'desc'
]), ])
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
@@ -37,6 +36,7 @@ class WAFTest extends TestCase
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id); $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id);
} }
public function testgetPackageInfo() public function testgetPackageInfo()
@@ -49,14 +49,14 @@ class WAFTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b'); $result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id); $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id);
} }
public function testgetRules() public function testgetRules()
@@ -76,8 +76,7 @@ class WAFTest extends TestCase
'match' => 'all', 'match' => 'all',
'order' => 'status', 'order' => 'status',
'direction' => 'desc' 'direction' => 'desc'
]), ])
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
@@ -88,6 +87,7 @@ class WAFTest extends TestCase
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id); $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id);
} }
public function testgetRuleInfo() public function testgetRuleInfo()
@@ -100,14 +100,14 @@ class WAFTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023'); $result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id); $this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
} }
public function testupdateRule() public function testupdateRule()
@@ -125,7 +125,6 @@ class WAFTest extends TestCase
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
$this->equalTo([]),
$this->equalTo($details) $this->equalTo($details)
); );
@@ -137,6 +136,7 @@ class WAFTest extends TestCase
foreach ($details as $property => $value) { foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value); $this->assertEquals($result->{ $property }, $value);
} }
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
} }
public function getGroups() public function getGroups()
@@ -156,8 +156,7 @@ class WAFTest extends TestCase
'match' => 'all', 'match' => 'all',
'order' => 'status', 'order' => 'status',
'direction' => 'desc' 'direction' => 'desc'
]), ])
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
@@ -168,6 +167,7 @@ class WAFTest extends TestCase
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id); $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id);
} }
public function testgetGroupInfo() public function testgetGroupInfo()
@@ -180,14 +180,14 @@ class WAFTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
$this->equalTo([])
); );
$waf = new \Cloudflare\API\Endpoints\WAF($mock); $waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5'); $result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id); $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
} }
public function testupdateGroup() public function testupdateGroup()
@@ -205,7 +205,6 @@ class WAFTest extends TestCase
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
$this->equalTo([]),
$this->equalTo($details) $this->equalTo($details)
); );
@@ -217,5 +216,6 @@ class WAFTest extends TestCase
foreach ($details as $property => $value) { foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value); $this->assertEquals($result->{ $property }, $value);
} }
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
} }
} }

View File

@@ -0,0 +1,19 @@
<?php
class ZoneDeleteTest extends TestCase
{
public function testDeleteTest()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteZoneTest.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353')
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->deleteZone('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertTrue($result);
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
}
}

View File

@@ -19,11 +19,10 @@ class ZoneLockdownTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([ $this->equalTo([
'page' => 1, 'page' => 1,
'per_page' => 20, 'per_page' => 20,
]), ])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); $zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
@@ -34,6 +33,7 @@ class ZoneLockdownTest extends TestCase
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
} }
public function testAddLockdown() public function testAddLockdown()
@@ -50,7 +50,6 @@ class ZoneLockdownTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'urls' => ['api.mysite.com/some/endpoint*'], 'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -67,6 +66,7 @@ class ZoneLockdownTest extends TestCase
'372e67954025e0ba6aaa6d586b9e0b59', '372e67954025e0ba6aaa6d586b9e0b59',
'Restrict access to these endpoints to requests from a known IP address' 'Restrict access to these endpoints to requests from a known IP address'
); );
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
} }
public function testGetRecordDetails() public function testGetRecordDetails()
@@ -79,14 +79,14 @@ class ZoneLockdownTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
$this->equalTo([])
); );
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); $lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
} }
public function testUpdateLockdown() public function testUpdateLockdown()
@@ -103,7 +103,6 @@ class ZoneLockdownTest extends TestCase
->method('put') ->method('put')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'urls' => ['api.mysite.com/some/endpoint*'], 'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -120,6 +119,7 @@ class ZoneLockdownTest extends TestCase
$config, $config,
'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 testDeleteLockdown() public function testDeleteLockdown()
@@ -135,12 +135,11 @@ class ZoneLockdownTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('delete') ->method('delete')
->with( ->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
$this->equalTo([]),
$this->equalTo([])
); );
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); $zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
} }
} }

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\ZoneSettings;
class ZoneSettingsTest extends TestCase
{
public function testGetServerSideExcludeSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getServerSideExclude.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())->method('get');
$zones = new ZoneSettings($mock);
$result = $zones->getServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertSame('on', $result);
}
public function testUpdateServerSideExcludeSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateServerSideExclude.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())->method('patch');
$zones = new ZoneSettings($mock);
$result = $zones->updateServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353', 'on');
$this->assertSame('on', $result);
}
public function testGetBrowserCacheTtlSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserCacheTtlSetting.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())->method('get');
$zones = new ZoneSettings($mock);
$result = $zones->getBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertSame(14400, $result);
}
public function testUpdateBrowserCacheTtlSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserCacheTtlSetting.json');
$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())->method('patch');
$zones = new ZoneSettings($mock);
$result = $zones->updateBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353', 16070400);
$this->assertTrue($result);
}
}

View File

@@ -19,8 +19,7 @@ class ZonesTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones'), $this->equalTo('zones'),
$this->equalTo([]), $this->equalTo(['name' => 'example.com', 'jump_start' => false])
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
@@ -38,16 +37,16 @@ class ZonesTest extends TestCase
->method('post') ->method('post')
->with( ->with(
$this->equalTo('zones'), $this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo([ $this->equalTo([
'name' => 'example.com', 'name' => 'example.com',
'jumpstart' => true, 'jump_start' => true,
'organization' => (object)['id' => '01a7362d577a6c3019a474fd6f485823'] 'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
]) ])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823'); $zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
} }
public function testActivationTest() public function testActivationTest()
@@ -60,15 +59,14 @@ class ZonesTest extends TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('put') ->method('put')
->with( ->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'), $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check')
$this->equalTo([]),
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
} }
public function testListZones() public function testListZones()
@@ -82,16 +80,15 @@ class ZonesTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones'), $this->equalTo('zones'),
$this->equalTo([ $this->equalTo([
'page' => 1, 'page' => 1,
'per_page' => 20, 'per_page' => 20,
'match' => 'all', 'match' => 'all',
'name' => 'example.com', 'name' => 'example.com',
'status' => 'active', 'status' => 'active',
'order' => 'status', 'order' => 'status',
'direction' => 'desc' 'direction' => 'desc',
]), ])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
@@ -102,6 +99,26 @@ class ZonesTest extends TestCase
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id); $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page); $this->assertEquals(1, $result->result_info->page);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
}
public function testGetZoneByID()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneById.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353'));
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneById('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertInstanceOf(\stdClass::class, $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
$this->assertEquals('example.com', $zones->getBody()->result->name);
} }
public function testGetZoneID() public function testGetZoneID()
@@ -115,19 +132,19 @@ class ZonesTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones'), $this->equalTo('zones'),
$this->equalTo([ $this->equalTo([
'page' => 1, 'page' => 1,
'per_page' => 20, 'per_page' => 20,
'match' => 'all', 'match' => 'all',
'name' => 'example.com', 'name' => 'example.com',
]), ])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneID('example.com'); $result = $zones->getZoneID('example.com');
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result); $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
} }
public function testGetAnalyticsDashboard() public function testGetAnalyticsDashboard()
@@ -141,8 +158,7 @@ class ZonesTest extends TestCase
->method('get') ->method('get')
->with( ->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'), $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)]), $this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)])
$this->equalTo([])
); );
$zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones = new \Cloudflare\API\Endpoints\Zones($mock);
@@ -151,7 +167,7 @@ class ZonesTest extends TestCase
$this->assertObjectHasAttribute('since', $analytics->totals); $this->assertObjectHasAttribute('since', $analytics->totals);
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]); $this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
} }
public function testChangeDevelopmentMode() public function testChangeDevelopmentMode()
{ {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json'); $response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
@@ -163,7 +179,6 @@ class ZonesTest extends TestCase
->method('patch') ->method('patch')
->with( ->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'), $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
$this->equalTo([]),
$this->equalTo(['value' => 'on']) $this->equalTo(['value' => 'on'])
); );
@@ -171,6 +186,7 @@ class ZonesTest extends TestCase
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals('development_mode', $zones->getBody()->result->id);
} }
public function testCachePurgeEverything() public function testCachePurgeEverything()
@@ -178,13 +194,12 @@ class ZonesTest extends TestCase
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json'); $response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response); $mock->method('post')->willReturn($response);
$mock->expects($this->once()) $mock->expects($this->once())
->method('delete') ->method('post')
->with( ->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'), $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo([]),
$this->equalTo(['purge_everything' => true]) $this->equalTo(['purge_everything' => true])
); );
@@ -192,5 +207,59 @@ class ZonesTest extends TestCase
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result); $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('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->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('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->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,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

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

View File

@@ -0,0 +1,17 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "12341234123412341234",
"certificate": "some-cert-data-foofoo",
"hostnames": [
"foo.example.com",
"bar.example.com"
],
"expires_on": "2014-01-01T05:20:00.12345Z",
"request_type": "origin-ecc",
"requested_validity": 365,
"csr": "some-csr-data-barbar"
}
}

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,20 @@
{
"result": [
{
"id": "970b10321e3f4adda674c912b5f76591",
"paused": false,
"description": "Foobar",
"action": "block",
"filter": {
"id": "70f39827184d487e97cc286b960f4cc3",
"expression": "http.cookie eq \"foobar\"",
"paused": false
},
"created_on": "2019-07-05T15:53:15Z",
"modified_on": "2019-07-05T15:53:15Z"
}
],
"success": true,
"errors": [],
"messages": []
}

View File

@@ -0,0 +1,33 @@
{
"result": [
{
"id": "970b10321e3f4adda674c912b5f76591",
"paused": false,
"description": "Foo",
"action": "block",
"filter": {
"id": "70f39827184d487e97cc286b960f4cc3",
"expression": "http.cookie eq \"foo\"",
"paused": false
},
"created_on": "2019-07-05T15:53:15Z",
"modified_on": "2019-07-05T15:53:15Z"
},
{
"id": "42c05fd0e0af4d17a361d2d1423476bc",
"paused": false,
"description": "Bar",
"action": "block",
"filter": {
"id": "246b4d9f5f51471485bdc95e1c6b53a7",
"expression": "http.cookie eq \"bar\"",
"paused": false
},
"created_on": "2019-07-05T15:53:15Z",
"modified_on": "2019-07-05T15:53:15Z"
}
],
"success": true,
"errors": [],
"messages": []
}

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,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,8 @@
{
"result": {
"id": "970b10321e3f4adda674c912b5f76591"
},
"success": true,
"errors": [],
"messages": []
}

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,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "4536bcfad5faccb111b47003c79917fa"
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "browser_cache_ttl",
"value": 14400,
"editable": true,
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,11 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "browser_check",
"value": "on",
"editable": true,
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,17 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "6666699999996666699999999966666666",
"certificate": "some-cert-data-foobar",
"hostnames": [
"foo.example.com",
"bar.example.com"
],
"expires_on": "2014-01-01T05:20:00.12345Z",
"request_type": "origin-ecc",
"requested_validity": 5475,
"csr": "some-csr-data-foobar"
}
}

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