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 AbstractTest { |
10
|
|
|
|
11
|
|
|
private $_commonKeyDirectoryPath; |
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
parent::__construct(); |
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->expectException(\RuntimeException::class); |
26
|
|
|
|
27
|
|
|
\LE_ACME2\Account::setCommonKeyDirectoryPath($notExistingPath); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testCommonKeyDirectoryPath() { |
31
|
|
|
|
32
|
|
|
if(!file_exists($this->_commonKeyDirectoryPath)) { |
33
|
|
|
mkdir($this->_commonKeyDirectoryPath); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
\LE_ACME2\Account::setCommonKeyDirectoryPath($this->_commonKeyDirectoryPath); |
37
|
|
|
|
38
|
|
|
$this->assertTrue( |
39
|
|
|
\LE_ACME2\Account::getCommonKeyDirectoryPath() === $this->_commonKeyDirectoryPath |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testNonExisting() { |
44
|
|
|
|
45
|
|
|
if(\LE_ACME2\Account::exists($this->_accountEmail)) { |
46
|
|
|
$this->markTestSkipped('Skipped: Account does already exist'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
50
|
|
|
|
51
|
|
|
$this->expectException(\RuntimeException::class); |
52
|
|
|
\LE_ACME2\Account::get($this->_accountEmail); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCreate() { |
56
|
|
|
|
57
|
|
|
if(\LE_ACME2\Account::exists($this->_accountEmail)) { |
58
|
|
|
// Skipping account modification tests, when the account already exists |
59
|
|
|
// to reduce the LE api usage while developing |
60
|
|
|
TestHelper::getInstance()->setSkipAccountModificationTests(true); |
|
|
|
|
61
|
|
|
$this->markTestSkipped('Account modifications skipped: Account does already exist'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
65
|
|
|
|
66
|
|
|
$account = \LE_ACME2\Account::create($this->_accountEmail); |
67
|
|
|
$this->assertTrue(is_object($account)); |
68
|
|
|
$this->assertTrue($account->getEmail() === $this->_accountEmail); |
69
|
|
|
|
70
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
71
|
|
|
$this->assertTrue(is_object($account)); |
72
|
|
|
|
73
|
|
|
$result = $account->getData(); |
74
|
|
|
$this->assertTrue($result->getStatus() === \LE_ACME2\Response\Account\AbstractAccount::STATUS_VALID); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testInvalidCreate() { |
78
|
|
|
|
79
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
|
|
|
|
80
|
|
|
$this->expectNotToPerformAssertions(); |
81
|
|
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->expectException(InvalidResponse::class); |
85
|
|
|
$this->expectExceptionMessage( |
86
|
|
|
'Invalid response received: ' . |
87
|
|
|
'urn:ietf:params:acme:error:invalidEmail' . |
88
|
|
|
' - ' . |
89
|
|
|
'Error creating new account :: invalid contact domain. Contact emails @example.org are forbidden' |
90
|
|
|
); |
91
|
|
|
\LE_ACME2\Account::create('[email protected]'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testModification() { |
95
|
|
|
|
96
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
97
|
|
|
$this->expectNotToPerformAssertions(); |
98
|
|
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
102
|
|
|
$this->assertTrue(is_object($account)); |
103
|
|
|
|
104
|
|
|
$keyDirectoryPath = $account->getKeyDirectoryPath(); |
105
|
|
|
$newEmail = 'new-' . $this->_accountEmail; |
106
|
|
|
|
107
|
|
|
// An email from example.org is not allowed |
108
|
|
|
$result = $account->update('[email protected]'); |
109
|
|
|
$this->assertTrue($result === false); |
110
|
|
|
|
111
|
|
|
$result = $account->update($newEmail); |
112
|
|
|
$this->assertTrue($result === true); |
113
|
|
|
|
114
|
|
|
$this->assertTrue($account->getKeyDirectoryPath() !== $keyDirectoryPath); |
115
|
|
|
$this->assertTrue(file_exists($account->getKeyDirectoryPath())); |
116
|
|
|
|
117
|
|
|
$result = $account->update($this->_accountEmail); |
118
|
|
|
$this->assertTrue($result === true); |
119
|
|
|
|
120
|
|
|
$result = $account->changeKeys(); |
121
|
|
|
$this->assertTrue($result === true); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testDeactivation() { |
125
|
|
|
|
126
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
127
|
|
|
$this->expectNotToPerformAssertions(); |
128
|
|
|
return; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
132
|
|
|
$this->assertTrue(is_object($account)); |
133
|
|
|
|
134
|
|
|
$result = $account->deactivate(); |
135
|
|
|
$this->assertTrue($result === true); |
136
|
|
|
|
137
|
|
|
// The account is already deactivated |
138
|
|
|
$result = $account->deactivate(); |
139
|
|
|
$this->assertTrue($result === false); |
140
|
|
|
|
141
|
|
|
// The account is already deactivated |
142
|
|
|
$result = $account->changeKeys(); |
143
|
|
|
$this->assertTrue($result === false); |
144
|
|
|
|
145
|
|
|
// The account is already deactivated |
146
|
|
|
$this->expectException(\LE_ACME2\Exception\InvalidResponse::class); |
147
|
|
|
$account->getData(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function testCreationAfterDeactivation() { |
151
|
|
|
|
152
|
|
|
if(TestHelper::getInstance()->shouldSkipAccountModificationTests()) { |
153
|
|
|
$this->expectNotToPerformAssertions(); |
154
|
|
|
return; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
158
|
|
|
$this->assertTrue(is_object($account)); |
159
|
|
|
|
160
|
|
|
system('rm -R ' . $account->getKeyDirectoryPath()); |
161
|
|
|
$this->assertTrue(!\LE_ACME2\Account::exists($this->_accountEmail)); |
162
|
|
|
|
163
|
|
|
$account = \LE_ACME2\Account::create($this->_accountEmail); |
164
|
|
|
$this->assertTrue(is_object($account)); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function test() { |
168
|
|
|
|
169
|
|
|
$account = \LE_ACME2\Account::get($this->_accountEmail); |
170
|
|
|
$this->assertTrue(is_object($account)); |
171
|
|
|
} |
172
|
|
|
} |