Which statement best describes the purpose of a Bearer token in API testing?
Think about how APIs verify who is making the request.
A Bearer token is sent in the Authorization header to prove the request is from an authenticated user or system.
Given this Postman test script, what will be the value of pm.environment.get('authStatus') after running?
pm.test('Check status code', function () { pm.response.to.have.status(200); if (pm.response.code === 200) { pm.environment.set('authStatus', 'success'); } else { pm.environment.set('authStatus', 'fail'); } });
Check how the script sets environment variables based on response code.
The script sets 'authStatus' to 'success' only if the response code is 200, otherwise 'fail'.
Which Postman test assertion correctly checks that the Authorization header contains a Bearer token?
Remember that the Bearer token is sent in the request headers, not response headers.
The Bearer token is part of the request's Authorization header. Option C correctly checks the request headers for 'Authorization' and verifies it starts with 'Bearer '.
What error will this Postman test script produce?
pm.test('Check Bearer token', () => { const authHeader = pm.request.headers.get('Authorization'); pm.expect(authHeader).to.match(/^Bearer\s\w+$/); });
Consider what happens if the Authorization header is missing or empty.
If the Authorization header is missing or does not match the regex, the assertion fails causing an AssertionError.
Which approach is the most secure and maintainable way to handle Bearer tokens in automated API tests using Postman?
Think about reusability and security of sensitive data in tests.
Storing the Bearer token in an environment variable allows easy updates and keeps sensitive data out of request bodies or hardcoded headers.