[英]How to Do the Authentication in Rest Assured?
Unable to Authenticate the API using the Rest Assured?无法使用 Rest Assured 对 API 进行身份验证? Could somebody share 1 Example for Authentication and Authorization of API Using the Rest Assured?
有人可以分享 1 个使用 Rest Assured 的 API 身份验证和授权示例吗?
BASIC Authentication基本认证
given().auth()
.basic("username", "password")
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
PREEMPTIVE Authentication抢先认证
given().auth()
.preemptive()
.basic("username", "password")
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
DIGEST Authentication摘要认证
given().auth()
.digest("username", "user1Pass")
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
FORM Authentication表单认证
given().auth()
.form("user1", "user1Pass")
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
OAuth Authentication OAuth 认证
given().auth()
.oauth2(accessToken)
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
AUTHORIZATION授权
given()
.header("Authorization", "Basic XXXXXXXXXXXXXXXXXX")
.when()
.get("http://anyURL")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.