@@ -11,95 +11,95 @@ |
||
11 | 11 | use OCP\Http\Client\IResponse; |
12 | 12 | |
13 | 13 | trait ClientServiceTrait { |
14 | - /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ |
|
15 | - private $clientService; |
|
16 | - /** @var IClient|\PHPUnit\Framework\MockObject\MockObject */ |
|
17 | - private $client; |
|
18 | - private $expectedGetRequests = []; |
|
19 | - private $expectedPostRequests = []; |
|
14 | + /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ |
|
15 | + private $clientService; |
|
16 | + /** @var IClient|\PHPUnit\Framework\MockObject\MockObject */ |
|
17 | + private $client; |
|
18 | + private $expectedGetRequests = []; |
|
19 | + private $expectedPostRequests = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Wrapper to be forward compatible to phpunit 5.4+ |
|
23 | - * |
|
24 | - * @param string $originalClassName |
|
25 | - * @return \PHPUnit\Framework\MockObject\MockObject |
|
26 | - */ |
|
27 | - abstract protected function createMock(string $originalClassName); |
|
21 | + /** |
|
22 | + * Wrapper to be forward compatible to phpunit 5.4+ |
|
23 | + * |
|
24 | + * @param string $originalClassName |
|
25 | + * @return \PHPUnit\Framework\MockObject\MockObject |
|
26 | + */ |
|
27 | + abstract protected function createMock(string $originalClassName); |
|
28 | 28 | |
29 | - /** |
|
30 | - * Returns a matcher that matches when the method is executed |
|
31 | - * zero or more times. |
|
32 | - * |
|
33 | - * @return \PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
34 | - * |
|
35 | - * @since Method available since Release 3.0.0 |
|
36 | - */ |
|
37 | - abstract public static function any(); |
|
29 | + /** |
|
30 | + * Returns a matcher that matches when the method is executed |
|
31 | + * zero or more times. |
|
32 | + * |
|
33 | + * @return \PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
34 | + * |
|
35 | + * @since Method available since Release 3.0.0 |
|
36 | + */ |
|
37 | + abstract public static function any(); |
|
38 | 38 | |
39 | - protected function setUpClientServiceTrait() { |
|
40 | - $this->clientService = $this->createMock(IClientService::class); |
|
41 | - $this->client = $this->createMock(IClient::class); |
|
42 | - $this->clientService->expects($this->any()) |
|
43 | - ->method('newClient') |
|
44 | - ->willReturn($this->client); |
|
45 | - $this->client->expects($this->any()) |
|
46 | - ->method('get') |
|
47 | - ->willReturnCallback(function ($url) { |
|
48 | - if (!isset($this->expectedGetRequests[$url])) { |
|
49 | - throw new \Exception('unexpected request: ' . $url); |
|
50 | - } |
|
51 | - $result = $this->expectedGetRequests[$url]; |
|
39 | + protected function setUpClientServiceTrait() { |
|
40 | + $this->clientService = $this->createMock(IClientService::class); |
|
41 | + $this->client = $this->createMock(IClient::class); |
|
42 | + $this->clientService->expects($this->any()) |
|
43 | + ->method('newClient') |
|
44 | + ->willReturn($this->client); |
|
45 | + $this->client->expects($this->any()) |
|
46 | + ->method('get') |
|
47 | + ->willReturnCallback(function ($url) { |
|
48 | + if (!isset($this->expectedGetRequests[$url])) { |
|
49 | + throw new \Exception('unexpected request: ' . $url); |
|
50 | + } |
|
51 | + $result = $this->expectedGetRequests[$url]; |
|
52 | 52 | |
53 | - if ($result instanceof \Exception) { |
|
54 | - throw $result; |
|
55 | - } else { |
|
56 | - $response = $this->createMock(IResponse::class); |
|
57 | - $response->expects($this->any()) |
|
58 | - ->method('getBody') |
|
59 | - ->willReturn($result); |
|
60 | - return $response; |
|
61 | - } |
|
62 | - }); |
|
63 | - $this->client->expects($this->any()) |
|
64 | - ->method('post') |
|
65 | - ->willReturnCallback(function ($url) { |
|
66 | - if (!isset($this->expectedPostRequests[$url])) { |
|
67 | - throw new \Exception('unexpected request: ' . $url); |
|
68 | - } |
|
69 | - $result = $this->expectedPostRequests[$url]; |
|
53 | + if ($result instanceof \Exception) { |
|
54 | + throw $result; |
|
55 | + } else { |
|
56 | + $response = $this->createMock(IResponse::class); |
|
57 | + $response->expects($this->any()) |
|
58 | + ->method('getBody') |
|
59 | + ->willReturn($result); |
|
60 | + return $response; |
|
61 | + } |
|
62 | + }); |
|
63 | + $this->client->expects($this->any()) |
|
64 | + ->method('post') |
|
65 | + ->willReturnCallback(function ($url) { |
|
66 | + if (!isset($this->expectedPostRequests[$url])) { |
|
67 | + throw new \Exception('unexpected request: ' . $url); |
|
68 | + } |
|
69 | + $result = $this->expectedPostRequests[$url]; |
|
70 | 70 | |
71 | - if ($result instanceof \Exception) { |
|
72 | - throw $result; |
|
73 | - } else { |
|
74 | - $response = $this->createMock(IResponse::class); |
|
75 | - $response->expects($this->any()) |
|
76 | - ->method('getBody') |
|
77 | - ->willReturn($result); |
|
78 | - return $response; |
|
79 | - } |
|
80 | - }); |
|
81 | - } |
|
71 | + if ($result instanceof \Exception) { |
|
72 | + throw $result; |
|
73 | + } else { |
|
74 | + $response = $this->createMock(IResponse::class); |
|
75 | + $response->expects($this->any()) |
|
76 | + ->method('getBody') |
|
77 | + ->willReturn($result); |
|
78 | + return $response; |
|
79 | + } |
|
80 | + }); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param string $url |
|
85 | - * @param string|\Exception $result |
|
86 | - */ |
|
87 | - protected function expectGetRequest($url, $result) { |
|
88 | - $this->expectedGetRequests[$url] = $result; |
|
89 | - } |
|
83 | + /** |
|
84 | + * @param string $url |
|
85 | + * @param string|\Exception $result |
|
86 | + */ |
|
87 | + protected function expectGetRequest($url, $result) { |
|
88 | + $this->expectedGetRequests[$url] = $result; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $url |
|
93 | - * @param string|\Exception $result |
|
94 | - */ |
|
95 | - protected function expectPostRequest($url, $result) { |
|
96 | - $this->expectedPostRequests[$url] = $result; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @param string $url |
|
93 | + * @param string|\Exception $result |
|
94 | + */ |
|
95 | + protected function expectPostRequest($url, $result) { |
|
96 | + $this->expectedPostRequests[$url] = $result; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return IClientService|\PHPUnit\Framework\MockObject\MockObject |
|
101 | - */ |
|
102 | - protected function getClientService() { |
|
103 | - return $this->clientService; |
|
104 | - } |
|
99 | + /** |
|
100 | + * @return IClientService|\PHPUnit\Framework\MockObject\MockObject |
|
101 | + */ |
|
102 | + protected function getClientService() { |
|
103 | + return $this->clientService; |
|
104 | + } |
|
105 | 105 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class AddFeaturePolicyEventTest extends TestCase { |
17 | - public function testAddEvent(): void { |
|
18 | - $manager = $this->createMock(FeaturePolicyManager::class); |
|
19 | - $policy = $this->createMock(FeaturePolicy::class); |
|
20 | - $event = new AddFeaturePolicyEvent($manager); |
|
17 | + public function testAddEvent(): void { |
|
18 | + $manager = $this->createMock(FeaturePolicyManager::class); |
|
19 | + $policy = $this->createMock(FeaturePolicy::class); |
|
20 | + $event = new AddFeaturePolicyEvent($manager); |
|
21 | 21 | |
22 | - $manager->expects($this->once()) |
|
23 | - ->method('addDefaultPolicy') |
|
24 | - ->with($policy); |
|
22 | + $manager->expects($this->once()) |
|
23 | + ->method('addDefaultPolicy') |
|
24 | + ->with($policy); |
|
25 | 25 | |
26 | - $event->addPolicy($policy); |
|
27 | - } |
|
26 | + $event->addPolicy($policy); |
|
27 | + } |
|
28 | 28 | } |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class SignerTest extends TestCase { |
21 | - /** @var string */ |
|
22 | - private $private = '-----BEGIN PRIVATE KEY----- |
|
21 | + /** @var string */ |
|
22 | + private $private = '-----BEGIN PRIVATE KEY----- |
|
23 | 23 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDImc6QvHBjBIoo |
24 | 24 | w9nnywiPNESleUuFJ2yQ3Gd/3w2BkblojlUAJAsUd/bQokjOH9d+7nqyzgSiXjRl |
25 | 25 | iwKagY6NjcNEEq0X5KOMNwx6uEbtq3+7pA7H2JefNrnAuD+Fhp3Hyo3h1cse6hAq |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | kC6HCb+CXsMRD7yp8KrrYnw= |
49 | 49 | -----END PRIVATE KEY-----'; |
50 | 50 | |
51 | - /** @var string */ |
|
52 | - private $public = '-----BEGIN PUBLIC KEY----- |
|
51 | + /** @var string */ |
|
52 | + private $public = '-----BEGIN PUBLIC KEY----- |
|
53 | 53 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyJnOkLxwYwSKKMPZ58sI |
54 | 54 | jzREpXlLhSdskNxnf98NgZG5aI5VACQLFHf20KJIzh/Xfu56ss4Eol40ZYsCmoGO |
55 | 55 | jY3DRBKtF+SjjDcMerhG7at/u6QOx9iXnza5wLg/hYadx8qN4dXLHuoQKuma/IWg |
@@ -59,130 +59,130 @@ discard block |
||
59 | 59 | gQIDAQAB |
60 | 60 | -----END PUBLIC KEY-----'; |
61 | 61 | |
62 | - /** @var Key */ |
|
63 | - private $key; |
|
64 | - |
|
65 | - /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ |
|
66 | - private $keyManager; |
|
67 | - |
|
68 | - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
69 | - private $timeFactory; |
|
70 | - |
|
71 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
72 | - private $userManager; |
|
73 | - |
|
74 | - /** @var Signer */ |
|
75 | - private $signer; |
|
76 | - |
|
77 | - protected function setUp(): void { |
|
78 | - parent::setUp(); |
|
79 | - |
|
80 | - $this->key = new Key($this->public, $this->private); |
|
81 | - |
|
82 | - $this->keyManager = $this->createMock(Manager::class); |
|
83 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
84 | - $this->userManager = $this->createMock(IUserManager::class); |
|
85 | - |
|
86 | - $this->signer = new Signer( |
|
87 | - $this->keyManager, |
|
88 | - $this->timeFactory, |
|
89 | - $this->userManager |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - public function testSign(): void { |
|
94 | - $user = $this->createMock(IUser::class); |
|
95 | - $user->method('getCloudId') |
|
96 | - ->willReturn('[email protected]'); |
|
97 | - |
|
98 | - $this->timeFactory->method('getTime') |
|
99 | - ->willReturn(42); |
|
100 | - |
|
101 | - $this->keyManager->method('getKey') |
|
102 | - ->with($this->equalTo($user)) |
|
103 | - ->willReturn($this->key); |
|
104 | - |
|
105 | - $data = [ |
|
106 | - 'foo' => 'bar', |
|
107 | - 'abc' => 'def', |
|
108 | - 'xyz' => 123, |
|
109 | - ]; |
|
110 | - |
|
111 | - $expects = [ |
|
112 | - 'message' => [ |
|
113 | - 'data' => $data, |
|
114 | - 'type' => 'myType', |
|
115 | - 'signer' => '[email protected]', |
|
116 | - 'timestamp' => 42, |
|
117 | - ], |
|
118 | - 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
119 | - ]; |
|
120 | - |
|
121 | - $result = $this->signer->sign('myType', $data, $user); |
|
122 | - |
|
123 | - $this->assertEquals($expects, $result); |
|
124 | - } |
|
125 | - |
|
126 | - public function testVerifyValid(): void { |
|
127 | - $data = [ |
|
128 | - 'message' => [ |
|
129 | - 'data' => [ |
|
130 | - 'foo' => 'bar', |
|
131 | - 'abc' => 'def', |
|
132 | - 'xyz' => 123, |
|
133 | - ], |
|
134 | - 'type' => 'myType', |
|
135 | - 'signer' => '[email protected]', |
|
136 | - 'timestamp' => 42, |
|
137 | - ], |
|
138 | - 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
139 | - ]; |
|
140 | - |
|
141 | - $user = $this->createMock(IUser::class); |
|
142 | - |
|
143 | - $this->keyManager->method('getKey') |
|
144 | - ->with($this->equalTo($user)) |
|
145 | - ->willReturn($this->key); |
|
146 | - |
|
147 | - $this->userManager->method('get') |
|
148 | - ->with('foo') |
|
149 | - ->willReturn($user); |
|
150 | - |
|
151 | - $this->assertTrue($this->signer->verify($data)); |
|
152 | - } |
|
153 | - |
|
154 | - public function testVerifyInvalid(): void { |
|
155 | - $data = [ |
|
156 | - 'message' => [ |
|
157 | - 'data' => [ |
|
158 | - 'foo' => 'bar', |
|
159 | - 'abc' => 'def', |
|
160 | - 'xyz' => 123, |
|
161 | - ], |
|
162 | - 'type' => 'myType', |
|
163 | - 'signer' => '[email protected]', |
|
164 | - 'timestamp' => 42, |
|
165 | - ], |
|
166 | - 'signature' => 'Invalid sig' |
|
167 | - ]; |
|
168 | - |
|
169 | - $user = $this->createMock(IUser::class); |
|
170 | - |
|
171 | - $this->keyManager->method('getKey') |
|
172 | - ->with($this->equalTo($user)) |
|
173 | - ->willReturn($this->key); |
|
174 | - |
|
175 | - $this->userManager->method('get') |
|
176 | - ->with('foo') |
|
177 | - ->willReturn($user); |
|
178 | - |
|
179 | - $this->assertFalse($this->signer->verify($data)); |
|
180 | - } |
|
181 | - |
|
182 | - public function testVerifyInvalidData(): void { |
|
183 | - $data = [ |
|
184 | - ]; |
|
185 | - |
|
186 | - $this->assertFalse($this->signer->verify($data)); |
|
187 | - } |
|
62 | + /** @var Key */ |
|
63 | + private $key; |
|
64 | + |
|
65 | + /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ |
|
66 | + private $keyManager; |
|
67 | + |
|
68 | + /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
69 | + private $timeFactory; |
|
70 | + |
|
71 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
72 | + private $userManager; |
|
73 | + |
|
74 | + /** @var Signer */ |
|
75 | + private $signer; |
|
76 | + |
|
77 | + protected function setUp(): void { |
|
78 | + parent::setUp(); |
|
79 | + |
|
80 | + $this->key = new Key($this->public, $this->private); |
|
81 | + |
|
82 | + $this->keyManager = $this->createMock(Manager::class); |
|
83 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
84 | + $this->userManager = $this->createMock(IUserManager::class); |
|
85 | + |
|
86 | + $this->signer = new Signer( |
|
87 | + $this->keyManager, |
|
88 | + $this->timeFactory, |
|
89 | + $this->userManager |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + public function testSign(): void { |
|
94 | + $user = $this->createMock(IUser::class); |
|
95 | + $user->method('getCloudId') |
|
96 | + ->willReturn('[email protected]'); |
|
97 | + |
|
98 | + $this->timeFactory->method('getTime') |
|
99 | + ->willReturn(42); |
|
100 | + |
|
101 | + $this->keyManager->method('getKey') |
|
102 | + ->with($this->equalTo($user)) |
|
103 | + ->willReturn($this->key); |
|
104 | + |
|
105 | + $data = [ |
|
106 | + 'foo' => 'bar', |
|
107 | + 'abc' => 'def', |
|
108 | + 'xyz' => 123, |
|
109 | + ]; |
|
110 | + |
|
111 | + $expects = [ |
|
112 | + 'message' => [ |
|
113 | + 'data' => $data, |
|
114 | + 'type' => 'myType', |
|
115 | + 'signer' => '[email protected]', |
|
116 | + 'timestamp' => 42, |
|
117 | + ], |
|
118 | + 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
119 | + ]; |
|
120 | + |
|
121 | + $result = $this->signer->sign('myType', $data, $user); |
|
122 | + |
|
123 | + $this->assertEquals($expects, $result); |
|
124 | + } |
|
125 | + |
|
126 | + public function testVerifyValid(): void { |
|
127 | + $data = [ |
|
128 | + 'message' => [ |
|
129 | + 'data' => [ |
|
130 | + 'foo' => 'bar', |
|
131 | + 'abc' => 'def', |
|
132 | + 'xyz' => 123, |
|
133 | + ], |
|
134 | + 'type' => 'myType', |
|
135 | + 'signer' => '[email protected]', |
|
136 | + 'timestamp' => 42, |
|
137 | + ], |
|
138 | + 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
139 | + ]; |
|
140 | + |
|
141 | + $user = $this->createMock(IUser::class); |
|
142 | + |
|
143 | + $this->keyManager->method('getKey') |
|
144 | + ->with($this->equalTo($user)) |
|
145 | + ->willReturn($this->key); |
|
146 | + |
|
147 | + $this->userManager->method('get') |
|
148 | + ->with('foo') |
|
149 | + ->willReturn($user); |
|
150 | + |
|
151 | + $this->assertTrue($this->signer->verify($data)); |
|
152 | + } |
|
153 | + |
|
154 | + public function testVerifyInvalid(): void { |
|
155 | + $data = [ |
|
156 | + 'message' => [ |
|
157 | + 'data' => [ |
|
158 | + 'foo' => 'bar', |
|
159 | + 'abc' => 'def', |
|
160 | + 'xyz' => 123, |
|
161 | + ], |
|
162 | + 'type' => 'myType', |
|
163 | + 'signer' => '[email protected]', |
|
164 | + 'timestamp' => 42, |
|
165 | + ], |
|
166 | + 'signature' => 'Invalid sig' |
|
167 | + ]; |
|
168 | + |
|
169 | + $user = $this->createMock(IUser::class); |
|
170 | + |
|
171 | + $this->keyManager->method('getKey') |
|
172 | + ->with($this->equalTo($user)) |
|
173 | + ->willReturn($this->key); |
|
174 | + |
|
175 | + $this->userManager->method('get') |
|
176 | + ->with('foo') |
|
177 | + ->willReturn($user); |
|
178 | + |
|
179 | + $this->assertFalse($this->signer->verify($data)); |
|
180 | + } |
|
181 | + |
|
182 | + public function testVerifyInvalidData(): void { |
|
183 | + $data = [ |
|
184 | + ]; |
|
185 | + |
|
186 | + $this->assertFalse($this->signer->verify($data)); |
|
187 | + } |
|
188 | 188 | } |
@@ -13,20 +13,20 @@ |
||
13 | 13 | use Test\TestCase; |
14 | 14 | |
15 | 15 | class KeyTest extends TestCase { |
16 | - /** @var Key */ |
|
17 | - private $key; |
|
16 | + /** @var Key */ |
|
17 | + private $key; |
|
18 | 18 | |
19 | - protected function setUp(): void { |
|
20 | - parent::setUp(); |
|
19 | + protected function setUp(): void { |
|
20 | + parent::setUp(); |
|
21 | 21 | |
22 | - $this->key = new Key('public', 'private'); |
|
23 | - } |
|
22 | + $this->key = new Key('public', 'private'); |
|
23 | + } |
|
24 | 24 | |
25 | - public function testGetPrivate(): void { |
|
26 | - $this->assertSame('private', $this->key->getPrivate()); |
|
27 | - } |
|
25 | + public function testGetPrivate(): void { |
|
26 | + $this->assertSame('private', $this->key->getPrivate()); |
|
27 | + } |
|
28 | 28 | |
29 | - public function testGetPublic(): void { |
|
30 | - $this->assertSame('public', $this->key->getPublic()); |
|
31 | - } |
|
29 | + public function testGetPublic(): void { |
|
30 | + $this->assertSame('public', $this->key->getPublic()); |
|
31 | + } |
|
32 | 32 | } |
@@ -15,70 +15,70 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class CapabilitiesTest extends TestCase { |
18 | - /** @var Capabilities */ |
|
19 | - private $capabilities; |
|
20 | - |
|
21 | - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - private $request; |
|
23 | - |
|
24 | - /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - private $throttler; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->request = $this->createMock(IRequest::class); |
|
31 | - |
|
32 | - $this->throttler = $this->createMock(IThrottler::class); |
|
33 | - |
|
34 | - $this->capabilities = new Capabilities( |
|
35 | - $this->request, |
|
36 | - $this->throttler |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public function testGetCapabilities(): void { |
|
41 | - $this->throttler->expects($this->atLeastOnce()) |
|
42 | - ->method('getDelay') |
|
43 | - ->with('10.10.10.10') |
|
44 | - ->willReturn(42); |
|
45 | - |
|
46 | - $this->throttler->expects($this->atLeastOnce()) |
|
47 | - ->method('isBypassListed') |
|
48 | - ->with('10.10.10.10') |
|
49 | - ->willReturn(true); |
|
50 | - |
|
51 | - $this->request->method('getRemoteAddress') |
|
52 | - ->willReturn('10.10.10.10'); |
|
53 | - |
|
54 | - $expected = [ |
|
55 | - 'bruteforce' => [ |
|
56 | - 'delay' => 42, |
|
57 | - 'allow-listed' => true, |
|
58 | - ] |
|
59 | - ]; |
|
60 | - $result = $this->capabilities->getCapabilities(); |
|
61 | - |
|
62 | - $this->assertEquals($expected, $result); |
|
63 | - } |
|
64 | - |
|
65 | - public function testGetCapabilitiesOnCli(): void { |
|
66 | - $this->throttler->expects($this->atLeastOnce()) |
|
67 | - ->method('getDelay') |
|
68 | - ->with('') |
|
69 | - ->willReturn(0); |
|
70 | - |
|
71 | - $this->request->method('getRemoteAddress') |
|
72 | - ->willReturn(''); |
|
73 | - |
|
74 | - $expected = [ |
|
75 | - 'bruteforce' => [ |
|
76 | - 'delay' => 0, |
|
77 | - 'allow-listed' => false, |
|
78 | - ] |
|
79 | - ]; |
|
80 | - $result = $this->capabilities->getCapabilities(); |
|
81 | - |
|
82 | - $this->assertEquals($expected, $result); |
|
83 | - } |
|
18 | + /** @var Capabilities */ |
|
19 | + private $capabilities; |
|
20 | + |
|
21 | + /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + private $request; |
|
23 | + |
|
24 | + /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + private $throttler; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->request = $this->createMock(IRequest::class); |
|
31 | + |
|
32 | + $this->throttler = $this->createMock(IThrottler::class); |
|
33 | + |
|
34 | + $this->capabilities = new Capabilities( |
|
35 | + $this->request, |
|
36 | + $this->throttler |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public function testGetCapabilities(): void { |
|
41 | + $this->throttler->expects($this->atLeastOnce()) |
|
42 | + ->method('getDelay') |
|
43 | + ->with('10.10.10.10') |
|
44 | + ->willReturn(42); |
|
45 | + |
|
46 | + $this->throttler->expects($this->atLeastOnce()) |
|
47 | + ->method('isBypassListed') |
|
48 | + ->with('10.10.10.10') |
|
49 | + ->willReturn(true); |
|
50 | + |
|
51 | + $this->request->method('getRemoteAddress') |
|
52 | + ->willReturn('10.10.10.10'); |
|
53 | + |
|
54 | + $expected = [ |
|
55 | + 'bruteforce' => [ |
|
56 | + 'delay' => 42, |
|
57 | + 'allow-listed' => true, |
|
58 | + ] |
|
59 | + ]; |
|
60 | + $result = $this->capabilities->getCapabilities(); |
|
61 | + |
|
62 | + $this->assertEquals($expected, $result); |
|
63 | + } |
|
64 | + |
|
65 | + public function testGetCapabilitiesOnCli(): void { |
|
66 | + $this->throttler->expects($this->atLeastOnce()) |
|
67 | + ->method('getDelay') |
|
68 | + ->with('') |
|
69 | + ->willReturn(0); |
|
70 | + |
|
71 | + $this->request->method('getRemoteAddress') |
|
72 | + ->willReturn(''); |
|
73 | + |
|
74 | + $expected = [ |
|
75 | + 'bruteforce' => [ |
|
76 | + 'delay' => 0, |
|
77 | + 'allow-listed' => false, |
|
78 | + ] |
|
79 | + ]; |
|
80 | + $result = $this->capabilities->getCapabilities(); |
|
81 | + |
|
82 | + $this->assertEquals($expected, $result); |
|
83 | + } |
|
84 | 84 | } |
@@ -17,55 +17,55 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class ContentSecurityPolicyNonceManagerTest extends TestCase { |
20 | - /** @var CsrfTokenManager&MockObject */ |
|
21 | - private $CSRFTokenManager; |
|
22 | - /** @var Request&MockObject */ |
|
23 | - private $request; |
|
24 | - /** @var ContentSecurityPolicyNonceManager */ |
|
25 | - private $nonceManager; |
|
20 | + /** @var CsrfTokenManager&MockObject */ |
|
21 | + private $CSRFTokenManager; |
|
22 | + /** @var Request&MockObject */ |
|
23 | + private $request; |
|
24 | + /** @var ContentSecurityPolicyNonceManager */ |
|
25 | + private $nonceManager; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - $this->CSRFTokenManager = $this->createMock(CsrfTokenManager::class); |
|
29 | - $this->request = $this->createMock(Request::class); |
|
30 | - $this->nonceManager = new ContentSecurityPolicyNonceManager( |
|
31 | - $this->CSRFTokenManager, |
|
32 | - $this->request |
|
33 | - ); |
|
34 | - } |
|
27 | + protected function setUp(): void { |
|
28 | + $this->CSRFTokenManager = $this->createMock(CsrfTokenManager::class); |
|
29 | + $this->request = $this->createMock(Request::class); |
|
30 | + $this->nonceManager = new ContentSecurityPolicyNonceManager( |
|
31 | + $this->CSRFTokenManager, |
|
32 | + $this->request |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function testGetNonce(): void { |
|
37 | - $secret = base64_encode('secret'); |
|
38 | - $tokenValue = base64_encode('secret' ^ 'value_') . ':' . $secret; |
|
39 | - $token = $this->createMock(CsrfToken::class); |
|
40 | - $token |
|
41 | - ->expects($this->once()) |
|
42 | - ->method('getEncryptedValue') |
|
43 | - ->willReturn($tokenValue); |
|
36 | + public function testGetNonce(): void { |
|
37 | + $secret = base64_encode('secret'); |
|
38 | + $tokenValue = base64_encode('secret' ^ 'value_') . ':' . $secret; |
|
39 | + $token = $this->createMock(CsrfToken::class); |
|
40 | + $token |
|
41 | + ->expects($this->once()) |
|
42 | + ->method('getEncryptedValue') |
|
43 | + ->willReturn($tokenValue); |
|
44 | 44 | |
45 | - $this->CSRFTokenManager |
|
46 | - ->expects($this->once()) |
|
47 | - ->method('getToken') |
|
48 | - ->willReturn($token); |
|
45 | + $this->CSRFTokenManager |
|
46 | + ->expects($this->once()) |
|
47 | + ->method('getToken') |
|
48 | + ->willReturn($token); |
|
49 | 49 | |
50 | - $this->assertSame($secret, $this->nonceManager->getNonce()); |
|
51 | - // call it twice but `getEncryptedValue` is expected to be called only once |
|
52 | - $this->assertSame($secret, $this->nonceManager->getNonce()); |
|
53 | - } |
|
50 | + $this->assertSame($secret, $this->nonceManager->getNonce()); |
|
51 | + // call it twice but `getEncryptedValue` is expected to be called only once |
|
52 | + $this->assertSame($secret, $this->nonceManager->getNonce()); |
|
53 | + } |
|
54 | 54 | |
55 | - public function testGetNonceServerVar(): void { |
|
56 | - $token = 'SERVERNONCE'; |
|
57 | - $this->request |
|
58 | - ->method('__isset') |
|
59 | - ->with('server') |
|
60 | - ->willReturn(true); |
|
55 | + public function testGetNonceServerVar(): void { |
|
56 | + $token = 'SERVERNONCE'; |
|
57 | + $this->request |
|
58 | + ->method('__isset') |
|
59 | + ->with('server') |
|
60 | + ->willReturn(true); |
|
61 | 61 | |
62 | - $this->request |
|
63 | - ->method('__get') |
|
64 | - ->with('server') |
|
65 | - ->willReturn(['CSP_NONCE' => $token]); |
|
62 | + $this->request |
|
63 | + ->method('__get') |
|
64 | + ->with('server') |
|
65 | + ->willReturn(['CSP_NONCE' => $token]); |
|
66 | 66 | |
67 | - $this->assertSame($token, $this->nonceManager->getNonce()); |
|
68 | - // call it twice but `CSP_NONCE` variable is expected to be loaded only once |
|
69 | - $this->assertSame($token, $this->nonceManager->getNonce()); |
|
70 | - } |
|
67 | + $this->assertSame($token, $this->nonceManager->getNonce()); |
|
68 | + // call it twice but `CSP_NONCE` variable is expected to be loaded only once |
|
69 | + $this->assertSame($token, $this->nonceManager->getNonce()); |
|
70 | + } |
|
71 | 71 | } |
@@ -15,15 +15,15 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class AddContentSecurityPolicyEventTest extends TestCase { |
18 | - public function testAddEvent(): void { |
|
19 | - $cspManager = $this->createMock(ContentSecurityPolicyManager::class); |
|
20 | - $policy = $this->createMock(ContentSecurityPolicy::class); |
|
21 | - $event = new AddContentSecurityPolicyEvent($cspManager); |
|
18 | + public function testAddEvent(): void { |
|
19 | + $cspManager = $this->createMock(ContentSecurityPolicyManager::class); |
|
20 | + $policy = $this->createMock(ContentSecurityPolicy::class); |
|
21 | + $event = new AddContentSecurityPolicyEvent($cspManager); |
|
22 | 22 | |
23 | - $cspManager->expects($this->once()) |
|
24 | - ->method('addDefaultPolicy') |
|
25 | - ->with($policy); |
|
23 | + $cspManager->expects($this->once()) |
|
24 | + ->method('addDefaultPolicy') |
|
25 | + ->with($policy); |
|
26 | 26 | |
27 | - $event->addPolicy($policy); |
|
28 | - } |
|
27 | + $event->addPolicy($policy); |
|
28 | + } |
|
29 | 29 | } |
@@ -14,20 +14,20 @@ |
||
14 | 14 | |
15 | 15 | class GenerateSecurePasswordEventTest extends \Test\TestCase { |
16 | 16 | |
17 | - public function testDefaultProperties(): void { |
|
18 | - $event = new GenerateSecurePasswordEvent(); |
|
19 | - $this->assertNull($event->getPassword()); |
|
20 | - $this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); |
|
21 | - } |
|
22 | - |
|
23 | - public function testSettingPassword(): void { |
|
24 | - $event = new GenerateSecurePasswordEvent(); |
|
25 | - $event->setPassword('example'); |
|
26 | - $this->assertEquals('example', $event->getPassword()); |
|
27 | - } |
|
28 | - |
|
29 | - public function testSettingContext(): void { |
|
30 | - $event = new GenerateSecurePasswordEvent(PasswordContext::SHARING); |
|
31 | - $this->assertEquals(PasswordContext::SHARING, $event->getContext()); |
|
32 | - } |
|
17 | + public function testDefaultProperties(): void { |
|
18 | + $event = new GenerateSecurePasswordEvent(); |
|
19 | + $this->assertNull($event->getPassword()); |
|
20 | + $this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); |
|
21 | + } |
|
22 | + |
|
23 | + public function testSettingPassword(): void { |
|
24 | + $event = new GenerateSecurePasswordEvent(); |
|
25 | + $event->setPassword('example'); |
|
26 | + $this->assertEquals('example', $event->getPassword()); |
|
27 | + } |
|
28 | + |
|
29 | + public function testSettingContext(): void { |
|
30 | + $event = new GenerateSecurePasswordEvent(PasswordContext::SHARING); |
|
31 | + $this->assertEquals(PasswordContext::SHARING, $event->getContext()); |
|
32 | + } |
|
33 | 33 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | |
15 | 15 | class ValidatePasswordPolicyEventTest extends \Test\TestCase { |
16 | 16 | |
17 | - public function testDefaultProperties(): void { |
|
18 | - $password = 'example'; |
|
19 | - $event = new ValidatePasswordPolicyEvent($password); |
|
20 | - $this->assertEquals($password, $event->getPassword()); |
|
21 | - $this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); |
|
22 | - } |
|
17 | + public function testDefaultProperties(): void { |
|
18 | + $password = 'example'; |
|
19 | + $event = new ValidatePasswordPolicyEvent($password); |
|
20 | + $this->assertEquals($password, $event->getPassword()); |
|
21 | + $this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); |
|
22 | + } |
|
23 | 23 | |
24 | - public function testSettingContext(): void { |
|
25 | - $event = new ValidatePasswordPolicyEvent('example', PasswordContext::SHARING); |
|
26 | - $this->assertEquals(PasswordContext::SHARING, $event->getContext()); |
|
27 | - } |
|
24 | + public function testSettingContext(): void { |
|
25 | + $event = new ValidatePasswordPolicyEvent('example', PasswordContext::SHARING); |
|
26 | + $this->assertEquals(PasswordContext::SHARING, $event->getContext()); |
|
27 | + } |
|
28 | 28 | } |