Add changing TLS Zone Settings capability

This commit is contained in:
Marlin-Ops.com - Jurgen Coetsiers
2018-10-21 16:02:42 +02:00
parent c1193f7f91
commit 4e17cc8984
3 changed files with 49 additions and 6 deletions

View File

@@ -19,11 +19,11 @@ class TLS implements API
$this->adapter = $adapter;
}
public function enableTLS13($zoneID, $enable=false)
public function enableTLS13($zoneID)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_1_3',
['value' => $enable ? 'on' : 'off']
['value' => 'on']
);
$body = json_decode($return->getBody());
@@ -34,6 +34,23 @@ class TLS implements API
return false;
}
public function disableTLS13($zoneID)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_1_3',
['value' => 'off']
);
$body = json_decode($return->getBody());
if ($body->success) {
return true;
}
return false;
}
public function changeMinimumTLSVersion($zoneID, $minimumVersion)
{
$return = $this->adapter->patch(

View File

@@ -23,8 +23,28 @@ class TLSTest extends TestCase
$this->equalTo(['value' => 'on'])
);
$ZoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $ZoneTLSSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $zoneTLSSettings->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'])
);
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $zoneTLSSettings->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result);
}
@@ -43,8 +63,8 @@ class TLSTest extends TestCase
$this->equalTo(['value' => '1.1'])
);
$ZoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $ZoneTLSSettings->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $zoneTLSSettings->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
$this->assertTrue($result);
}

View File

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