1
|
|
|
<?php |
2
|
|
|
namespace LE_ACME2Tests; |
3
|
|
|
|
4
|
|
|
use LE_ACME2\Exception\InvalidResponse; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @covers \LE_ACME2\Account |
8
|
|
|
*/ |
9
|
|
|
class AccountTest extends AbstractLeAcme2TestCase { |
10
|
|
|
|
11
|
|
|
private $_commonKeyDirectoryPath; |
12
|
|
|
|
13
|
|
|
public function __construct(string $name) { |
14
|
|
|
parent::__construct($name); |
15
|
|
|
|
16
|
|
|
$this->_commonKeyDirectoryPath = TestHelper::getInstance()->getTempPath() . 'le-storage/'; |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testNonExistingCommonKeyDirectoryPath() { |
20
|
|
|
|
21
|
|
|
$this->assertTrue(\LE_ACME2\Account::getCommonKeyDirectoryPath() === null); |
22
|
|
|
|
23
|
|
|
$notExistingPath = TestHelper::getInstance()->getTempPath() . 'should-not-exist/'; |
24
|
|
|
|
25
|
|
|
$this->catchExpectedException( |
26
|
|
|
\RuntimeException::class, |
27
|
|
|
function() use($notExistingPath) { |
28
|
|
|
\LE_ACME2\Account::setCommonKeyDirectoryPath($notExistingPath); |
29
|
|
|
} |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testCommonKeyDirectoryPath() { |
34
|
|
|
|
35
|
|
|
if(!file_exists($this->_commonKeyDirectoryPath)) { |
36
|
|
|
mkdir($this->_commonKeyDirectoryPath); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
\LE_ACME2\Account::setCommonKeyDirectoryPath($this->_commonKeyDirectoryPath); |
40
|
|
|
|
41
|
|
|
$this->assertTrue( |
42
|
|
|
\LE_ACME2\Account::getCommonKeyDirectoryPath() === $this->_commonKeyDirectoryPath |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testNonExisting() { |
47
|
|
|
|
48
|
|
|
if(\LE_ACME2\Account::exists($this->_accountEmail)) { |
49
|
|
|
$this->markTestSkipped('Skipped: Account does already exist'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
53
|
|
|
|
54
|
|
|
$this->catchExpectedException( |
55
|
|
|
\RuntimeException::class, |
56
|
|
|
function() { |
57
|
|
|
\LE_ACME2\Account::get($this->_accountEmail); |
58
|
|
|
} |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testCreate() { |
64
|
|
|
|
65
|
|
|
if(\LE_ACME2\Account::exists($this->_accountEmail)) { |
66
|
|
|
// Skipping account modification tests, when the account already exists |
67
|
|
|
// to reduce the LE api usage while developing |
68
|
|
|
TestHelper::getInstance()->setSkipAccountModificationTests(true); |
|
|
|
|
69
|
|
|
$this->markTestSkipped('Account modifications skipped: Account does already exist'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
73
|
|
|
|
74
|
|
|
$account = \LE_ACME2\Account::create($this->_accountEmail); |
75
|
|
|
$this->assertTrue(is_object($account)); |
76
|
|
|
$this->assertTrue($account->getEmail() === $this->_accountEmail); |
77
|
|
|
|
78
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
79
|
|
|
$this->assertTrue(is_object($account)); |
80
|
|
|
|
81
|
|
|
$result = $account->getData(); |
82
|
|
|
$this->assertTrue($result->getStatus() === \LE_ACME2\Response\Account\AbstractAccount::STATUS_VALID); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testInvalidCreate() { |
86
|
|
|
|
87
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
|
|
|
|
88
|
|
|
$this->expectNotToPerformAssertions(); |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$e = $this->catchExpectedException( |
93
|
|
|
InvalidResponse::class, |
94
|
|
|
function() { |
95
|
|
|
\LE_ACME2\Account::create('test_php' . phpversion() . '@example.org'); |
96
|
|
|
} |
97
|
|
|
); |
98
|
|
|
$this->assertEquals( |
99
|
|
|
'Invalid response received: ' . |
100
|
|
|
'urn:ietf:params:acme:error:invalidContact' . |
101
|
|
|
' - ' . |
102
|
|
|
'Error creating new account :: contact email has forbidden domain "example.org"', |
103
|
|
|
$e->getMessage(), |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testModification() { |
108
|
|
|
|
109
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
110
|
|
|
$this->expectNotToPerformAssertions(); |
111
|
|
|
return; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
115
|
|
|
$this->assertTrue(is_object($account)); |
116
|
|
|
|
117
|
|
|
$keyDirectoryPath = $account->getKeyDirectoryPath(); |
118
|
|
|
$newEmail = 'new-' . $this->_accountEmail; |
119
|
|
|
|
120
|
|
|
// An email from example.org is not allowed |
121
|
|
|
$result = $account->update('[email protected]'); |
122
|
|
|
$this->assertTrue($result === false); |
123
|
|
|
|
124
|
|
|
$result = $account->update($newEmail); |
125
|
|
|
$this->assertTrue($result === true); |
126
|
|
|
|
127
|
|
|
$this->assertTrue($account->getKeyDirectoryPath() !== $keyDirectoryPath); |
128
|
|
|
$this->assertTrue(file_exists($account->getKeyDirectoryPath())); |
129
|
|
|
|
130
|
|
|
$result = $account->update($this->_accountEmail); |
131
|
|
|
$this->assertTrue($result === true); |
132
|
|
|
|
133
|
|
|
$result = $account->changeKeys(); |
134
|
|
|
$this->assertTrue($result === true); |
135
|
|
|
|
136
|
|
|
// 11. August 2022 |
137
|
|
|
// Quickfix: The LE server will not recognize fast enough, that the account key has already changed |
138
|
|
|
sleep(5); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testDeactivation() { |
142
|
|
|
|
143
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
144
|
|
|
$this->expectNotToPerformAssertions(); |
145
|
|
|
return; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
149
|
|
|
$this->assertTrue(is_object($account)); |
150
|
|
|
|
151
|
|
|
$result = $account->deactivate(); |
152
|
|
|
$this->assertTrue($result === true); |
153
|
|
|
|
154
|
|
|
// 11. August 2022 |
155
|
|
|
// Quickfix: The LE server will not recognize fast enough, that the account is already deactivated |
156
|
|
|
sleep(5); |
157
|
|
|
|
158
|
|
|
// The account is already deactivated |
159
|
|
|
$result = $account->deactivate(); |
160
|
|
|
$this->assertTrue($result === false); |
161
|
|
|
|
162
|
|
|
// The account is already deactivated |
163
|
|
|
$result = $account->changeKeys(); |
164
|
|
|
$this->assertTrue($result === false); |
165
|
|
|
|
166
|
|
|
// The account is already deactivated |
167
|
|
|
$this->catchExpectedException( |
168
|
|
|
\LE_ACME2\Exception\InvalidResponse::class, |
169
|
|
|
function() use($account) { |
170
|
|
|
$account->getData(); |
171
|
|
|
} |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testCreationAfterDeactivation() { |
176
|
|
|
|
177
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
178
|
|
|
$this->expectNotToPerformAssertions(); |
179
|
|
|
return; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
183
|
|
|
$this->assertTrue(is_object($account)); |
184
|
|
|
|
185
|
|
|
system('rm -R ' . $account->getKeyDirectoryPath()); |
186
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
187
|
|
|
|
188
|
|
|
$account = \LE_ACME2\Account::create($this->_accountEmail); |
189
|
|
|
$this->assertTrue(is_object($account)); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function test() { |
193
|
|
|
|
194
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
195
|
|
|
$this->assertTrue(is_object($account)); |
196
|
|
|
} |
197
|
|
|
} |