Polish MockHttpServletRequest Usage

This commit makes so that the requestURI is set to a value that makes
sense with the other properties being mocked.

Issue gh-16632
This commit is contained in:
Josh Cummings 2025-03-26 11:12:37 -06:00
parent ad1ee28f01
commit 50ad378a29
No known key found for this signature in database
GPG Key ID: 869B37A20E876129
10 changed files with 52 additions and 37 deletions

View File

@ -78,7 +78,7 @@ public class CasAuthenticationFilterTests {
@Test @Test
public void testNormalOperation() throws Exception { public void testNormalOperation() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/login/cas");
request.setServletPath("/login/cas"); request.setServletPath("/login/cas");
request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ"); request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
CasAuthenticationFilter filter = new CasAuthenticationFilter(); CasAuthenticationFilter filter = new CasAuthenticationFilter();
@ -103,7 +103,7 @@ public class CasAuthenticationFilterTests {
String url = "/login/cas"; String url = "/login/cas";
CasAuthenticationFilter filter = new CasAuthenticationFilter(); CasAuthenticationFilter filter = new CasAuthenticationFilter();
filter.setFilterProcessesUrl(url); filter.setFilterProcessesUrl(url);
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", url);
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
request.setServletPath(url); request.setServletPath(url);
assertThat(filter.requiresAuthentication(request, response)).isTrue(); assertThat(filter.requiresAuthentication(request, response)).isTrue();
@ -132,10 +132,11 @@ public class CasAuthenticationFilterTests {
CasAuthenticationFilter filter = new CasAuthenticationFilter(); CasAuthenticationFilter filter = new CasAuthenticationFilter();
filter.setFilterProcessesUrl(url); filter.setFilterProcessesUrl(url);
filter.setServiceProperties(properties); filter.setServiceProperties(properties);
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", url);
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
request.setServletPath(url); request.setServletPath(url);
assertThat(filter.requiresAuthentication(request, response)).isTrue(); assertThat(filter.requiresAuthentication(request, response)).isTrue();
request = new MockHttpServletRequest("POST", "/other");
request.setServletPath("/other"); request.setServletPath("/other");
assertThat(filter.requiresAuthentication(request, response)).isFalse(); assertThat(filter.requiresAuthentication(request, response)).isFalse();
request.setParameter(properties.getArtifactParameter(), "value"); request.setParameter(properties.getArtifactParameter(), "value");
@ -170,7 +171,7 @@ public class CasAuthenticationFilterTests {
given(manager.authenticate(any(Authentication.class))).willReturn(authentication); given(manager.authenticate(any(Authentication.class))).willReturn(authentication);
ServiceProperties serviceProperties = new ServiceProperties(); ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.setAuthenticateAllArtifacts(true); serviceProperties.setAuthenticateAllArtifacts(true);
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/authenticate");
request.setParameter("ticket", "ST-1-123"); request.setParameter("ticket", "ST-1-123");
request.setServletPath("/authenticate"); request.setServletPath("/authenticate");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();

View File

@ -102,7 +102,7 @@ public class OpenSaml4AuthenticationRequestResolverTests {
} }
private MockHttpServletRequest givenRequest(String path) { private MockHttpServletRequest givenRequest(String path) {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("GET", path);
request.setServletPath(path); request.setServletPath(path);
return request; return request;
} }

View File

@ -102,7 +102,7 @@ public class OpenSaml5AuthenticationRequestResolverTests {
} }
private MockHttpServletRequest givenRequest(String path) { private MockHttpServletRequest givenRequest(String path) {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("GET", path);
request.setServletPath(path); request.setServletPath(path);
return request; return request;
} }

View File

@ -43,7 +43,8 @@ public class DefaultRelyingPartyRegistrationResolverTests {
@Test @Test
public void resolveWhenRequestContainsRegistrationIdThenResolves() { public void resolveWhenRequestContainsRegistrationIdThenResolves() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("GET",
"/some/path/" + this.registration.getRegistrationId());
request.setPathInfo("/some/path/" + this.registration.getRegistrationId()); request.setPathInfo("/some/path/" + this.registration.getRegistrationId());
RelyingPartyRegistration registration = this.resolver.convert(request); RelyingPartyRegistration registration = this.resolver.convert(request);
assertThat(registration).isNotNull(); assertThat(registration).isNotNull();

View File

@ -74,39 +74,39 @@ public class Saml2MetadataFilterTests {
@Test @Test
public void doFilterWhenMatcherSucceedsThenResolverInvoked() throws Exception { public void doFilterWhenMatcherSucceedsThenResolverInvoked() throws Exception {
this.request.setPathInfo("/saml2/service-provider-metadata/registration-id"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/registration-id");
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verifyNoInteractions(this.chain); verifyNoInteractions(this.chain);
verify(this.repository).findByRegistrationId("registration-id"); verify(this.repository).findByRegistrationId("registration-id");
} }
@Test @Test
public void doFilterWhenMatcherFailsThenProcessesFilterChain() throws Exception { public void doFilterWhenMatcherFailsThenProcessesFilterChain() throws Exception {
this.request.setPathInfo("/saml2/authenticate/registration-id"); MockHttpServletRequest request = uri("/saml2/authenticate/registration-id");
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verify(this.chain).doFilter(this.request, this.response); verify(this.chain).doFilter(request, this.response);
} }
@Test @Test
public void doFilterWhenNoRelyingPartyRegistrationThenUnauthorized() throws Exception { public void doFilterWhenNoRelyingPartyRegistrationThenUnauthorized() throws Exception {
this.request.setPathInfo("/saml2/service-provider-metadata/invalidRegistration"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/invalidRegistration");
given(this.repository.findByRegistrationId("invalidRegistration")).willReturn(null); given(this.repository.findByRegistrationId("invalidRegistration")).willReturn(null);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verifyNoInteractions(this.chain); verifyNoInteractions(this.chain);
assertThat(this.response.getStatus()).isEqualTo(401); assertThat(this.response.getStatus()).isEqualTo(401);
} }
@Test @Test
public void doFilterWhenRelyingPartyRegistrationFoundThenInvokesMetadataResolver() throws Exception { public void doFilterWhenRelyingPartyRegistrationFoundThenInvokesMetadataResolver() throws Exception {
this.request.setPathInfo("/saml2/service-provider-metadata/validRegistration"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/validRegistration");
RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.noCredentials() RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.noCredentials()
.assertingPartyDetails((party) -> party .assertingPartyDetails((party) -> party
.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))) .verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
.build(); .build();
String generatedMetadata = "<xml>test</xml>"; String generatedMetadata = "<xml>test</xml>";
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata); given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
this.filter = new Saml2MetadataFilter((request, registrationId) -> validRegistration, this.resolver); this.filter = new Saml2MetadataFilter((r, registrationId) -> validRegistration, this.resolver);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verifyNoInteractions(this.chain); verifyNoInteractions(this.chain);
assertThat(this.response.getStatus()).isEqualTo(200); assertThat(this.response.getStatus()).isEqualTo(200);
assertThat(this.response.getContentAsString()).isEqualTo(generatedMetadata); assertThat(this.response.getContentAsString()).isEqualTo(generatedMetadata);
@ -128,9 +128,9 @@ public class Saml2MetadataFilterTests {
@Test @Test
public void doFilterWhenCustomRequestMatcherThenUses() throws Exception { public void doFilterWhenCustomRequestMatcherThenUses() throws Exception {
this.request.setPathInfo("/path"); MockHttpServletRequest request = uri("/path");
this.filter.setRequestMatcher(new AntPathRequestMatcher("/path")); this.filter.setRequestMatcher(new AntPathRequestMatcher("/path"));
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verifyNoInteractions(this.chain); verifyNoInteractions(this.chain);
verify(this.repository).findByRegistrationId("path"); verify(this.repository).findByRegistrationId("path");
} }
@ -142,11 +142,11 @@ public class Saml2MetadataFilterTests {
String fileName = testMetadataFilename.replace("{registrationId}", validRegistration.getRegistrationId()); String fileName = testMetadataFilename.replace("{registrationId}", validRegistration.getRegistrationId());
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()); String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
String generatedMetadata = "<xml>test</xml>"; String generatedMetadata = "<xml>test</xml>";
this.request.setPathInfo("/saml2/service-provider-metadata/registration-id"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/registration-id");
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata); given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
this.filter = new Saml2MetadataFilter((request, registrationId) -> validRegistration, this.resolver); this.filter = new Saml2MetadataFilter((r, registrationId) -> validRegistration, this.resolver);
this.filter.setMetadataFilename(testMetadataFilename); this.filter.setMetadataFilename(testMetadataFilename);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
assertThat(this.response.getHeaderValue(HttpHeaders.CONTENT_DISPOSITION)).asString() assertThat(this.response.getHeaderValue(HttpHeaders.CONTENT_DISPOSITION)).asString()
.isEqualTo("attachment; filename=\"%s\"; filename*=UTF-8''%s", fileName, encodedFileName); .isEqualTo("attachment; filename=\"%s\"; filename*=UTF-8''%s", fileName, encodedFileName);
} }
@ -160,8 +160,8 @@ public class Saml2MetadataFilterTests {
(id) -> this.repository.findByRegistrationId("registration-id")); (id) -> this.repository.findByRegistrationId("registration-id"));
this.filter = new Saml2MetadataFilter(resolver, this.resolver); this.filter = new Saml2MetadataFilter(resolver, this.resolver);
this.filter.setRequestMatcher(new AntPathRequestMatcher("/metadata")); this.filter.setRequestMatcher(new AntPathRequestMatcher("/metadata"));
this.request.setPathInfo("/metadata"); MockHttpServletRequest request = uri("/metadata");
this.filter.doFilter(this.request, this.response, new MockFilterChain()); this.filter.doFilter(request, this.response, new MockFilterChain());
verify(this.repository).findByRegistrationId("registration-id"); verify(this.repository).findByRegistrationId("registration-id");
} }
@ -174,8 +174,8 @@ public class Saml2MetadataFilterTests {
this.filter = new Saml2MetadataFilter((id) -> this.repository.findByRegistrationId("registration-id"), this.filter = new Saml2MetadataFilter((id) -> this.repository.findByRegistrationId("registration-id"),
this.resolver); this.resolver);
this.filter.setRequestMatcher(new AntPathRequestMatcher("/metadata")); this.filter.setRequestMatcher(new AntPathRequestMatcher("/metadata"));
this.request.setPathInfo("/metadata"); MockHttpServletRequest request = uri("/metadata");
this.filter.doFilter(this.request, this.response, new MockFilterChain()); this.filter.doFilter(request, this.response, new MockFilterChain());
verify(this.repository).findByRegistrationId("registration-id"); verify(this.repository).findByRegistrationId("registration-id");
} }
@ -185,11 +185,11 @@ public class Saml2MetadataFilterTests {
RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.full().build(); RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.full().build();
String testMetadataFilename = "test-{registrationId}-metadata.xml"; String testMetadataFilename = "test-{registrationId}-metadata.xml";
String generatedMetadata = "<xml>testäöü</xml>"; String generatedMetadata = "<xml>testäöü</xml>";
this.request.setPathInfo("/saml2/service-provider-metadata/registration-id"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/registration-id");
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata); given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
this.filter = new Saml2MetadataFilter((req, id) -> validRegistration, this.resolver); this.filter = new Saml2MetadataFilter((req, id) -> validRegistration, this.resolver);
this.filter.setMetadataFilename(testMetadataFilename); this.filter.setMetadataFilename(testMetadataFilename);
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
assertThat(this.response.getCharacterEncoding()).isEqualTo(StandardCharsets.UTF_8.name()); assertThat(this.response.getCharacterEncoding()).isEqualTo(StandardCharsets.UTF_8.name());
assertThat(this.response.getContentAsString(StandardCharsets.UTF_8)).isEqualTo(generatedMetadata); assertThat(this.response.getContentAsString(StandardCharsets.UTF_8)).isEqualTo(generatedMetadata);
assertThat(this.response.getContentLength()) assertThat(this.response.getContentLength())
@ -218,9 +218,15 @@ public class Saml2MetadataFilterTests {
public void constructorWhenRelyingPartyRegistrationRepositoryThenUses() throws Exception { public void constructorWhenRelyingPartyRegistrationRepositoryThenUses() throws Exception {
RelyingPartyRegistrationRepository repository = mock(RelyingPartyRegistrationRepository.class); RelyingPartyRegistrationRepository repository = mock(RelyingPartyRegistrationRepository.class);
this.filter = new Saml2MetadataFilter(repository, this.resolver); this.filter = new Saml2MetadataFilter(repository, this.resolver);
this.request.setPathInfo("/saml2/service-provider-metadata/one"); MockHttpServletRequest request = uri("/saml2/service-provider-metadata/one");
this.filter.doFilter(this.request, this.response, this.chain); this.filter.doFilter(request, this.response, this.chain);
verify(repository).findByRegistrationId("one"); verify(repository).findByRegistrationId("one");
} }
private MockHttpServletRequest uri(String uri) {
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
request.setPathInfo(uri);
return request;
}
} }

View File

@ -68,6 +68,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
@BeforeEach @BeforeEach
public void setup() { public void setup() {
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository); this.filter = new Saml2WebSsoAuthenticationFilter(this.repository);
this.request.setRequestURI("/login/saml2/sso/idp-registration-id");
this.request.setPathInfo("/login/saml2/sso/idp-registration-id"); this.request.setPathInfo("/login/saml2/sso/idp-registration-id");
this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here"); this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here");
} }
@ -99,6 +100,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
@Test @Test
public void requiresAuthenticationWhenCustomProcessingUrlThenReturnsTrue() { public void requiresAuthenticationWhenCustomProcessingUrlThenReturnsTrue() {
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}"); this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
this.request.setRequestURI("/some/other/path/idp-registration-id");
this.request.setPathInfo("/some/other/path/idp-registration-id"); this.request.setPathInfo("/some/other/path/idp-registration-id");
this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here"); this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here");
assertThat(this.filter.requiresAuthentication(this.request, this.response)).isTrue(); assertThat(this.filter.requiresAuthentication(this.request, this.response)).isTrue();
@ -108,6 +110,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
public void attemptAuthenticationWhenRegistrationIdDoesNotExistThenThrowsException() { public void attemptAuthenticationWhenRegistrationIdDoesNotExistThenThrowsException() {
given(this.repository.findByRegistrationId("non-existent-id")).willReturn(null); given(this.repository.findByRegistrationId("non-existent-id")).willReturn(null);
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}"); this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
this.request.setRequestURI("/some/other/path/non-existent-id");
this.request.setPathInfo("/some/other/path/non-existent-id"); this.request.setPathInfo("/some/other/path/non-existent-id");
this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "response"); this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "response");
assertThatExceptionOfType(Saml2AuthenticationException.class) assertThatExceptionOfType(Saml2AuthenticationException.class)
@ -123,6 +126,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
given(authenticationConverter.convert(this.request)).willReturn(TestSaml2AuthenticationTokens.token()); given(authenticationConverter.convert(this.request)).willReturn(TestSaml2AuthenticationTokens.token());
this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}"); this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}");
this.filter.setAuthenticationManager((authentication) -> null); this.filter.setAuthenticationManager((authentication) -> null);
this.request.setRequestURI("/some/other/path/idp-registration-id");
this.request.setPathInfo("/some/other/path/idp-registration-id"); this.request.setPathInfo("/some/other/path/idp-registration-id");
this.filter.setAuthenticationRequestRepository(authenticationRequestRepository); this.filter.setAuthenticationRequestRepository(authenticationRequestRepository);
this.filter.attemptAuthentication(this.request, this.response); this.filter.attemptAuthentication(this.request, this.response);
@ -201,6 +205,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
Saml2AuthenticationTokenConverter authenticationConverter = new Saml2AuthenticationTokenConverter(resolver); Saml2AuthenticationTokenConverter authenticationConverter = new Saml2AuthenticationTokenConverter(resolver);
this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, loginProcessingUrl); this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, loginProcessingUrl);
this.filter.setAuthenticationManager(this.authenticationManager); this.filter.setAuthenticationManager(this.authenticationManager);
this.request.setRequestURI("/registration-id/login/saml2/sso");
this.request.setPathInfo("/registration-id/login/saml2/sso"); this.request.setPathInfo("/registration-id/login/saml2/sso");
this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "response"); this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "response");
this.filter.doFilter(this.request, this.response, new MockFilterChain()); this.filter.doFilter(this.request, this.response, new MockFilterChain());

View File

@ -100,7 +100,7 @@ public class AbstractAuthenticationProcessingFilterTests {
@Test @Test
public void testDefaultProcessesFilterUrlMatchesWithPathParameter() { public void testDefaultProcessesFilterUrlMatchesWithPathParameter() {
MockHttpServletRequest request = createMockAuthenticationRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/login;jsessionid=I8MIONOSTHOR");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
MockAuthenticationFilter filter = new MockAuthenticationFilter(); MockAuthenticationFilter filter = new MockAuthenticationFilter();
filter.setFilterProcessesUrl("/login"); filter.setFilterProcessesUrl("/login");

View File

@ -39,9 +39,9 @@ public class LogoutHandlerTests {
@Test @Test
public void testRequiresLogoutUrlWorksWithPathParams() { public void testRequiresLogoutUrlWorksWithPathParams() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/context/logout;someparam=blah");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
request.setRequestURI("/context/logout;someparam=blah?param=blah"); request.setContextPath("/context");
request.setServletPath("/logout;someparam=blah"); request.setServletPath("/logout;someparam=blah");
request.setQueryString("otherparam=blah"); request.setQueryString("otherparam=blah");
DefaultHttpFirewall fw = new DefaultHttpFirewall(); DefaultHttpFirewall fw = new DefaultHttpFirewall();
@ -50,12 +50,11 @@ public class LogoutHandlerTests {
@Test @Test
public void testRequiresLogoutUrlWorksWithQueryParams() { public void testRequiresLogoutUrlWorksWithQueryParams() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/logout");
request.setContextPath("/context"); request.setContextPath("/context");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
request.setServletPath("/logout"); request.setServletPath("/logout");
request.setRequestURI("/context/logout?param=blah"); request.setQueryString("param=blah");
request.setQueryString("otherparam=blah");
assertThat(this.filter.requiresLogout(request, response)).isTrue(); assertThat(this.filter.requiresLogout(request, response)).isTrue();
} }

View File

@ -65,6 +65,7 @@ public class GenerateOneTimeTokenFilterTests {
void setup() { void setup() {
this.request.setMethod("POST"); this.request.setMethod("POST");
this.request.setServletPath("/ott/generate"); this.request.setServletPath("/ott/generate");
this.request.setRequestURI("/ott/generate");
} }
@Test @Test

View File

@ -37,7 +37,7 @@ class DefaultOneTimeTokenSubmitPageGeneratingFilterTests {
DefaultOneTimeTokenSubmitPageGeneratingFilter filter = new DefaultOneTimeTokenSubmitPageGeneratingFilter(); DefaultOneTimeTokenSubmitPageGeneratingFilter filter = new DefaultOneTimeTokenSubmitPageGeneratingFilter();
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login/ott");
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
@ -47,6 +47,7 @@ class DefaultOneTimeTokenSubmitPageGeneratingFilterTests {
void setup() { void setup() {
this.request.setMethod("GET"); this.request.setMethod("GET");
this.request.setServletPath("/login/ott"); this.request.setServletPath("/login/ott");
this.request.setRequestURI("/login/ott");
} }
@Test @Test
@ -80,6 +81,7 @@ class DefaultOneTimeTokenSubmitPageGeneratingFilterTests {
@Test @Test
void setContextThenGenerates() throws Exception { void setContextThenGenerates() throws Exception {
this.request.setContextPath("/context"); this.request.setContextPath("/context");
this.request.setRequestURI("/context/login/ott");
this.filter.setLoginProcessingUrl("/login/another"); this.filter.setLoginProcessingUrl("/login/another");
this.filter.doFilterInternal(this.request, this.response, this.filterChain); this.filter.doFilterInternal(this.request, this.response, this.filterChain);
String response = this.response.getContentAsString(); String response = this.response.getContentAsString();