Skip to content

Commit dd9f954

Browse files
author
Steve Riesenberg
committed
Fix tests in CsrfConfigurerTests
Closes gh-12241
1 parent 5da78f4 commit dd9f954

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Diff for: config/src/test/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurerTests.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,7 @@ public void loginWhenXorCsrfTokenRequestAttributeHandlerSetAndMaskedCsrfTokenThe
521521
}
522522

523523
@Test
524-
public void loginWhenFormLoginAndCookieCsrfTokenRepositorySetAndExistingTokenThenRemovesAndGeneratesNewToken()
525-
throws Exception {
524+
public void loginWhenFormLoginAndCookieCsrfTokenRepositorySetAndExistingTokenThenRemoves() throws Exception {
526525
CsrfToken csrfToken = new DefaultCsrfToken("X-XSRF-TOKEN", "_csrf", "token");
527526
Cookie existingCookie = new Cookie("XSRF-TOKEN", csrfToken.getToken());
528527
CookieCsrfTokenRepository csrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
@@ -541,13 +540,12 @@ public void loginWhenFormLoginAndCookieCsrfTokenRepositorySetAndExistingTokenThe
541540
MvcResult mvcResult = this.mvc.perform(loginRequest).andExpect(redirectedUrl("/")).andReturn();
542541
List<Cookie> cookies = Arrays.asList(mvcResult.getResponse().getCookies());
543542
cookies.removeIf((cookie) -> !cookie.getName().equalsIgnoreCase(existingCookie.getName()));
544-
assertThat(cookies).hasSize(2);
543+
assertThat(cookies).hasSize(1);
545544
assertThat(cookies.get(0).getValue()).isEmpty();
546-
assertThat(cookies.get(1).getValue()).isNotEmpty();
547545
}
548546

549547
@Test
550-
public void postWhenHttpBasicAndCookieCsrfTokenRepositorySetAndExistingTokenThenRemovesAndGeneratesNewToken()
548+
public void postWhenHttpBasicAndCookieCsrfTokenRepositorySetAndExistingTokenThenDoesNotGenerateNewToken()
551549
throws Exception {
552550
CsrfToken csrfToken = new DefaultCsrfToken("X-XSRF-TOKEN", "_csrf", "token");
553551
Cookie existingCookie = new Cookie("XSRF-TOKEN", csrfToken.getToken());
@@ -569,13 +567,11 @@ public void postWhenHttpBasicAndCookieCsrfTokenRepositorySetAndExistingTokenThen
569567
// @formatter:on
570568
List<Cookie> cookies = Arrays.asList(mvcResult.getResponse().getCookies());
571569
cookies.removeIf((cookie) -> !cookie.getName().equalsIgnoreCase(existingCookie.getName()));
572-
assertThat(cookies).hasSize(2);
573-
assertThat(cookies.get(0).getValue()).isEmpty();
574-
assertThat(cookies.get(1).getValue()).isNotEmpty();
570+
assertThat(cookies).isEmpty();
575571
}
576572

577573
@Test
578-
public void getWhenHttpBasicAndCookieCsrfTokenRepositorySetAndNoExistingCookieThenGeneratesNewToken()
574+
public void getWhenHttpBasicAndCookieCsrfTokenRepositorySetAndNoExistingCookieThenDoesNotGenerateNewToken()
579575
throws Exception {
580576
CsrfToken csrfToken = new DefaultCsrfToken("X-XSRF-TOKEN", "_csrf", "token");
581577
Cookie expectedCookie = new Cookie("XSRF-TOKEN", csrfToken.getToken());
@@ -596,8 +592,7 @@ public void getWhenHttpBasicAndCookieCsrfTokenRepositorySetAndNoExistingCookieTh
596592
// @formatter:on
597593
List<Cookie> cookies = Arrays.asList(mvcResult.getResponse().getCookies());
598594
cookies.removeIf((cookie) -> !cookie.getName().equalsIgnoreCase(expectedCookie.getName()));
599-
assertThat(cookies).hasSize(1);
600-
assertThat(cookies.get(0).getValue()).isNotEmpty();
595+
assertThat(cookies).isEmpty();
601596
}
602597

603598
@Configuration

0 commit comments

Comments
 (0)