diff --git a/src/Endpoints/Crypto.php b/src/Endpoints/Crypto.php index a5a03f3..94df3bb 100644 --- a/src/Endpoints/Crypto.php +++ b/src/Endpoints/Crypto.php @@ -13,42 +13,6 @@ class Crypto implements API $this->adapter = $adapter; } - /** - * Get the SSL setting for the zone - * - * @param string $zoneID The ID of the zone - * @return string|false - */ - public function getSSLSetting(string $zoneID) - { - $return = $this->adapter->get( - 'zones/' . $zoneID . '/settings/ssl' - ); - $body = json_decode($return->getBody()); - if (isset($body->result)) { - return $body->result->value; - } - return false; - } - - /** - * Get SSL Verification Info for a Zone - * - * @param string $zoneID The ID of the zone - * @return array|false - */ - public function getSSLVerificationStatus(string $zoneID) - { - $return = $this->adapter->get( - 'zones/' . $zoneID . '/ssl/verification' - ); - $body = json_decode($return->getBody()); - if (isset($body->result)) { - return $body; - } - return false; - } - /** * Get the Opportunistic Encryption feature for a zone. * @@ -85,108 +49,6 @@ class Crypto implements API 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 Oppurtunistic Encryption setting for the zone * diff --git a/src/Endpoints/SSL.php b/src/Endpoints/SSL.php new file mode 100644 index 0000000..50d56b3 --- /dev/null +++ b/src/Endpoints/SSL.php @@ -0,0 +1,154 @@ +adapter = $adapter; + } + + /** + * Get the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getSSLSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/ssl' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result->value; + } + return false; + } + + /** + * Get SSL Verification Info for a Zone + * + * @param string $zoneID The ID of the zone + * @return array|false + */ + public function getSSLVerificationStatus(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/ssl/verification' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body; + } + return false; + } + + /** + * Get the HTTPS Redirect setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getHTTPSRedirectSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/always_use_https' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Get the HTTPS Rewrite setting for the zone + * + * @param string $zoneID The ID of the zone + * @return string|false + */ + public function getHTTPSRewritesSetting(string $zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites' + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Update the SSL setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateSSLSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/ssl', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the HTTPS Redirect setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRedirectSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/always_use_https', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + + /** + * Update the HTTPS Rewrite setting for the zone + * + * @param string $zoneID The ID of the zone + * @param string $value The value of the zone setting + * @return bool + */ + public function updateHTTPSRewritesSetting(string $zoneID, string $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/automatic_https_rewrites', + [ + 'value' => $value, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->success) && $body->success == true) { + return true; + } + return false; + } + +} diff --git a/tests/Endpoints/CryptoTest.php b/tests/Endpoints/CryptoTest.php index 5019308..a798dc1 100644 --- a/tests/Endpoints/CryptoTest.php +++ b/tests/Endpoints/CryptoTest.php @@ -2,44 +2,6 @@ class CryptoTest 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') - ); - - $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock); - $result = $cryptoMock->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') - ); - - $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() { @@ -79,104 +41,6 @@ class CryptoTest extends TestCase $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() - { - $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']) - ); - - $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'); diff --git a/tests/Endpoints/SSLTest.php b/tests/Endpoints/SSLTest.php new file mode 100644 index 0000000..2f0ca62 --- /dev/null +++ b/tests/Endpoints/SSLTest.php @@ -0,0 +1,142 @@ +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); + } + +}