Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@WebMvcTest permitAll() no longer works after upgrade to 2.6.0 #28765

Closed
markusheiden opened this issue Nov 21, 2021 · 1 comment
Closed

@WebMvcTest permitAll() no longer works after upgrade to 2.6.0 #28765

markusheiden opened this issue Nov 21, 2021 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@markusheiden
Copy link

After upgrading to 2.6.0 a @WebMvcTest controller test for an unauthenticated endpoint no longer works, because a 401 instead of a 200 is returned.

This looks similar to the @SpringBootTest issue #28759

Minimal repro:

@Order(1)
@Configuration
public class Security extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().antMatcher("/test/**").authorizeRequests()
                .antMatchers("/test").permitAll()
                .anyRequest().authenticated();
    }
}
@Order(2)
@Configuration
public class BaseSecurity extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated();
    }
}
@RestController
public class Controller {
    @GetMapping("/test")
    public String test() { return "test"; }
}
@WebMvcTest(Controller.class)
class ControllerTest {
    @Autowired
    private MockMvc mockMvc;
    @Test
    void test() throws Exception { mockMvc.perform(get("/test")).andExpect(status().isOk()); }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 21, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Nov 21, 2021

Thanks for the report. This is a duplicate of #28759 (@WebMvcTest uses @AutoConfigureMockMvc under the covers).

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants