简体   繁体   English

如何在 Spring Boot 2.2.0 中禁用集成测试中的安全性?

[英]How to disable security in integration tests in Spring Boot 2.2.0?

I need to disable spring-security in my integration test.我需要在集成测试中禁用spring-security I'm using Spring boot 2.2.0 and in this version, I didn't find some methods to do it.我使用的是Spring boot 2.2.0 ,在这个版本中,我没有找到一些方法来做到这一点。

@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.我能够让@AutoConfigureMockMvc(secure=false)完全按照我的@AutoConfigureMockMvc(secure=false)去做——禁用我的单元测试的所有安全性。 However, it was immediately marked deprecated in my IDE because I was using Spring Boot 2.1.6.但是,它立即在我的 IDE 中被标记为已弃用,因为我使用的是 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.我不喜欢使用过时的东西,所以我尝试并试图让exclude属性起作用,但它从来没有。

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.一时兴起,我尝试将项目中的 Spring Boot 从 2.1.6 升级到 2.2.2。 To my horror, the secure attribute was no longer deprecated--it was removed altogether!令我震惊的是, secure属性不再被弃用——它被完全删除了! 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!我在属性消失的情况下对单元测试进行了旋转,但是完全按照您在问题中显示的方式填充了exclude属性并且它起作用了!

TL;DR?特尔;博士? Upgrade to Spring Boot 2.2.2升级到 Spring Boot 2.2.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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