简体   繁体   中英

How to disable security in integration tests in Spring Boot 2.2.0?

I need to disable spring-security in my integration test. I'm using Spring boot 2.2.0 and in this version, I didn't find some methods to do it.

@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class}) // not working

@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, ManagementSecurityAutoConfiguration.class }) // not working too.

how can I do it?

you could play this game via profile

@ActiveProfiles(value = "IntegrationTest")
public class myTest {

You and I must have been banging our heads against the same thing at the same time it seems.

I was able to make @AutoConfigureMockMvc(secure=false) do exactly what I wanted--disable all security for my unit tests. However, it was immediately marked deprecated in my IDE because I was using Spring Boot 2.1.6. I don't like using deprecated things so I tried and tried to get the exclude attribute to work, but it never did.

I was about to give up on it and suffer with the deprecation warning because at least my unit tests worked with it.

On a whim, I tried upgrading Spring Boot in my project from 2.1.6 to 2.2.2. To my horror, the secure attribute was no longer deprecated--it was removed altogether! I gave the unit test a spin with the attribute gone, but with the exclude attribute populated exactly as you show in your question and it worked!

TL;DR? Upgrade to Spring Boot 2.2.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM