0

*New to Rest Assured

Question:
How do I pass the email (User email required for GET endpoint) in the alias header and obtain the session ID as well as the username ID from the response?

Details: The [GET] users/signin endpoint requires a user email and an api key.

Curl:

curl -X GET "https://SomeWebSite.com/apiservice/users/signin?challengeMethod=EMAIL" -H "accept: application/json" -H "alias: usersignin@EXAMPLE.com" -H "X-API-KEY: d5a1d56d51d651d651d51d651d6d6d1"

Response:

{
"session": "ID inside of here",
"challengename": "CUSTOM_CHALLENGE",
"challengeSentTo": "usersignin@EXAMPLE.com",
"username": "5d654d6d65dd64d66adsb6a4"
}

My code:

public class AuthResponseTest {

    public static final String baseUri = "https://qa-mobile-app-auth-ext.clearcollateral.com/";
    public static final String basePath = "/apiservice/users ";

public String[] getSignIn() {

       return RestAssured
                .with()
                .log().all()
                .header("X-API-KEY", "API KEY IN HERE")
               .header("alias", "email here")
                .contentType(ContentType.JSON)
                .accept(ContentType.JSON)
                .baseUri(baseUri)
                .basePath(basePath)
               .when()
               .post("/users/signin")
               .then()
               .log().all()
               .statusCode(200)
       .extract().as(String[].class);
    }
    @Test
    public void testSignIn() {
        String[] authsignin =  getSignIn();
        System.out.println(authsignin);
    }
}
foragerEngineer
  • 149
  • 1
  • 2
  • 13
  • 1
    Did you try; `.header("alias", "usersignin@EXAMPLE.com")` – kaweesha Jun 19 '20 at 05:25
  • @kaweesha No I have not. I just tried it and it worked I believe. I do get a 405 error. However, this is a good sign. As I think this is expected since I'm currently working from a user interface API service that requires that you authenticate with an API key before using the end points available to me (Get, Post, Update, etc.). So I guess my initial question was answered. I may need to asked about how to provide an API key to an authenticator before running my endpoint tests. – foragerEngineer Jun 19 '20 at 05:37
  • @kaweesha since a 405 is for a Method not allowed response status code. Am I right in thinking that before I can use the endpoints I need to provide an API key to the authenticator? – foragerEngineer Jun 19 '20 at 05:40
  • Sorry, Im not familiar with authenticators. Please search more or add another question on your requirement.. – kaweesha Jun 19 '20 at 06:06
  • @kaweesha I have added Question 2 with detailed explanation and I hope it makes sense. – foragerEngineer Jun 19 '20 at 06:29
  • @kaweesha Sorry no need to answer the second follow up question. I feel that deserves to be it's own question in another thread. Thank you very much for answering my initial question. – foragerEngineer Jun 19 '20 at 06:32

1 Answers1

1

Try;

.header("alias", "usersignin@EXAMPLE.com")
kaweesha
  • 803
  • 6
  • 16