私は残りのサービスといくつかの安心できるテストを備えた動作中の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");
現在、私は2つのことを達成しようとしています:
- ダイジェストをサポートするためにいくつかのテストをアップグレードする必要があります
- 残りのテスト スイート (認証の問題とは関係ありません)の@Beforeを修正して、既にログインしている必要があります。
アイデアやドキュメントはありますか?