18
18
package ru .mystamps .web .support .spring .security ;
19
19
20
20
import org .assertj .core .api .WithAssertions ;
21
+ import org .junit .BeforeClass ;
21
22
import org .junit .Rule ;
22
23
import org .junit .Test ;
24
+ import org .springframework .boot .autoconfigure .h2 .H2ConsoleProperties ;
23
25
import org .springframework .mock .web .MockHttpServletRequest ;
24
26
import org .springframework .mock .web .MockHttpServletResponse ;
25
27
import org .togglz .junit .TogglzRule ;
@@ -38,10 +40,16 @@ public class ContentSecurityPolicyHeaderWriterTest implements WithAssertions {
38
40
private static final int NUMBER_OF_DIRECTIVES_ON_ADD_SERIES_PAGE = 7 ;
39
41
private static final int NUMBER_OF_DIRECTIVES_ON_INFO_SERIES_PAGE = 7 ;
40
42
private static final int NUMBER_OF_DIRECTIVES_ON_H2_CONSOLE_PAGE = 7 ;
41
-
43
+ private static final H2ConsoleProperties H2_CONSOLE_PROPERTIES = new H2ConsoleProperties ();
44
+
42
45
@ Rule
43
46
public TogglzRule togglz = TogglzRule .allEnabled (Features .class );
44
47
48
+ @ BeforeClass
49
+ public static void setupClass () {
50
+ H2_CONSOLE_PROPERTIES .setPath ("/console/" );
51
+ }
52
+
45
53
//
46
54
// Tests for writeHeaders()
47
55
//
@@ -50,7 +58,13 @@ public class ContentSecurityPolicyHeaderWriterTest implements WithAssertions {
50
58
public void writeContentSecurityPolicyHeader () {
51
59
// given
52
60
ContentSecurityPolicyHeaderWriter writer =
53
- new ContentSecurityPolicyHeaderWriter (bool (), bool (), bool (), Random .host ());
61
+ new ContentSecurityPolicyHeaderWriter (
62
+ bool (),
63
+ bool (),
64
+ bool (),
65
+ Random .host (),
66
+ H2_CONSOLE_PROPERTIES
67
+ );
54
68
HttpServletRequest request = new MockHttpServletRequest ();
55
69
HttpServletResponse response = new MockHttpServletResponse ();
56
70
@@ -77,7 +91,12 @@ public void writeContentSecurityPolicyHeader() {
77
91
@ Test
78
92
public void onIndexPageWithLocalResources () {
79
93
ContentSecurityPolicyHeaderWriter writer =
80
- new ContentSecurityPolicyHeaderWriter (false , true , bool (), SiteUrl .SITE );
94
+ new ContentSecurityPolicyHeaderWriter (
95
+ false ,
96
+ true ,
97
+ bool (),
98
+ SiteUrl .SITE , H2_CONSOLE_PROPERTIES
99
+ );
81
100
String [] directives = writer .constructDirectives ("/" ).split (";" );
82
101
83
102
assertThat (directives )
@@ -91,11 +110,16 @@ public void onIndexPageWithLocalResources() {
91
110
)
92
111
.hasSize (NUMBER_OF_DIRECTIVES_ON_STANDARD_PAGES );
93
112
}
94
-
113
+
95
114
@ Test
96
115
public void onIndexPageWithResourcesFromCdn () {
97
116
ContentSecurityPolicyHeaderWriter writer
98
- = new ContentSecurityPolicyHeaderWriter (true , false , bool (), SiteUrl .PUBLIC_URL );
117
+ = new ContentSecurityPolicyHeaderWriter (
118
+ true ,
119
+ false ,
120
+ bool (),
121
+ SiteUrl .PUBLIC_URL , H2_CONSOLE_PROPERTIES
122
+ );
99
123
String [] directives = writer .constructDirectives ("/" ).split (";" );
100
124
101
125
assertThat (directives )
@@ -126,7 +150,13 @@ public void onIndexPageWithResourcesFromCdn() {
126
150
@ Test
127
151
public void onCollectionInfoPageWithLocalResources () {
128
152
ContentSecurityPolicyHeaderWriter writer =
129
- new ContentSecurityPolicyHeaderWriter (false , true , bool (), Random .host ());
153
+ new ContentSecurityPolicyHeaderWriter (
154
+ false ,
155
+ true ,
156
+ bool (),
157
+ Random .host (),
158
+ H2_CONSOLE_PROPERTIES
159
+ );
130
160
String [] directives = writer .constructDirectives ("/collection/user" ).split (";" );
131
161
132
162
// test only the directives that differ from the index page
@@ -153,7 +183,13 @@ public void onCollectionInfoPageWithLocalResources() {
153
183
@ Test
154
184
public void onCollectionInfoPageWithResourcesFromCdn () {
155
185
ContentSecurityPolicyHeaderWriter writer =
156
- new ContentSecurityPolicyHeaderWriter (true , false , bool (), Random .host ());
186
+ new ContentSecurityPolicyHeaderWriter (
187
+ true ,
188
+ false ,
189
+ bool (),
190
+ Random .host (),
191
+ H2_CONSOLE_PROPERTIES
192
+ );
157
193
String [] directives = writer .constructDirectives ("/collection/user" ).split (";" );
158
194
159
195
// test only the directives that differ from the index page
@@ -183,7 +219,13 @@ public void onCollectionInfoPageWithResourcesFromCdn() {
183
219
@ Test
184
220
public void onSeriesAddImagePageWithLocalResources () {
185
221
ContentSecurityPolicyHeaderWriter writer =
186
- new ContentSecurityPolicyHeaderWriter (false , true , bool (), Random .host ());
222
+ new ContentSecurityPolicyHeaderWriter (
223
+ false ,
224
+ true ,
225
+ bool (),
226
+ Random .host (),
227
+ H2_CONSOLE_PROPERTIES
228
+ );
187
229
188
230
for (String page : new String []{"/series/11" , "/series/12/ask" , "/series/13/image" }) {
189
231
String [] directives = writer .constructDirectives (page ).split (";" );
@@ -206,7 +248,13 @@ public void onSeriesAddImagePageWithLocalResources() {
206
248
@ Test
207
249
public void onSeriesAddImagePageWithResourcesFromCdn () {
208
250
ContentSecurityPolicyHeaderWriter writer =
209
- new ContentSecurityPolicyHeaderWriter (true , false , bool (), Random .host ());
251
+ new ContentSecurityPolicyHeaderWriter (
252
+ true ,
253
+ false ,
254
+ bool (),
255
+ Random .host (),
256
+ H2_CONSOLE_PROPERTIES
257
+ );
210
258
211
259
for (String page : new String []{"/series/11" , "/series/12/ask" , "/series/13/image" }) {
212
260
String [] directives = writer .constructDirectives (page ).split (";" );
@@ -239,7 +287,13 @@ public void onSeriesAddImagePageWithResourcesFromCdn() {
239
287
@ Test
240
288
public void onSeriesAddPageWithLocalResources () {
241
289
ContentSecurityPolicyHeaderWriter writer =
242
- new ContentSecurityPolicyHeaderWriter (false , true , bool (), Random .host ());
290
+ new ContentSecurityPolicyHeaderWriter (
291
+ false ,
292
+ true ,
293
+ bool (),
294
+ Random .host (),
295
+ H2_CONSOLE_PROPERTIES
296
+ );
243
297
String [] directives = writer .constructDirectives ("/series/add" ).split (";" );
244
298
245
299
// test only the directives that differ from the index page
@@ -267,7 +321,13 @@ public void onSeriesAddPageWithLocalResources() {
267
321
@ Test
268
322
public void onSeriesAddPageWithResourcesFromCdn () {
269
323
ContentSecurityPolicyHeaderWriter writer =
270
- new ContentSecurityPolicyHeaderWriter (true , false , bool (), Random .host ());
324
+ new ContentSecurityPolicyHeaderWriter (
325
+ true ,
326
+ false ,
327
+ bool (),
328
+ Random .host (),
329
+ H2_CONSOLE_PROPERTIES
330
+ );
271
331
String [] directives = writer .constructDirectives ("/series/add" ).split (";" );
272
332
273
333
// test only the directives that differ from the index page
@@ -298,7 +358,13 @@ public void onSeriesAddPageWithResourcesFromCdn() {
298
358
@ Test
299
359
public void onH2ConsoleWithLocalResources () {
300
360
ContentSecurityPolicyHeaderWriter writer =
301
- new ContentSecurityPolicyHeaderWriter (false , true , true , Random .host ());
361
+ new ContentSecurityPolicyHeaderWriter (
362
+ false ,
363
+ true ,
364
+ true ,
365
+ Random .host (),
366
+ H2_CONSOLE_PROPERTIES
367
+ );
302
368
String [] directives = writer .constructDirectives ("/console/" ).split (";" );
303
369
304
370
// test only the directives that are differ from the index page
@@ -326,7 +392,13 @@ public void onH2ConsoleWithLocalResources() {
326
392
@ Test
327
393
public void onH2ConsoleWithResourcesFromCdn () {
328
394
ContentSecurityPolicyHeaderWriter writer =
329
- new ContentSecurityPolicyHeaderWriter (true , false , false , Random .host ());
395
+ new ContentSecurityPolicyHeaderWriter (
396
+ true ,
397
+ false ,
398
+ false ,
399
+ Random .host (),
400
+ H2_CONSOLE_PROPERTIES
401
+ );
330
402
String [] directives = writer .constructDirectives ("/console/" ).split (";" );
331
403
332
404
assertThat (directives )
0 commit comments