From d941144f8c5b32f0fd04888e2645bdb929113fc6 Mon Sep 17 00:00:00 2001 From: Sami Date: Fri, 11 Oct 2024 22:44:24 -0400 Subject: [PATCH] day 7: Authentication and Authorization --- .../DaySeven/AuthenticationTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/java/zacksolutions/DaySeven/AuthenticationTest.java diff --git a/src/test/java/zacksolutions/DaySeven/AuthenticationTest.java b/src/test/java/zacksolutions/DaySeven/AuthenticationTest.java new file mode 100644 index 0000000..cd7aab2 --- /dev/null +++ b/src/test/java/zacksolutions/DaySeven/AuthenticationTest.java @@ -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(); + } +}