title: Testing a secure REST endpoint with Spring MVC Test Framework
body: <p>I am trying to test a secure REST method, using <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#spring-mvc-test-framework" rel="nofollow noreferrer">Spring MVC Test Framework.</a></p>
  
  <pre><code>  val result = this.mockMvc!!
       .perform(get("/ping").with(SecurityMockMvcRequestPostProcessors.user("user")))
                  .andDo(MockMvcResultHandlers.print())
                  .andReturn()
  
    assertThat(result.response.contentAsString).contains("pong")
  </code></pre>
  
  <p>The problem is that on this request, the mocked server is responding a 302 code, to redirect to a secure channel. The result is never <code>2xx</code> code, is always a <code>302</code> code. I would like to follow this redirect, or perform the request on secure channel at the first time.</p>
  
  <p>How can I perform this test to do directly on a mocked secure channel?  </p>