Adds the ability to set the CSRF Token cookie max age value

Closes gh-11432
This commit is contained in:
Alonso Araya Calvo
2022-06-24 14:40:14 -06:00
committed by Josh Cummings
parent c85b7c6c17
commit 1ac1271972
2 changed files with 45 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Eric Deandrea
* @author Thomas Vitale
* @author Alonso Araya
* @since 5.1
*/
public class CookieServerCsrfTokenRepositoryTests {
@@ -113,6 +114,12 @@ public class CookieServerCsrfTokenRepositoryTests {
saveAndAssertExpectedValues(createToken());
}
@Test
public void saveTokenWhenCookieMaxAgeThenCookieMaxAge() {
setExpectedCookieMaxAge(3600);
saveAndAssertExpectedValues(createToken());
}
@Test
public void saveTokenWhenCustomPropertiesThenCustomProperties() {
setExpectedDomain("spring.io");
@@ -120,6 +127,7 @@ public class CookieServerCsrfTokenRepositoryTests {
setExpectedPath("/some/path");
setExpectedHeaderName("headerName");
setExpectedParameterName("paramName");
setExpectedCookieMaxAge(3600);
saveAndAssertExpectedValues(createToken());
}
@@ -235,6 +243,11 @@ public class CookieServerCsrfTokenRepositoryTests {
this.csrfTokenRepository.setCookieName(expectedCookieName);
}
private void setExpectedCookieMaxAge(int expectedCookieMaxAge) {
this.csrfTokenRepository.setCookieMaxAge(expectedCookieMaxAge);
this.expectedMaxAge = Duration.ofSeconds(expectedCookieMaxAge);
}
private void setExpectedCookieValue(String expectedCookieValue) {
this.expectedCookieValue = expectedCookieValue;
}