【发布时间】:2016-01-06 16:25:13
【问题描述】:
我想测试 Grails Web 应用程序的安全性,确保只有某些角色可以 POST 并给出正确的响应。我在集成测试中有以下内容:
class MyIntegrationSpec extends IntegrationSpec {
def grailsApplication
def testdataService
def setup() {
testdataService.addTestData()
SpringSecurityUtils.reauthenticate 'user1', null
}
def cleanup() {
}
void "test case"() {
given:
RestBuilder rest = new RestBuilder()
when:
RestResponse response = rest.post("http://localhost:8080/${grailsApplication.metadata.'app.name'}/mycontroller/myaction") {
json([
data1: "foo",
data2: "bar"
])
}
then:
response.status == 200
}
}
不幸的是,集成测试在 Spring Security 启动之前运行,我收到以下错误:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8080/myapp/mycontroller/myaction":Connection refused: connect; nested exception is java.net.ConnectException
如何让我的集成测试运行,以便测试用户体验,尤其是安全性?
【问题讨论】: