assert_headers
Assert HTTP headers
Usage
CLI
Global usage
pip install assert_headers
# Assume headersSchema.json in current working directory
assert-headers-py https://example.com
or with specified configuration
assert-headers-py --config ./customConfiguration.json https://example.com
in silent mode
assert-headers-py --silent --config ./customConfiguration.json https://example.com
to see what version you are running
assert-headers-py --version
Advanced CLI Usage
TODO: Add example of how to stream a column of a .csv into the tool
TODO: Show how the exit codes can be used in smoke tests
CLI Configuration
assert-headers-py currently 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: False
strict-transport-security: True
x-content-type-options: "nosniff"
x-frame-options:
DENY: True
SAMEORIGIN: False
Schema Explanation:
Note: Since the example format of the schema is JSON, the values will use
falseinstead 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 markedtrue- If no enumerated header values are marked
true, all listed values are considered invalid values. It is highly recommended to ONLY usetrueandfalsefor enumerated values
assertHeader
from assert_headers import assertHeader
headers = {
"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)
except BaseException as err:
print("OOPS!")
print(err.message)
if err.errors:
for assertionError in err.errors:
print(f'The header {assertionError.headerName} was bad!')
This can also be used inside a test library for validating HTTP response headers.
assertHeaderFromUrl
from assert_headers import assertHeaderFromUrl
configuration = {
"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 dependencies
poetry install
# 3. Start contained environment
poetry shell
# 3 (alternate). Run virtualenv inside current shell
# source ./venv/bin/activate
# 4. Make changes
# 5. Run tests
poetry run pytest
If installing additional dependencies:
# Inside Poetry shell or virtualenv/venv
poetry add my_new_package
For more information, refer to https://python-poetry.org/docs/basic-usage/.
Metadata
Release files for assert-headers 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| assert_headers-1.0.0.tar.gz | 7.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| assert_headers-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / assert_headers-1.0.0.tar.gz
| Download URL | assert_headers-1.0.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec1c65a72f75074c965e0b56dfbe6b760e8e1aa2ba26905dfb309048b8aa94a8
|
|
BLAKE2b-256 checksum How to use checksums |
a631d8d1b2b4117714e00e455c2d1b73d287eeee76739b979508d2f1bb507557
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.8.2 Darwin/20.3.0
|
Release files / assert_headers-1.0.0-py3-none-any.whl
| Download URL | assert_headers-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1994b3b1d76d1207a8a92866767f8ff33bed9b0d7583eb9397f9a03a55d089d9
|
|
BLAKE2b-256 checksum How to use checksums |
53547fa8253af61397b8a0fc33e84ace93516deb06eebcad9988b629e703a9b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.8.2 Darwin/20.3.0
|
Security for assert-headers 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.