How do you write a Automation test script to validate access_token value in response body that keeps changing with each send request?

My question:
How do you write a Automation test script to validate access_token value in response body that keeps changing with each send request?

Hi @farhanhasanali

The detail you have provided is very minimal, but as far as I know, access tokens (in particular jwt/bearer tokens) are usually encoded with a time stamp so it would be incredibly difficult (practically impossible) to guess what the expected value should be โ€ฆ this is why they are considered secure.

You could however, consider capturing the token and decrypting it if you know the algorithm etc. used to encode it. You would then see the original values used to create the token โ€ฆ

Not sure if thatโ€™s what you are trying to achieve though.

2 Likes

Just to clarify: JWT tokens are not encrypted. They are encoded and can be read by anyone receiving it. The security relies on the way they are exchanged (for instance oAuth 2.0, as part of its specification, requires to have an encrypted connection on exchange).

1 Like

Thank you everyone for your helpโ€ฆ I noticed that i was able to get it to capture in console.
pm.test(" Validate access_token !=null or undefined validation ", function (){

    var jsonData = pm.response.json();

    pm.expect(jsonData.access_token).not.eql([null,undefined]);

    console.log("SUCCESS: - ACCESS TOKEN FIELD IS NOT NULL OR UNDEFINED")

    });
1 Like

Fair shout, my mistake, itโ€™s been a long week.

1 Like