mitmproxy/test
Matthew Hughes d9cac6fbcd
Make Cert.not{before,after} timezone aware (#4805)
I noticed when running tests the output of
`web/src/js/__tests__/ducks/_tflow.ts` would change depending on how I
set my timezone, e.g.

    $ TZ=America/Los_Angeles pytest --quiet \
        test/mitmproxy/tools/web/test_app.py >/dev/null \
        && grep --extended-regexp 'not(after|before)' web/src/js/__tests__/ducks/_tflow.ts
                "notafter": 2235132207,
                "notbefore": 1604415807,
    $ TZ=Asia/Tokyo pytest --quiet \
        test/mitmproxy/tools/web/test_app.py >/dev/null \
        && grep --extended-regexp 'not(after|before)'  web/src/js/__tests__/ducks/_tflow.ts
                "notafter": 2235074607,
                "notbefore": 1604354607

It looks like this is because the `cert_to_json` function simply calls
`timestamp` the `datetime` object from
`x509.Certificate.not_valid_before`, however, this `datetime` object is
not timestamp aware, from the docs [1]:

> A naïve datetime representing the beginning of the validity period for
the certificate in UTC

So when serializing to JSON, first convert the `datetime` to UTC then
call `timestamp`.

A test was added by inspecting one of the test certs with:

    $ openssl x509 -in test/mitmproxy/net/data/text_cert_2 -text

Extracting the date and asserting on that.

The corresponding test has also been re-run so that `_tflow.ts` was
regenerated with it's correct value. Snapshots were also updated via:

    $(npm bin)/jest --updateSnapshot

[1] https://cryptography.io/en/latest/x509/reference/#cryptography.x509.Certificate.not_valid_after
2021-09-16 10:53:36 +02:00
..
bench Improve Markdown syntax(styling) (#4496) 2021-03-11 19:13:02 +01:00
examples docs++ 2021-02-13 00:13:37 +01:00
helper_tools make flake8 happy 2021-09-04 00:23:45 +02:00
mitmproxy Make Cert.not{before,after} timezone aware (#4805) 2021-09-16 10:53:36 +02:00
release master branch -> main branch 2021-03-30 15:30:45 +02:00
__init__.py move tests into shared folder 2016-02-15 16:34:22 +01:00
conftest.py cibuild: cleanup outdated providers 2020-12-14 20:01:32 +01:00
filename_matching.py nuke legacy protocol stack 2020-12-14 22:14:43 +01:00
full_coverage_plugin.py pyupgrade --py36-plus mitmproxy/**/*.py 2020-11-20 19:25:26 +01:00
individual_coverage.py remove pathod and pathoc 2020-12-13 20:21:11 +01:00