You want to write a Postman test to check if the Content-Security-Policy header is present in the response.
Which assertion code snippet correctly verifies this?
Use Postman's built-in assertion methods to check headers.
Option A uses pm.response.to.have.header(), which is the correct way to assert header presence in Postman tests.
Option A calls has() but does not assert the result, so it won't fail the test if missing.
Option A tries to access headers like an object, which is invalid in Postman.
Option A uses to.have.property() which is not valid for headers.
What is the test result when running this Postman test if the response header X-Frame-Options has the value DENY?
pm.test('X-Frame-Options is DENY', () => {
pm.expect(pm.response.headers.get('X-Frame-Options')).to.eql('DENY');
});pm.test('X-Frame-Options is DENY', () => { pm.expect(pm.response.headers.get('X-Frame-Options')).to.eql('DENY'); });
Check if the header value matches exactly.
The test compares the header value to 'DENY'. If the header value is exactly 'DENY', the test passes.
If the value differs, it fails with an AssertionError.
Review this Postman test code snippet. It is intended to check if the Strict-Transport-Security header contains max-age=31536000. What error will occur when running this test?
pm.test('HSTS max-age check', () => {
const hsts = pm.response.headers.get('Strict-Transport-Security');
pm.expect(hsts.includes('max-age=31536000')).to.be.true;
});pm.test('HSTS max-age check', () => { const hsts = pm.response.headers.get('Strict-Transport-Security'); pm.expect(hsts.includes('max-age=31536000')).to.be.true; });
Consider what happens if the header is missing.
If the header Strict-Transport-Security is missing, pm.response.headers.get() returns null.
Calling includes() on null causes a TypeError.
You want to validate that the response contains these security headers with correct values:
- Content-Security-Policy: default-src 'self'
- X-Content-Type-Options: nosniff
- Referrer-Policy: no-referrer
Which approach is best to write these validations in Postman tests?
Think about clarity and test reporting.
Writing separate pm.test blocks for each header makes it clear which header fails if any.
Option D works but is less clear in reports.
Option D is incomplete testing.
Option D only checks count, not values.
You have multiple environments (dev, staging, production) with different base URLs. You want to automate security header validation tests in Postman so they run on all environments without duplicating test scripts.
Which method best achieves this goal?
Think about reusability and maintainability.
Using collection variables for base URLs allows writing tests once and running them across environments by switching variables.
Copying or duplicating scripts increases maintenance effort and risk of inconsistency.