SEC-2832: Fix config tests
This commit is contained in:
parent
76d9ef4ec3
commit
d2fd852711
|
@ -232,6 +232,7 @@ class CsrfConfigurerTests extends BaseSpringSpec {
|
||||||
setup:
|
setup:
|
||||||
CsrfTokenRepositoryConfig.repo = Mock(CsrfTokenRepository)
|
CsrfTokenRepositoryConfig.repo = Mock(CsrfTokenRepository)
|
||||||
(1.._) * CsrfTokenRepositoryConfig.repo.loadToken(_) >> csrfToken
|
(1.._) * CsrfTokenRepositoryConfig.repo.loadToken(_) >> csrfToken
|
||||||
|
(1.._) * CsrfTokenRepositoryConfig.repo.generateToken(_) >> csrfToken
|
||||||
loadConfig(CsrfTokenRepositoryConfig)
|
loadConfig(CsrfTokenRepositoryConfig)
|
||||||
request.method = "POST"
|
request.method = "POST"
|
||||||
request.getSession()
|
request.getSession()
|
||||||
|
@ -381,6 +382,7 @@ class CsrfConfigurerTests extends BaseSpringSpec {
|
||||||
def "csrf disables POST requests from RequestCache"() {
|
def "csrf disables POST requests from RequestCache"() {
|
||||||
setup:
|
setup:
|
||||||
CsrfDisablesPostRequestFromRequestCacheConfig.repo = Mock(CsrfTokenRepository)
|
CsrfDisablesPostRequestFromRequestCacheConfig.repo = Mock(CsrfTokenRepository)
|
||||||
|
(1.._) * CsrfDisablesPostRequestFromRequestCacheConfig.repo.generateToken(_) >> csrfToken
|
||||||
loadConfig(CsrfDisablesPostRequestFromRequestCacheConfig)
|
loadConfig(CsrfDisablesPostRequestFromRequestCacheConfig)
|
||||||
request.servletPath = "/some-url"
|
request.servletPath = "/some-url"
|
||||||
request.requestURI = "/some-url"
|
request.requestURI = "/some-url"
|
||||||
|
@ -407,6 +409,7 @@ class CsrfConfigurerTests extends BaseSpringSpec {
|
||||||
def "csrf enables GET requests with RequestCache"() {
|
def "csrf enables GET requests with RequestCache"() {
|
||||||
setup:
|
setup:
|
||||||
CsrfDisablesPostRequestFromRequestCacheConfig.repo = Mock(CsrfTokenRepository)
|
CsrfDisablesPostRequestFromRequestCacheConfig.repo = Mock(CsrfTokenRepository)
|
||||||
|
(1.._) * CsrfDisablesPostRequestFromRequestCacheConfig.repo.generateToken(_) >> csrfToken
|
||||||
loadConfig(CsrfDisablesPostRequestFromRequestCacheConfig)
|
loadConfig(CsrfDisablesPostRequestFromRequestCacheConfig)
|
||||||
request.servletPath = "/some-url"
|
request.servletPath = "/some-url"
|
||||||
request.requestURI = "/some-url"
|
request.requestURI = "/some-url"
|
||||||
|
|
|
@ -144,6 +144,7 @@ class CsrfConfigTests extends AbstractHttpConfigTests {
|
||||||
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
||||||
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
||||||
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
|
when(repo.generateToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
request.setParameter(token.parameterName,token.token)
|
request.setParameter(token.parameterName,token.token)
|
||||||
request.servletPath = "/some-url"
|
request.servletPath = "/some-url"
|
||||||
request.requestURI = "/some-url"
|
request.requestURI = "/some-url"
|
||||||
|
@ -178,6 +179,7 @@ class CsrfConfigTests extends AbstractHttpConfigTests {
|
||||||
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
||||||
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
||||||
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
|
when(repo.generateToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
request.setParameter(token.parameterName,token.token)
|
request.setParameter(token.parameterName,token.token)
|
||||||
request.servletPath = "/some-url"
|
request.servletPath = "/some-url"
|
||||||
request.requestURI = "/some-url"
|
request.requestURI = "/some-url"
|
||||||
|
@ -277,6 +279,7 @@ class CsrfConfigTests extends AbstractHttpConfigTests {
|
||||||
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
CsrfTokenRepository repo = appContext.getBean("repo",CsrfTokenRepository)
|
||||||
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
CsrfToken token = new DefaultCsrfToken("X-CSRF-TOKEN","_csrf", "abc")
|
||||||
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
when(repo.loadToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
|
when(repo.generateToken(any(HttpServletRequest))).thenReturn(token)
|
||||||
request.setParameter(token.parameterName,token.token)
|
request.setParameter(token.parameterName,token.token)
|
||||||
request.method = "POST"
|
request.method = "POST"
|
||||||
request.setParameter("username","user")
|
request.setParameter("username","user")
|
||||||
|
|
Loading…
Reference in New Issue