Polish Tests

Tests should use an absolute path to address mock endpoints
This commit is contained in:
Josh Cummings 2020-02-25 12:47:25 -07:00
parent 2fb3d3d5a2
commit b33ed416e1
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
2 changed files with 18 additions and 16 deletions

View File

@ -15,20 +15,21 @@
*/
package org.springframework.security.integration;
import org.junit.Test;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
public class BasicAuthenticationTests extends AbstractWebServerIntegrationTests {
@Test
public void httpBasicWhenAuthenticationRequiredAndNotAuthenticatedThen401() throws Exception {
MockMvc mockMvc = createMockMvc("classpath:/spring/http-security-basic.xml", "classpath:/spring/in-memory-provider.xml", "classpath:/spring/testapp-servlet.xml");
mockMvc.perform(get("secure/index"))
mockMvc.perform(get("/secure/index"))
.andExpect(status().isUnauthorized());
}

View File

@ -15,6 +15,17 @@
*/
package org.springframework.security.integration;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.session.SessionDestroyedEvent;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
@ -25,16 +36,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.session.SessionDestroyedEvent;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
/**
* @author Luke Taylor
*/
@ -47,7 +48,7 @@ public class ConcurrentSessionManagementTests extends AbstractWebServerIntegrati
MockMvc mockMvc = createMockMvc("classpath:/spring/http-security-concurrency.xml", "classpath:/spring/in-memory-provider.xml", "classpath:/spring/testapp-servlet.xml");
mockMvc.perform(get("secure/index").session(session1))
mockMvc.perform(get("/secure/index").session(session1))
.andExpect(status().is3xxRedirection());
MockHttpServletRequestBuilder login1 = login()