Skip to content

Commit 99e8b97

Browse files
Implement SSL certificates install/remove procedures
Co-authored-by: Bobi <[email protected]>
1 parent 5cdd09c commit 99e8b97

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

src/Api/Operator/Certificate.php

+34
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,38 @@ public function generate(array $properties): Struct\Info
2020

2121
return new Struct\Info($response);
2222
}
23+
24+
public function install(array $properties, string $request, string $privateKey): bool
25+
{
26+
$packet = $this->client->getPacket();
27+
28+
$installTag = $packet->addChild($this->wrapperTag)->addChild('install');
29+
foreach ($properties as $name => $value) {
30+
$installTag->{$name} = $value;
31+
}
32+
33+
$contentTag = $installTag->addChild('content');
34+
$contentTag->addChild('csr', $request);
35+
$contentTag->addChild('pvt', $privateKey);
36+
37+
$result = $this->client->request($packet);
38+
39+
return 'ok' == (string) $result->status;
40+
}
41+
42+
public function delete(string $name, array $properties): bool
43+
{
44+
$packet = $this->client->getPacket();
45+
46+
$removeTag = $packet->addChild($this->wrapperTag)->addChild('remove');
47+
$removeTag->addChild('filter')->addChild('name', $name);
48+
49+
foreach ($properties as $name => $value) {
50+
$removeTag->{$name} = $value;
51+
}
52+
53+
$result = $this->client->request($packet);
54+
55+
return 'ok' == (string) $result->status;
56+
}
2357
}

tests/CertificateTest.php

+37-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,48 @@
55

66
class CertificateTest extends AbstractTestCase
77
{
8+
private array $certificateProperties = [
9+
'bits' => 2048,
10+
'country' => 'CH',
11+
'state' => 'Schaffhausen',
12+
'location' => 'Schaffhausen',
13+
'company' => 'Plesk',
14+
'email' => '[email protected]',
15+
'name' => 'plesk.com',
16+
];
17+
818
public function testGenerate()
919
{
10-
$certificate = static::$client->certificate()->generate([
11-
'bits' => 2048,
12-
'country' => 'RU',
13-
'state' => 'NSO',
14-
'location' => 'Novosibirsk',
15-
'company' => 'Plesk',
16-
'email' => '[email protected]',
17-
'name' => 'plesk.com',
18-
]);
20+
$certificate = static::$client->certificate()->generate($this->certificateProperties);
1921
$this->assertGreaterThan(0, strlen($certificate->request));
2022
$this->assertStringStartsWith('-----BEGIN CERTIFICATE REQUEST-----', $certificate->request);
2123
$this->assertGreaterThan(0, strlen($certificate->privateKey));
2224
$this->assertStringStartsWith('-----BEGIN PRIVATE KEY-----', $certificate->privateKey);
2325
}
26+
27+
public function testInstall()
28+
{
29+
$certificate = static::$client->certificate()->generate($this->certificateProperties);
30+
31+
$result = static::$client->certificate()->install([
32+
'name' => 'test',
33+
'admin' => true,
34+
], $certificate->request, $certificate->privateKey);
35+
$this->assertTrue($result);
36+
37+
static::$client->certificate()->delete('test', ['admin' => true]);
38+
}
39+
40+
public function testDelete()
41+
{
42+
$certificate = static::$client->certificate()->generate($this->certificateProperties);
43+
44+
static::$client->certificate()->install([
45+
'name' => 'test',
46+
'admin' => true,
47+
], $certificate->request, $certificate->privateKey);
48+
49+
$result = static::$client->certificate()->delete('test', ['admin' => true]);
50+
$this->assertTrue($result);
51+
}
2452
}

0 commit comments

Comments
 (0)