Skip to content

Option to run pre-requisite javascript for API testing  #2636

Open
@jestinsebastian

Description

@jestinsebastian

🚀 Feature Proposal

Have you read the contributing guidelines on issues?

  • Yes

Description

We are trying to use Saucelabs for our API automation along with our UI automation. But our APIs require HmacSHA1 authentication. We need to generate this using resource path, request method and time stamp. As far as I know, right now Saucelabs doesn't give an option to execute a pre-requisite script to generate such token. There is the option of hmacSha1(input : String, secret : String) : String but without having the option of Date in UTCString and resource path variable, it is not possible to use this.

Motivation

We are already using Saucelabs for our Mobile testing. Wanted to use it for our API testing as well.

Example

This is how we use it in Postman. Looking for a similar capability in Saucelabs.

var access_id = "access_id";
var secret_key = "secret_key";
const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());
var mydate = new Date();
var dateString = mydate.toUTCString();
var canon = [request.method, 'application/json', '', path,dateString].join(',');
var hash = CryptoJS.HmacSHA1(canon, secret_key);
token = hash.toString(CryptoJS.enc.Base64);
var authHeader = "APIAuth " + access_id + ":" + token;
pm.collectionVariables.set('dateHeader', mydate.toUTCString());
pm.collectionVariables.set('apiauth', authHeader);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions