From 58ba140930f71fdd42462944e8aeec9de3abae5b Mon Sep 17 00:00:00 2001 From: Jens Beltofte Date: Thu, 12 Sep 2019 14:50:24 +0200 Subject: [PATCH 1/2] Add method to change SSL certificate pack validation method --- src/Endpoints/SSL.php | 23 +++++++++++++++++++ tests/Endpoints/SSLTest.php | 20 ++++++++++++++++ ...ateSSLCertificatePackValidationMethod.json | 6 +++++ 3 files changed, 49 insertions(+) create mode 100644 tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json diff --git a/src/Endpoints/SSL.php b/src/Endpoints/SSL.php index fea524b..d1dea20 100644 --- a/src/Endpoints/SSL.php +++ b/src/Endpoints/SSL.php @@ -150,4 +150,27 @@ class SSL implements API } 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; + } } diff --git a/tests/Endpoints/SSLTest.php b/tests/Endpoints/SSLTest.php index b29a97e..bfbaf66 100644 --- a/tests/Endpoints/SSLTest.php +++ b/tests/Endpoints/SSLTest.php @@ -138,4 +138,24 @@ class SSLTest extends TestCase $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' => 'cname']) + ); + + $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'cname'); + + $this->assertTrue($result); + } } diff --git a/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json new file mode 100644 index 0000000..878457d --- /dev/null +++ b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json @@ -0,0 +1,6 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": "off" +} \ No newline at end of file From 1211b644e024ada87e3bf491c0712fca4cffb50a Mon Sep 17 00:00:00 2001 From: Jens Beltofte Date: Thu, 12 Sep 2019 15:10:22 +0200 Subject: [PATCH 2/2] Change validation method to txt as in the CF API documentation + change response json file --- tests/Endpoints/SSLTest.php | 4 ++-- .../Endpoints/updateSSLCertificatePackValidationMethod.json | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Endpoints/SSLTest.php b/tests/Endpoints/SSLTest.php index bfbaf66..1f0fc53 100644 --- a/tests/Endpoints/SSLTest.php +++ b/tests/Endpoints/SSLTest.php @@ -150,11 +150,11 @@ class SSLTest extends TestCase ->method('patch') ->with( $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification/a77f8bd7-3b47-46b4-a6f1-75cf98109948'), - $this->equalTo(['validation_method' => 'cname']) + $this->equalTo(['validation_method' => 'txt']) ); $sslMock = new \Cloudflare\API\Endpoints\SSL($mock); - $result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'cname'); + $result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'txt'); $this->assertTrue($result); } diff --git a/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json index 878457d..5e2d5e2 100644 --- a/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json +++ b/tests/Fixtures/Endpoints/updateSSLCertificatePackValidationMethod.json @@ -2,5 +2,8 @@ "success": true, "errors": [], "messages": [], - "result": "off" + "result": { + "validation_method": "txt", + "status": "pending_validation" + } } \ No newline at end of file