@@ -49,32 +49,19 @@ public function testCreateShouldReturnPolicyAndMergeCustomWithDefaultDirective()
4949 $ nonceMock = $ this ->createMock (Nonce::class);
5050
5151 $ defaultDirective = [
52- 'base-uri ' => [
53- 'test.com ' ,
54- ],
55- 'script-src ' => [
56- 'test.com ' ,
57- ],
52+ 'base-uri ' => ['test.com ' => true ],
53+ 'script-src ' => ['test.com ' => true ],
5854 ];
5955 $ customDirective = [
60- 'script-src ' => [
61- 'custom.com ' ,
62- ],
63- ];
64-
65- $ expected = [
66- 'base-uri ' => [
67- 'test.com ' ,
68- ],
69- 'script-src ' => [
70- 'test.com ' ,
71- 'custom.com ' ,
72- ],
56+ 'script-src ' => ['custom.com ' => true ],
7357 ];
7458
7559 $ result = $ this ->policyFactory ->create ($ nonceMock , $ defaultDirective , $ customDirective );
7660
77- self ::assertSame ($ expected , $ result ->getDirectives ());
61+ self ::assertSame ([
62+ 'base-uri ' => ['test.com ' ],
63+ 'script-src ' => ['test.com ' , 'custom.com ' ],
64+ ], $ result ->getDirectives ());
7865 }
7966
8067 public function testCreateShouldReturnPolicyAndHandleSpecialDirectives (): void
@@ -83,35 +70,26 @@ public function testCreateShouldReturnPolicyAndHandleSpecialDirectives(): void
8370
8471 $ defaultDirective = [
8572 'script-src ' => [
86- '{nonce} ' ,
87- 'self ' ,
73+ '{nonce} ' => true ,
74+ 'self ' => true ,
8875 ],
8976 ];
9077 $ customDirective = [];
9178
92- $ expected = [
93- 'script-src ' => [
94- "'nonce-' " ,
95- "'self' " ,
96- ],
97- ];
98-
9979 $ result = $ this ->policyFactory ->create ($ nonceMock , $ defaultDirective , $ customDirective );
10080
101- self ::assertSame ($ expected , $ result ->getDirectives ());
81+ self ::assertSame ([
82+ 'script-src ' => ["'nonce-' " , "'self' " ],
83+ ], $ result ->getDirectives ());
10284 }
10385
10486 public function testCreateShouldFailWithInvalidDirective (): void
10587 {
10688 $ nonceMock = $ this ->createMock (Nonce::class);
10789
10890 $ defaultDirective = [
109- 'invalid ' => [
110- 'self ' ,
111- ],
112- 'script-src ' => [
113- 'self ' ,
114- ],
91+ 'invalid ' => ['self ' => true ],
92+ 'script-src ' => ['self ' => true ],
11593 ];
11694 $ customDirective = [];
11795
@@ -128,12 +106,8 @@ public function testCreateShouldLogInvalidDirectiveInProduction(): void
128106 );
129107
130108 $ defaultDirective = [
131- 'invalid ' => [
132- 'self ' ,
133- ],
134- 'script-src ' => [
135- 'self ' ,
136- ],
109+ 'invalid ' => ['self ' => true ],
110+ 'script-src ' => ['self ' => true ],
137111 ];
138112 $ customDirective = [];
139113
@@ -151,69 +125,40 @@ public function testCreateShouldReturnPolicyWithUniqueValues(): void
151125 $ nonceMock = $ this ->createMock (Nonce::class);
152126
153127 $ defaultDirective = [
154- 'base-uri ' => [
155- 'test.com ' ,
156- ],
157- 'script-src ' => [
158- 'test.com ' ,
159- ],
128+ 'base-uri ' => ['test.com ' => true ],
129+ 'script-src ' => ['test.com ' => true ],
160130 ];
161131 $ customDirective = [
162- 'base-uri ' => [
163- 'test.com ' ,
164- 'test.com ' ,
165- ],
166- 'script-src ' => [
167- 'test.com ' ,
168- ],
169- ];
170-
171- $ expected = [
172- 'base-uri ' => [
173- 'test.com ' ,
174- ],
175- 'script-src ' => [
176- 'test.com ' ,
177- ],
132+ 'base-uri ' => ['test.com ' => true ],
133+ 'script-src ' => ['test.com ' => true ],
178134 ];
179135
180136 $ result = $ this ->policyFactory ->create ($ nonceMock , $ defaultDirective , $ customDirective );
181137
182- self ::assertSame ($ expected , $ result ->getDirectives ());
138+ self ::assertSame ([
139+ 'base-uri ' => ['test.com ' ],
140+ 'script-src ' => ['test.com ' ],
141+ ], $ result ->getDirectives ());
183142 }
184143
185144 public function testCreateShouldAddDirectiveWhichIsPresentInCustomButNotDefaultConfiguration (): void
186145 {
187146 $ nonceMock = $ this ->createMock (Nonce::class);
188147
189148 $ defaultDirective = [
190- 'base-uri ' => [
191- 'test.com ' ,
192- ],
193- 'script-src ' => [
194- 'test.com ' ,
195- ],
149+ 'base-uri ' => ['test.com ' => true ],
150+ 'script-src ' => ['test.com ' => true ],
196151 ];
197152 $ customDirective = [
198- 'worker-src ' => [
199- 'test.com ' ,
200- ],
201- ];
202-
203- $ expected = [
204- 'base-uri ' => [
205- "test.com " ,
206- ],
207- 'script-src ' => [
208- "test.com " ,
209- ],
210- 'worker-src ' => [
211- "test.com " ,
212- ],
153+ 'worker-src ' => ['test.com ' => true ],
213154 ];
214155
215156 $ result = $ this ->policyFactory ->create ($ nonceMock , $ defaultDirective , $ customDirective );
216157
217- self ::assertSame ($ expected , $ result ->getDirectives ());
158+ self ::assertSame ([
159+ 'base-uri ' => ['test.com ' ],
160+ 'script-src ' => ['test.com ' ],
161+ 'worker-src ' => ['test.com ' ],
162+ ], $ result ->getDirectives ());
218163 }
219164}
0 commit comments