Test Overview
This test checks that a Postman request correctly inherits authentication settings from its parent collection. It verifies that the request uses the collection's auth token to access a protected API endpoint.
This test checks that a Postman request correctly inherits authentication settings from its parent collection. It verifies that the request uses the collection's auth token to access a protected API endpoint.
pm.test("Request inherits auth from collection and receives 200 OK", function () { pm.sendRequest({ url: pm.environment.get("api_url") + "/protected/resource", method: 'GET', header: { 'Authorization': pm.collectionVariables.get('auth_token') } }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('code', 200); pm.expect(res.json()).to.have.property('success', true); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Postman prepares the GET request to the protected API endpoint | Postman environment has 'api_url' and collection variable 'auth_token' set | - | PASS |
| 2 | Postman sends the GET request with Authorization header from collection variable | Request is sent to the API server with the auth token inherited from collection | - | PASS |
| 3 | Postman receives response from API server | Response status code is 200 OK with JSON body containing success: true | Check that error is null, status code is 200, and response JSON has success: true | PASS |
| 4 | Assertions verify the response is successful and authorized | Test script confirms auth inheritance works correctly | pm.expect(err).to.be.null; pm.expect(res).to.have.property('code', 200); pm.expect(res.json()).to.have.property('success', true); | PASS |