我有一个工作的 spring-mvc 应用程序,带有休息服务和一些很好的放心测试:
@Test
public void createFoobarFromScratchReturns201(){
expect().statusCode(201).given()
.queryParam("foo", generateFoo())
.queryParam("bar", generateBar())
.when().post("/foo/bar/");
}
=> OK
然后我实现了一个摘要认证。一切正常,现在我必须登录才能使用我的服务:
curl http://localhost:8089/foo/bar
=> HTTP ERROR 401, Full authentication is required to access this resource
curl http://localhost:8089/foo/bar --digest -u user_test:password
=> HTTP 201, CREATED
但是当我尝试用最明显的功能升级我的测试时,我仍然有一个 401 错误:
@Test
public void createFoobarFromScratchReturns201(){
expect().statusCode(201).given()
.auth().digest("user_test", "password") // Digest added here
.queryParam("foo", generateFoo())
.queryParam("bar", generateBar())
.when().post("/foo/bar/");
}
=> Expected status code <201> doesn't match actual status code <401>
我发现了preemptive()函数的一些线索,但它似乎只针对 basic 实现:
// Returns an AuthenticatedScheme and stores it into the general configuration
RestAssured.authentication = preemptive().basic("user_test", "password");
// Try a similar thing, but it didn't work :
RestAssured.authentication = RestAssured.digest("user_test", "password");
目前,我正在努力实现两件事:
- 我需要升级一些测试以支持摘要
- 我需要修改我的其余测试套件(与身份验证问题无关)的@Before ,以便已经登录。
任何想法或文件?