Package: assert-headers
assert_headersAssert HTTP headersUsageCLIGlobal usagepipinstallassert_headers# Assume headersSchema.json in current working directoryassert-headers-pyhttps://example.comor with specified configurationassert-headers-py--config./customConfiguration.jsonhttps://example.comin silent modeassert-headers-py--silent--config./customConfiguration.jsonhttps://example.comto see what version you are runningassert-headers-py--versionAdvanced CLI UsageTODO: Add example of how to stream a column of a .csv into the toolTODO: Show how the exit codes can be used in smoke testsCLI Configurationassert-headers-pycurrently accepts configuration in JSON or YAML formats. It allows specifying a schema for the headers, but also the outgoing origin and user-agent headers for the request. Below is an example configuration:{"userAgent":"assert-headers-py","origin":"https://example.com","schema":{"cache-control":false,"strict-transport-security":true,"x-content-type-options":"nosniff","x-frame-options":{"DENY":true,"SAMEORIGIN":false}}}userAgent:"assert-headers-py"origin:"https://example.com"schema:cache-control:Falsestrict-transport-security:Truex-content-type-options:"nosniff"x-frame-options:DENY:TrueSAMEORIGIN:FalseSchema Explanation:Note: Since the example format of the schema is JSON, the values will usefalseinstead ofFalseandtrueinstead ofTrue."disallowed-header-name": false- It is considered an error if this header is defined"required-header-name": true- It is considered an error if this header is missing (orundefined)"strict-header-name": "only good value"- It is considered an error if this header does not have this value"enumerated-header-name": { "good header value": true, "another good value": true }- It is considered an error if this header contains a value other than one markedtrue."enumerated-header-name": { "bad header value": false, "another bad value": false }- It is considered an error if this header contains a value not markedtrueIf no enumerated header values are markedtrue, all listed values are considered invalid values. It is highly recommended to ONLY usetrueandfalsefor enumerated valuesassertHeaderfromassert_headersimportassertHeaderheaders={"strict-transport-security":"max-age=31536000; includeSubDomains","x-content-type-options":"nosniff","x-frame-options":"DENY"}schema={"cache-control":False,"strict-transport-security":True,"x-content-type-options":"nosniff","x-frame-options":{# if any are true, the header value must match a true schema value"DENY":True}}try:assertHeaders(headers,schema)exceptBaseExceptionaserr:print("OOPS!")print(err.message)iferr.errors:forassertionErrorinerr.errors:print(f'The header{assertionError.headerName}was bad!')This can also be used inside a test library for validating HTTP response headers.assertHeaderFromUrlfromassert_headersimportassertHeaderFromUrlconfiguration={"userAgent":"Custom User Agent name","origin":"https://my-domain.com","schema":{"cache-control":False,"strict-transport-security":True,"x-content-type-options":"nosniff","x-frame-options":{# if any are true, the header value must match a true schema value"DENY":True}}}assertHeaderFromUrl("https://example.com/my-test-page",configuration)Contributing# 1. Install Poetry# 2. Install dependenciespoetryinstall# 3. Start contained environmentpoetryshell# 3 (alternate). Run virtualenv inside current shell# source ./venv/bin/activate# 4. Make changes# 5. Run testspoetryrunpytestIf installing additional dependencies:# Inside Poetry shell or virtualenv/venvpoetryaddmy_new_packageFor more information, refer tohttps://python-poetry.org/docs/basic-usage/.