forked from plesk/api-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecretKeyTest.php
102 lines (83 loc) · 3.1 KB
/
SecretKeyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
// Copyright 1999-2022. Plesk International GmbH.
namespace PleskXTest;
use PleskX\Api\Exception;
class SecretKeyTest extends AbstractTestCase
{
public function testCreate()
{
$keyId = static::$client->secretKey()->create('192.168.0.1');
$this->assertMatchesRegularExpression(
'/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
$keyId
);
static::$client->secretKey()->delete($keyId);
}
public function testCreateAutoIp()
{
$keyId = static::$client->secretKey()->create();
$this->assertNotEmpty($keyId);
static::$client->secretKey()->delete($keyId);
}
public function testCreateMultiIps()
{
$keyId = static::$client->secretKey()->create(join(',', ['192.168.0.1', '192.168.0.2']));
$this->assertMatchesRegularExpression(
'/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
$keyId
);
static::$client->secretKey()->delete($keyId);
}
public function testCreateWithDescription()
{
$keyId = static::$client->secretKey()->create('192.168.0.1', 'test key');
$keyInfo = static::$client->secretKey()->get($keyId);
$this->assertEquals('test key', $keyInfo->description);
static::$client->secretKey()->delete($keyId);
}
public function testGet()
{
$keyId = static::$client->secretKey()->create('192.168.0.1');
$keyInfo = static::$client->secretKey()->get($keyId);
$this->assertNotEmpty($keyInfo->key);
$this->assertEquals('192.168.0.1', $keyInfo->ipAddress);
$this->assertEquals('admin', $keyInfo->login);
static::$client->secretKey()->delete($keyId);
}
public function testGetAll()
{
$keyIds = [];
$keyIds[] = static::$client->secretKey()->create('192.168.0.1');
$keyIds[] = static::$client->secretKey()->create('192.168.0.2');
$keys = static::$client->secretKey()->getAll();
$this->assertGreaterThanOrEqual(2, count($keys));
$keyIpAddresses = array_map(function ($key) {
return $key->ipAddress;
}, $keys);
$this->assertContains('192.168.0.1', $keyIpAddresses);
$this->assertContains('192.168.0.2', $keyIpAddresses);
foreach ($keyIds as $keyId) {
static::$client->secretKey()->delete($keyId);
}
}
public function testDelete()
{
$keyId = static::$client->secretKey()->create('192.168.0.1');
static::$client->secretKey()->delete($keyId);
try {
static::$client->secretKey()->get($keyId);
$this->fail("Secret key $keyId was not deleted.");
} catch (Exception $exception) {
$this->assertEquals(1013, $exception->getCode());
}
}
public function testListEmpty()
{
$keys = static::$client->secretKey()->getAll();
foreach ($keys as $key) {
static::$client->secretKey()->delete($key->key);
}
$keys = static::$client->secretKey()->getAll();
$this->assertEquals(0, count($keys));
}
}