day 7: Authentication and Authorization
This commit is contained in:
parent
66344f9e3c
commit
d941144f8c
63
src/test/java/zacksolutions/DaySeven/AuthenticationTest.java
Normal file
63
src/test/java/zacksolutions/DaySeven/AuthenticationTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
package zacksolutions.DaySeven;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static io.restassured.RestAssured.*;
|
||||
|
||||
/**
|
||||
* Authentication
|
||||
*/
|
||||
public class AuthenticationTest {
|
||||
|
||||
@Test(priority = 1)
|
||||
void testBasicAuth() {
|
||||
System.out.println("Starting the authenticantion using Basic auth");
|
||||
given().auth()
|
||||
.basic("postman", "password")
|
||||
.when().get("https://postman-echo.com/basic-auth")
|
||||
.then().statusCode(200).body("authenticated", equalTo(true)).log().all();
|
||||
|
||||
}
|
||||
|
||||
@Test(priority = 2)
|
||||
void testDigestAuth() {
|
||||
System.out.println("Starting the authenticantion using Digest auth");
|
||||
given().auth()
|
||||
.digest("postman", "password")
|
||||
.when().get("https://postman-echo.com/basic-auth")
|
||||
.then().statusCode(200).body("authenticated", equalTo(true)).log().all();
|
||||
|
||||
}
|
||||
|
||||
@Test(priority = 3)
|
||||
void testPreemptiveAuth() {
|
||||
System.out.println("Starting the authenticantion using Preemptive auth");
|
||||
given().auth()
|
||||
.preemptive().basic("postman", "password")
|
||||
.when().get("https://postman-echo.com/basic-auth")
|
||||
.then().statusCode(200).body("authenticated", equalTo(true)).log().all();
|
||||
|
||||
}
|
||||
|
||||
@Test(priority = 4)
|
||||
void testBearerTokenAuth() {
|
||||
System.out.println("Starting the authenticantion using Bearer Token auth");
|
||||
String bearerToken = "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";
|
||||
|
||||
given().headers("Authorization", "Bearer " + bearerToken)
|
||||
.when().get("https://api.github.com/user/repos")
|
||||
.then().statusCode(200).log().all();
|
||||
}
|
||||
|
||||
@Test(priority = 5)
|
||||
void testOAuth1Auth() {
|
||||
System.out.println("Starting the authenticantion using OAuth1 auth");
|
||||
String bearerToken = "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";
|
||||
|
||||
given().headers("Authorization", "Bearer " + bearerToken)
|
||||
.when().get("https://api.github.com/user/repos")
|
||||
.then().statusCode(200).log().all();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user