POSTMAN : Validate response header with Javascript

While working with POSTMAN , we validate many headers and values as part of API testing.
We can validate API response and Headers using javascript

pm.test("Cache-Control is correct", function() {
    pm.response.to.have.header("Cache-Control");
    pm.response.to.be.header("Cache-Control", "no-cache, no-store, must-revalidate");
});

pm.test("X-Content-Type-Options is correct", function() {
    pm.response.to.have.header("X-Content-Type-Options");
    pm.response.to.be.header("X-Content-Type-Options", "nosniff");
});

pm.test("Strict-Transport-Security is correct", function() {
    pm.response.to.have.header("Strict-Transport-Security");
    pm.response.to.be.header("Strict-Transport-Security","max-age=15768000");
});

pm.test("Server is correct", function() {
    pm.response.to.have.header("Server");
    pm.response.to.be.header("Server","");
});

Leave a Reply