20
20
import org .junit .Test ;
21
21
import org .springframework .mock .web .MockHttpServletRequest ;
22
22
import org .springframework .mock .web .MockHttpServletResponse ;
23
+ import ru .mystamps .web .feature .site .SiteUrl ;
24
+ import ru .mystamps .web .tests .Random ;
23
25
24
26
import javax .servlet .http .HttpServletRequest ;
25
27
import javax .servlet .http .HttpServletResponse ;
@@ -46,7 +48,7 @@ public class ContentSecurityPolicyHeaderWriterTest {
46
48
@ Test
47
49
public void writeContentSecurityPolicyHeader () {
48
50
ContentSecurityPolicyHeaderWriter writer =
49
- new ContentSecurityPolicyHeaderWriter (bool (), bool ());
51
+ new ContentSecurityPolicyHeaderWriter (bool (), bool (), Random . host () );
50
52
51
53
HttpServletRequest request = new MockHttpServletRequest ();
52
54
HttpServletResponse response = new MockHttpServletResponse ();
@@ -64,7 +66,7 @@ public void writeContentSecurityPolicyHeader() {
64
66
@ Test
65
67
public void onIndexPageWithLocalResources () {
66
68
ContentSecurityPolicyHeaderWriter writer =
67
- new ContentSecurityPolicyHeaderWriter (true , bool ());
69
+ new ContentSecurityPolicyHeaderWriter (true , bool (), SiteUrl . SITE );
68
70
String [] directives = writer .constructDirectives ("/" ).split (";" );
69
71
70
72
assertThat (directives , hasItemInArray ("default-src 'none'" ));
@@ -78,7 +80,7 @@ public void onIndexPageWithLocalResources() {
78
80
79
81
assertThat (
80
82
directives ,
81
- hasItemInArray ("report-uri https ://mystamps.report-uri.com/r/d/ csp/reportOnly " )
83
+ hasItemInArray ("report-uri http ://127.0.0.1:8080/site/ csp/reports " )
82
84
);
83
85
84
86
assertThat (directives , hasItemInArray ("style-src https://cdn.jsdelivr.net 'self'" ));
@@ -90,7 +92,7 @@ public void onIndexPageWithLocalResources() {
90
92
@ Test
91
93
public void onIndexPageWithResourcesFromCdn () {
92
94
ContentSecurityPolicyHeaderWriter writer
93
- = new ContentSecurityPolicyHeaderWriter (false , bool ());
95
+ = new ContentSecurityPolicyHeaderWriter (false , bool (), SiteUrl . PUBLIC_URL );
94
96
String [] directives = writer .constructDirectives ("/" ).split (";" );
95
97
96
98
assertThat (directives , hasItemInArray ("default-src 'none'" ));
@@ -104,7 +106,7 @@ public void onIndexPageWithResourcesFromCdn() {
104
106
105
107
assertThat (
106
108
directives ,
107
- hasItemInArray ("report-uri https://mystamps.report-uri.com/r/d/ csp/reportOnly " )
109
+ hasItemInArray ("report-uri https://my-stamps.ru/site/ csp/reports " )
108
110
);
109
111
110
112
assertThat (
@@ -134,7 +136,7 @@ public void onIndexPageWithResourcesFromCdn() {
134
136
@ Test
135
137
public void onCollectionInfoPageWithLocalResources () {
136
138
ContentSecurityPolicyHeaderWriter writer =
137
- new ContentSecurityPolicyHeaderWriter (true , bool ());
139
+ new ContentSecurityPolicyHeaderWriter (true , bool (), Random . host () );
138
140
String [] directives = writer .constructDirectives ("/collection/user" ).split (";" );
139
141
140
142
// test only the directives that differ from the index page
@@ -167,7 +169,7 @@ public void onCollectionInfoPageWithLocalResources() {
167
169
@ Test
168
170
public void onCollectionInfoPageWithResourcesFromCdn () {
169
171
ContentSecurityPolicyHeaderWriter writer =
170
- new ContentSecurityPolicyHeaderWriter (false , bool ());
172
+ new ContentSecurityPolicyHeaderWriter (false , bool (), Random . host () );
171
173
String [] directives = writer .constructDirectives ("/collection/user" ).split (";" );
172
174
173
175
// test only the directives that differ from the index page
@@ -203,7 +205,7 @@ public void onCollectionInfoPageWithResourcesFromCdn() {
203
205
@ Test
204
206
public void onSeriesAddImagePageWithLocalResources () {
205
207
ContentSecurityPolicyHeaderWriter writer =
206
- new ContentSecurityPolicyHeaderWriter (true , bool ());
208
+ new ContentSecurityPolicyHeaderWriter (true , bool (), Random . host () );
207
209
208
210
for (String page : new String []{"/series/11" , "/series/12/ask" , "/series/13/image" }) {
209
211
String [] directives = writer .constructDirectives (page ).split (";" );
@@ -229,7 +231,7 @@ public void onSeriesAddImagePageWithLocalResources() {
229
231
@ Test
230
232
public void onSeriesAddImagePageWithResourcesFromCdn () {
231
233
ContentSecurityPolicyHeaderWriter writer =
232
- new ContentSecurityPolicyHeaderWriter (false , bool ());
234
+ new ContentSecurityPolicyHeaderWriter (false , bool (), Random . host () );
233
235
234
236
for (String page : new String []{"/series/11" , "/series/12/ask" , "/series/13/image" }) {
235
237
String [] directives = writer .constructDirectives (page ).split (";" );
@@ -268,7 +270,7 @@ public void onSeriesAddImagePageWithResourcesFromCdn() {
268
270
@ Test
269
271
public void onSeriesAddPageWithLocalResources () {
270
272
ContentSecurityPolicyHeaderWriter writer =
271
- new ContentSecurityPolicyHeaderWriter (true , bool ());
273
+ new ContentSecurityPolicyHeaderWriter (true , bool (), Random . host () );
272
274
String [] directives = writer .constructDirectives ("/series/add" ).split (";" );
273
275
274
276
// test only the directives that differ from the index page
@@ -302,7 +304,7 @@ public void onSeriesAddPageWithLocalResources() {
302
304
@ Test
303
305
public void onSeriesAddPageWithResourcesFromCdn () {
304
306
ContentSecurityPolicyHeaderWriter writer =
305
- new ContentSecurityPolicyHeaderWriter (false , bool ());
307
+ new ContentSecurityPolicyHeaderWriter (false , bool (), Random . host () );
306
308
String [] directives = writer .constructDirectives ("/series/add" ).split (";" );
307
309
308
310
// test only the directives that differ from the index page
@@ -339,7 +341,7 @@ public void onSeriesAddPageWithResourcesFromCdn() {
339
341
@ Test
340
342
public void onH2ConsoleWithLocalResources () {
341
343
ContentSecurityPolicyHeaderWriter writer =
342
- new ContentSecurityPolicyHeaderWriter (true , true );
344
+ new ContentSecurityPolicyHeaderWriter (true , true , Random . host () );
343
345
String [] directives = writer .constructDirectives ("/console/" ).split (";" );
344
346
345
347
// test only the directives that are differ from the index page
@@ -374,7 +376,7 @@ public void onH2ConsoleWithLocalResources() {
374
376
@ Test
375
377
public void onH2ConsoleWithResourcesFromCdn () {
376
378
ContentSecurityPolicyHeaderWriter writer =
377
- new ContentSecurityPolicyHeaderWriter (false , false );
379
+ new ContentSecurityPolicyHeaderWriter (false , false , Random . host () );
378
380
String [] directives = writer .constructDirectives ("/console/" ).split (";" );
379
381
380
382
// "style-src" directive should be the same as for the index page
0 commit comments