diff --git a/src/Endpoints/Crypto.php b/src/Endpoints/Crypto.php index faf30c1..a5a03f3 100644 --- a/src/Endpoints/Crypto.php +++ b/src/Endpoints/Crypto.php @@ -19,13 +19,13 @@ class Crypto implements API * @param string $zoneID The ID of the zone * @return string|false */ - public function getSSLSetting($zoneID) + public function getSSLSetting(string $zoneID) { $return = $this->adapter->get( 'zones/' . $zoneID . '/settings/ssl' ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->result)) { return $body->result->value; } return false; @@ -37,13 +37,13 @@ class Crypto implements API * @param string $zoneID The ID of the zone * @return array|false */ - public function getSSLVerificationStatus($zoneID) + public function getSSLVerificationStatus(string $zoneID) { $return = $this->adapter->get( 'zones/' . $zoneID . '/ssl/verification' ); $body = json_decode($return->getBody()); - if ($body->result) { + if (isset($body->result)) { return $body; } return false; @@ -55,13 +55,13 @@ class Crypto implements API * @param string $zoneID The ID of the zone * @return string|false */ - public function getOpportunisticEncryptionSetting($zoneID) + public function getOpportunisticEncryptionSetting(string $zoneID) { $return = $this->adapter->get( 'zones/' . $zoneID . '/settings/opportunistic_encryption' ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->result)) { return $body->result->value; } return false; @@ -73,38 +73,50 @@ class Crypto implements API * @param string $zoneID The ID of the zone * @return string|false */ - public function getOnionRoutingSetting($zoneID) + public function getOnionRoutingSetting(string $zoneID) { $return = $this->adapter->get( 'zones/' . $zoneID . '/settings/opportunistic_onion' ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->result)) { return $body->result; } return false; } - public function getHTTPSRedirectSetting($zoneID) + /** + * 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 ($body->success) { - return $body->result->value; + if (isset($body->result)) { + return $body->result; } return false; } - public function getHTTPSRewritesSetting($zoneID) + /** + * 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 ($body->success) { - return $body->result->value; + if (isset($body->result)) { + return $body->result; } return false; } @@ -116,7 +128,7 @@ class Crypto implements API * @param string $value The value of the zone setting * @return bool */ - public function updateSSLSetting($zoneID, $value) + public function updateSSLSetting(string $zoneID, string $value) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/ssl', @@ -125,7 +137,7 @@ class Crypto implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -138,7 +150,7 @@ class Crypto implements API * @param string $value The value of the zone setting * @return bool */ - public function updateHTTPSRedirectSetting($zoneID, $value) + public function updateHTTPSRedirectSetting(string $zoneID, string $value) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/always_use_https', @@ -147,7 +159,7 @@ class Crypto implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -160,7 +172,7 @@ class Crypto implements API * @param string $value The value of the zone setting * @return bool */ - public function updateHTTPSRewritesSetting($zoneID, $value) + public function updateHTTPSRewritesSetting(string $zoneID, string $value) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/automatic_https_rewrites', @@ -169,7 +181,7 @@ class Crypto implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -182,7 +194,7 @@ class Crypto implements API * @param string $value The value of the zone setting * @return bool */ - public function updateOpportunisticEncryptionSetting($zoneID, $value) + public function updateOpportunisticEncryptionSetting(string $zoneID, string $value) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/opportunistic_encryption', @@ -191,7 +203,7 @@ class Crypto implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -204,7 +216,7 @@ class Crypto implements API * @param string $value The value of the zone setting * @return bool */ - public function updateOnionRoutingSetting($zoneID, $value) + public function updateOnionRoutingSetting(string $zoneID, string $value) { $return = $this->adapter->patch( 'zones/' . $zoneID . '/settings/opportunistic_onion', @@ -213,7 +225,7 @@ class Crypto implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; diff --git a/src/Endpoints/TLS.php b/src/Endpoints/TLS.php index 6b8bc1f..b6ca671 100644 --- a/src/Endpoints/TLS.php +++ b/src/Endpoints/TLS.php @@ -31,7 +31,7 @@ class TLS implements API 'zones/' . $zoneID . '/settings/tls_client_auth' ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->result)) { return $body->result->value; } return false; @@ -50,7 +50,7 @@ class TLS implements API ['value' => 'on'] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -69,7 +69,7 @@ class TLS implements API ['value' => 'off'] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -91,7 +91,7 @@ class TLS implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; @@ -113,7 +113,7 @@ class TLS implements API ] ); $body = json_decode($return->getBody()); - if ($body->success) { + if (isset($body->success) && $body->success == true) { return true; } return false; diff --git a/tests/Endpoints/CryptoTest.php b/tests/Endpoints/CryptoTest.php index 84c0110..5019308 100644 --- a/tests/Endpoints/CryptoTest.php +++ b/tests/Endpoints/CryptoTest.php @@ -15,8 +15,8 @@ class CryptoTest extends TestCase $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl') ); - $zoneSSLSetting = new \Cloudflare\API\Endpoints\Crypto($mock); - $result = $zoneSSLSetting->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertEquals('off', $result); } @@ -34,17 +34,88 @@ class CryptoTest extends TestCase $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification') ); - $zoneVerificationStatus = new \Cloudflare\API\Endpoints\Crypto($mock); - $result = $zoneVerificationStatus->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertObjectHasAttribute('result', $result); $this->assertEquals('active', $result->result{0}->certificate_status); } + 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 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') + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->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') + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } public function testUpdateSSLSetting() { @@ -60,11 +131,90 @@ class CryptoTest extends TestCase $this->equalTo(['value' => 'full']) ); - $zoneSSLSetting = new \Cloudflare\API\Endpoints\Crypto($mock); - $result = $zoneSSLSetting->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full'); + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->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']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->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']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } + + public function testUpdateOpportunisticEncryptionSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption'), + $this->equalTo(['value' => 'off']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } + + public function testUpdateOnionRoutingSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion'), + $this->equalTo(['value' => 'off']) + ); + + $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); + + $this->assertTrue($result); + } } diff --git a/tests/Endpoints/TLSTest.php b/tests/Endpoints/TLSTest.php index d17aabb..cf0018c 100644 --- a/tests/Endpoints/TLSTest.php +++ b/tests/Endpoints/TLSTest.php @@ -9,6 +9,25 @@ class TLSTest extends TestCase { + public function testGetTLSClientAuth() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getTLSClientAuth.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth') + ); + + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->getTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + public function testEnableTLS13() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/enableTLS13.json'); @@ -23,8 +42,8 @@ class TLSTest extends TestCase $this->equalTo(['value' => 'on']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); } @@ -43,8 +62,8 @@ class TLSTest extends TestCase $this->equalTo(['value' => 'off']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); } @@ -63,8 +82,28 @@ class TLSTest extends TestCase $this->equalTo(['value' => '1.1']) ); - $zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock); - $result = $zoneTLSSettings->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1'); + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1'); + + $this->assertTrue($result); + } + + public function testUpdateTLSClientAuth() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateTLSClientAuth.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth'), + $this->equalTo(['value' => 'off']) + ); + + $tlsMock = new \Cloudflare\API\Endpoints\TLS($mock); + $result = $tlsMock->updateTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off'); $this->assertTrue($result); } diff --git a/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json b/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json b/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getOnionRoutingSetting.json b/tests/Fixtures/Endpoints/getOnionRoutingSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/getOnionRoutingSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json b/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json new file mode 100644 index 0000000..b5df0a4 --- /dev/null +++ b/tests/Fixtures/Endpoints/getOpportunisticEncryptionSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "opportunistic_encryption", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getTLSClientAuth.json b/tests/Fixtures/Endpoints/getTLSClientAuth.json new file mode 100644 index 0000000..fac9fa5 --- /dev/null +++ b/tests/Fixtures/Endpoints/getTLSClientAuth.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "tls_client_auth", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json b/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateHTTPSRedirectSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json b/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateHTTPSRewritesSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json b/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateOnionRoutingSetting.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json b/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json new file mode 100644 index 0000000..e8077c9 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateOpportunisticEncryptionSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "opportunistic_encryption", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateTLSClientAuth.json b/tests/Fixtures/Endpoints/updateTLSClientAuth.json new file mode 100644 index 0000000..fac9fa5 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateTLSClientAuth.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "tls_client_auth", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file