Skip to content

Commit f616144

Browse files
committed
refactor(ContentSecurityPolicyHeaderWriter): rename a member.
Related to #1059
1 parent 3672a31 commit f616144

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/main/java/ru/mystamps/web/support/spring/security/ContentSecurityPolicyHeaderWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
163163
// number of separators between directives
164164
+ 5;
165165

166-
private final boolean useSingleHost;
166+
private final boolean useCdn;
167167
private final boolean hasH2Console;
168168
private final String host;
169169

@@ -182,11 +182,11 @@ protected String constructDirectives(String uri) {
182182
StringBuilder sb = new StringBuilder(MIN_HEADER_LENGTH);
183183

184184
sb.append(DEFAULT_SRC).append(SEPARATOR)
185-
.append(IMG_SRC).append(useSingleHost ? IMG_SRC_SELF : IMG_SRC_CDN).append(SEPARATOR)
186-
.append(useSingleHost ? FONT_SRC_SELF : FONT_SRC_CDN).append(SEPARATOR)
185+
.append(IMG_SRC).append(useCdn ? IMG_SRC_CDN : IMG_SRC_SELF).append(SEPARATOR)
186+
.append(useCdn ? FONT_SRC_CDN : FONT_SRC_SELF).append(SEPARATOR)
187187
.append(REPORT_URI).append(host).append(SiteUrl.CSP_REPORTS_HANDLER).append(SEPARATOR)
188188
.append(STYLE_SRC)
189-
.append(useSingleHost ? STYLES_SELF : STYLES_CDN);
189+
.append(useCdn ? STYLES_CDN : STYLES_SELF);
190190

191191
if (onCollectionInfoPage) {
192192
sb.append(STYLE_COLLECTION_INFO);
@@ -204,7 +204,7 @@ protected String constructDirectives(String uri) {
204204

205205
sb.append(SEPARATOR)
206206
.append(SCRIPT_SRC)
207-
.append(useSingleHost ? SCRIPTS_SELF : SCRIPTS_CDN);
207+
.append(useCdn ? SCRIPTS_CDN : SCRIPTS_SELF);
208208

209209
if (onCollectionInfoPage) {
210210
sb.append(SCRIPT_COLLECTION_INFO);

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ public void configure(WebSecurity web) throws Exception {
8080
@Override
8181
@SuppressWarnings({ "PMD.SignatureDeclareThrowsException", "checkstyle:linelength" })
8282
protected void configure(HttpSecurity http) throws Exception {
83-
boolean useSingleHost = !environment.acceptsProfiles("prod");
83+
boolean useCdn = environment.acceptsProfiles("prod");
8484
boolean hasH2Console = environment.acceptsProfiles("test");
8585

8686
// @todo #226 Introduce app.use-public-hostname property
8787
boolean usePublicHostname = environment.acceptsProfiles("prod");
8888
String hostname = usePublicHostname ? SiteUrl.PUBLIC_URL : SiteUrl.SITE;
8989

9090
ContentSecurityPolicyHeaderWriter cspWriter =
91-
new ContentSecurityPolicyHeaderWriter(useSingleHost, hasH2Console, hostname);
91+
new ContentSecurityPolicyHeaderWriter(useCdn, hasH2Console, hostname);
9292

9393
http
9494
.authorizeRequests()

src/test/java/ru/mystamps/web/support/spring/security/ContentSecurityPolicyHeaderWriterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void writeContentSecurityPolicyHeader() {
6666
@Test
6767
public void onIndexPageWithLocalResources() {
6868
ContentSecurityPolicyHeaderWriter writer =
69-
new ContentSecurityPolicyHeaderWriter(true, bool(), SiteUrl.SITE);
69+
new ContentSecurityPolicyHeaderWriter(false, bool(), SiteUrl.SITE);
7070
String[] directives = writer.constructDirectives("/").split(";");
7171

7272
assertThat(directives, hasItemInArray("default-src 'none'"));
@@ -92,7 +92,7 @@ public void onIndexPageWithLocalResources() {
9292
@Test
9393
public void onIndexPageWithResourcesFromCdn() {
9494
ContentSecurityPolicyHeaderWriter writer
95-
= new ContentSecurityPolicyHeaderWriter(false, bool(), SiteUrl.PUBLIC_URL);
95+
= new ContentSecurityPolicyHeaderWriter(true, bool(), SiteUrl.PUBLIC_URL);
9696
String[] directives = writer.constructDirectives("/").split(";");
9797

9898
assertThat(directives, hasItemInArray("default-src 'none'"));
@@ -136,7 +136,7 @@ public void onIndexPageWithResourcesFromCdn() {
136136
@Test
137137
public void onCollectionInfoPageWithLocalResources() {
138138
ContentSecurityPolicyHeaderWriter writer =
139-
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
139+
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
140140
String[] directives = writer.constructDirectives("/collection/user").split(";");
141141

142142
// test only the directives that differ from the index page
@@ -169,7 +169,7 @@ public void onCollectionInfoPageWithLocalResources() {
169169
@Test
170170
public void onCollectionInfoPageWithResourcesFromCdn() {
171171
ContentSecurityPolicyHeaderWriter writer =
172-
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
172+
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
173173
String[] directives = writer.constructDirectives("/collection/user").split(";");
174174

175175
// test only the directives that differ from the index page
@@ -205,7 +205,7 @@ public void onCollectionInfoPageWithResourcesFromCdn() {
205205
@Test
206206
public void onSeriesAddImagePageWithLocalResources() {
207207
ContentSecurityPolicyHeaderWriter writer =
208-
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
208+
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
209209

210210
for (String page : new String[]{"/series/11", "/series/12/ask", "/series/13/image"}) {
211211
String[] directives = writer.constructDirectives(page).split(";");
@@ -231,7 +231,7 @@ public void onSeriesAddImagePageWithLocalResources() {
231231
@Test
232232
public void onSeriesAddImagePageWithResourcesFromCdn() {
233233
ContentSecurityPolicyHeaderWriter writer =
234-
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
234+
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
235235

236236
for (String page : new String[]{"/series/11", "/series/12/ask", "/series/13/image"}) {
237237
String[] directives = writer.constructDirectives(page).split(";");
@@ -270,7 +270,7 @@ public void onSeriesAddImagePageWithResourcesFromCdn() {
270270
@Test
271271
public void onSeriesAddPageWithLocalResources() {
272272
ContentSecurityPolicyHeaderWriter writer =
273-
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
273+
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
274274
String[] directives = writer.constructDirectives("/series/add").split(";");
275275

276276
// test only the directives that differ from the index page
@@ -304,7 +304,7 @@ public void onSeriesAddPageWithLocalResources() {
304304
@Test
305305
public void onSeriesAddPageWithResourcesFromCdn() {
306306
ContentSecurityPolicyHeaderWriter writer =
307-
new ContentSecurityPolicyHeaderWriter(false, bool(), Random.host());
307+
new ContentSecurityPolicyHeaderWriter(true, bool(), Random.host());
308308
String[] directives = writer.constructDirectives("/series/add").split(";");
309309

310310
// test only the directives that differ from the index page
@@ -341,7 +341,7 @@ public void onSeriesAddPageWithResourcesFromCdn() {
341341
@Test
342342
public void onH2ConsoleWithLocalResources() {
343343
ContentSecurityPolicyHeaderWriter writer =
344-
new ContentSecurityPolicyHeaderWriter(true, true, Random.host());
344+
new ContentSecurityPolicyHeaderWriter(false, true, Random.host());
345345
String[] directives = writer.constructDirectives("/console/").split(";");
346346

347347
// test only the directives that are differ from the index page
@@ -376,7 +376,7 @@ public void onH2ConsoleWithLocalResources() {
376376
@Test
377377
public void onH2ConsoleWithResourcesFromCdn() {
378378
ContentSecurityPolicyHeaderWriter writer =
379-
new ContentSecurityPolicyHeaderWriter(false, false, Random.host());
379+
new ContentSecurityPolicyHeaderWriter(true, false, Random.host());
380380
String[] directives = writer.constructDirectives("/console/").split(";");
381381

382382
// "style-src" directive should be the same as for the index page

0 commit comments

Comments
 (0)