在集成测试中,哪个类可以绕过Springboot安全性

时间:2017-04-07 14:03:58

标签: spring-security integration-testing spock spring-boot-test

@SpringBootTest(webEnvironment = RANDOM_PORT)
@ActiveProfiles("test")
class ContextLoadingSpec extends Specification {

    @Autowired
    TestRestTemplate testRestTemplate

    def '/ should load the context'() {
        when:
        ResponseEntity<Object> entity = testRestTemplate.getForEntity('/', Object.class)

        then:
        entity.statusCode == HttpStatus.OK
    }

    @TestConfiguration
    static class Config {

        @Bean
        RestTemplateBuilder restTemplateBuilder() {
            return new RestTemplateBuilder()
            .basicAuthorization('user', 'xxxxxxxx')
        }
    }
}

创建TestConfiguration对我来说似乎不对。凭据应该在&#39; application.yml&#39;并且应该模拟身份验证调用。请建议更好的方法来编写此测试。

0 个答案:

没有答案