【问题标题】:How to disable security in integration tests in Spring Boot 2.2.0?如何在 Spring Boot 2.2.0 的集成测试中禁用安全性?
【发布时间】:2020-04-05 23:36:32
【问题描述】:

我需要在集成测试中禁用 spring-security。我正在使用Spring boot 2.2.0,在这个版本中,我没有找到一些方法来做到这一点。

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

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

我该怎么做?

【问题讨论】:

标签: java spring spring-boot spring-security


【解决方案1】:

你可以通过个人资料玩这个游戏

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

【讨论】:

【解决方案2】:

你和我一定同时在同一件事上撞到了同一件事。

我能够让@AutoConfigureMockMvc(secure=false) 做我想做的事——禁用我的单元测试的所有安全性。但是,由于我使用的是 Spring Boot 2.1.6,它在我的 IDE 中立即被标记为弃用。我不喜欢使用已弃用的东西,所以我尝试并尝试让 exclude 属性起作用,但它从来没有。

我正要放弃它并遭受弃用警告,因为至少我的单元测试可以使用它。

一时兴起,我尝试将项目中的 Spring Boot 从 2.1.6 升级到 2.2.2。令我恐惧的是,secure 属性不再被弃用——它被完全删除了!我在属性消失的情况下对单元测试进行了一次旋转,但是 exclude 属性完全按照您在问题中显示的方式填充并且它起作用了!

TL;博士?升级到 Spring Boot 2.2.2

【讨论】:

    猜你喜欢
    • 2016-01-02
    • 2020-06-28
    • 2019-03-30
    • 1970-01-01
    • 2015-09-19
    • 2016-12-05
    • 2020-02-02
    相关资源
    最近更新 更多