From eefc55f28feab92c0d637ab8f11e339cce827c87 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 30 Mar 2021 12:12:38 +0200 Subject: [PATCH] coverage++ --- mitmproxy/test/tflow.py | 7 +- test/mitmproxy/tools/web/test_app.py | 16 +- web/README.md | 4 + .../components/FlowTable/FlowColumnsSpec.js | 8 + .../__snapshots__/FlowColumnsSpec.js.snap | 10 +- .../__snapshots__/FlowRowSpec.js.snap | 2 +- .../__snapshots__/DetailsSpec.js.snap | 250 +++++++++++++----- .../__snapshots__/MessagesSpec.js.snap | 100 +------ web/src/js/__tests__/ducks/_tflow.js | 44 ++- 9 files changed, 244 insertions(+), 197 deletions(-) diff --git a/mitmproxy/test/tflow.py b/mitmproxy/test/tflow.py index 9f76d34eb..496e380b5 100644 --- a/mitmproxy/test/tflow.py +++ b/mitmproxy/test/tflow.py @@ -184,9 +184,6 @@ def tserver_conn() -> connection.Server: return c -def terr(content="error"): - """ - @return: mitmproxy.proxy.protocol.primitives.Error - """ - err = flow.Error(content) +def terr(content: str = "error") -> flow.Error: + err = flow.Error(content, 946681207) return err diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index 8af0f85bb..79456e600 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -1,9 +1,9 @@ +import asyncio import json as _json import logging -from unittest import mock import os -import asyncio import sys +from unittest import mock import pytest @@ -331,14 +331,18 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): # Set some value as constant, so that _tflow.js would not change every time. _tflow['client_conn']['id'] = "4a18d1a0-50a1-48dd-9aa6-d45d74282939" _tflow['id'] = "d91165be-ca1f-4612-88a9-c0f8696f3e29" - _tflow['error']['timestamp'] = 1495370312.4814785 - _tflow['response']['timestamp_end'] = 1495370312.4814625 - _tflow['response']['timestamp_start'] = 1495370312.481462 _tflow['server_conn']['id'] = "f087e7b2-6d0a-41a8-a8f0-e1a4761395f8" + _tflow["request"]["trailers"] = [["trailer", "qvalue"]] + _tflow["response"]["trailers"] = [["trailer", "qvalue"]] tflow_json = _json.dumps(_tflow, indent=4, sort_keys=True) here = os.path.abspath(os.path.dirname(__file__)) web_root = os.path.join(here, os.pardir, os.pardir, os.pardir, os.pardir, 'web') tflow_path = os.path.join(web_root, 'src/js/__tests__/ducks/_tflow.js') - content = f"""export default function(){{\n return {tflow_json}\n}}""" + content = ( + f"/** Auto-generated by test_app.py:TestApp._test_generate_tflow_js */\n" + f"export default function(){{\n" + f" return {tflow_json}\n" + f"}}" + ) with open(tflow_path, 'w', newline="\n") as f: f.write(content) diff --git a/web/README.md b/web/README.md index 7b412a5f1..1918583a8 100644 --- a/web/README.md +++ b/web/README.md @@ -7,6 +7,10 @@ and activate your virtualenv environment before proceeding.** - Run `yarn run gulp` to start live-compilation. - Run `mitmweb` and open http://localhost:8081/ +## Testing + +- Run `yarn run test` to run the testsuite. + ## Architecture There are two components: diff --git a/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js b/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js index 3622f3c1e..fdb69d12a 100644 --- a/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js +++ b/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js @@ -105,4 +105,12 @@ describe('FlowColumns Components', () => { tree = timeColumn.toJSON() expect(tree).toMatchSnapshot() }) + + it('should render TimeStampColumn', () => { + let timeStampColumn = renderer.create(), + tree = timeStampColumn.toJSON() + tflow.request.timestamp_start = + + expect(tree).toMatchSnapshot() + }) }) diff --git a/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowColumnsSpec.js.snap b/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowColumnsSpec.js.snap index 98ba8a109..f648ac98c 100644 --- a/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowColumnsSpec.js.snap +++ b/web/src/js/__tests__/components/FlowTable/__snapshots__/FlowColumnsSpec.js.snap @@ -127,7 +127,7 @@ exports[`FlowColumns Components should render TimeColumn 1`] = ` - 415381h + 3s `; @@ -139,6 +139,14 @@ exports[`FlowColumns Components should render TimeColumn 2`] = ` `; +exports[`FlowColumns Components should render TimeStampColumn 1`] = ` + + 1999-12-31 23:00:00.000 + +`; + exports[`FlowColumns Components should render pathColumn 1`] = ` - 415381h + 3s `; diff --git a/web/src/js/__tests__/components/FlowView/__snapshots__/DetailsSpec.js.snap b/web/src/js/__tests__/components/FlowView/__snapshots__/DetailsSpec.js.snap index 418567758..388b56a24 100644 --- a/web/src/js/__tests__/components/FlowView/__snapshots__/DetailsSpec.js.snap +++ b/web/src/js/__tests__/components/FlowView/__snapshots__/DetailsSpec.js.snap @@ -155,6 +155,18 @@ exports[`Details Component should render correctly 1`] = ` TLSv1.2 + + + + ALPN: + + + + http/1.1 + + Resolved address: @@ -182,24 +194,20 @@ exports[`Details Component should render correctly 1`] = ` className="timing-table" > - - Server conn. initiated : - 1970-01-01 00:00:01.000 - - - - - Client conn. established - : - - - 1970-01-01 00:00:01.000 + 1999-12-31 23:00:02.000 + + ( + 2s + ) + @@ -208,25 +216,57 @@ exports[`Details Component should render correctly 1`] = ` : - 1970-01-01 00:00:02.000 + 1999-12-31 23:00:03.000 + + ( + 3s + ) + + + + + + + Client conn. established + : + + + 1999-12-31 23:00:00.000 + + ( + 0ms + ) + + + + + + + First request byte + : + + + 1999-12-31 23:00:00.000 - Client conn. SSL handshake + Request complete : - 1970-01-01 00:00:02.000 - - - - - Server conn. SSL handshake - : - - - 1970-01-01 00:00:03.000 + 1999-12-31 23:00:01.000 + + ( + 1s + ) + @@ -235,7 +275,14 @@ exports[`Details Component should render correctly 1`] = ` : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:02.000 + + ( + 2s + ) + @@ -244,7 +291,14 @@ exports[`Details Component should render correctly 1`] = ` : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:03.000 + + ( + 3s + ) + @@ -323,8 +377,6 @@ exports[`Details Component should render correctly when server address is missin className="timing-table" > - - @@ -334,16 +386,40 @@ exports[`Details Component should render correctly when server address is missin : - 1970-01-01 00:00:01.000 + 1999-12-31 23:00:00.000 + + ( + 0ms + ) + + + + + + + First request byte + : + + + 1999-12-31 23:00:00.000 - Client conn. SSL handshake + Request complete : - 1970-01-01 00:00:02.000 + 1999-12-31 23:00:01.000 + + ( + 1s + ) + @@ -352,7 +428,14 @@ exports[`Details Component should render correctly when server address is missin : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:02.000 + + ( + 2s + ) + @@ -361,7 +444,14 @@ exports[`Details Component should render correctly when server address is missin : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:03.000 + + ( + 3s + ) + @@ -400,24 +490,20 @@ exports[`Timing Component should render correctly 1`] = ` className="timing-table" > - - Server conn. initiated : - 1970-01-01 00:00:01.000 - - - - - Client conn. established - : - - - 1970-01-01 00:00:01.000 + 1999-12-31 23:00:02.000 + + ( + 2s + ) + @@ -426,25 +512,57 @@ exports[`Timing Component should render correctly 1`] = ` : - 1970-01-01 00:00:02.000 + 1999-12-31 23:00:03.000 + + ( + 3s + ) + + + + + + + Client conn. established + : + + + 1999-12-31 23:00:00.000 + + ( + 0ms + ) + + + + + + + First request byte + : + + + 1999-12-31 23:00:00.000 - Client conn. SSL handshake + Request complete : - 1970-01-01 00:00:02.000 - - - - - Server conn. SSL handshake - : - - - 1970-01-01 00:00:03.000 + 1999-12-31 23:00:01.000 + + ( + 1s + ) + @@ -453,7 +571,14 @@ exports[`Timing Component should render correctly 1`] = ` : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:02.000 + + ( + 2s + ) + @@ -462,7 +587,14 @@ exports[`Timing Component should render correctly 1`] = ` : - 2017-05-21 12:38:32.481 + 1999-12-31 23:00:03.000 + + ( + 3s + ) + diff --git a/web/src/js/__tests__/components/FlowView/__snapshots__/MessagesSpec.js.snap b/web/src/js/__tests__/components/FlowView/__snapshots__/MessagesSpec.js.snap index 387f868ab..b03d7f2bf 100644 --- a/web/src/js/__tests__/components/FlowView/__snapshots__/MessagesSpec.js.snap +++ b/web/src/js/__tests__/components/FlowView/__snapshots__/MessagesSpec.js.snap @@ -10,7 +10,7 @@ exports[`Error Component should render correctly 1`] = ` error
- 2017-05-21 12:38:32.481 + 1999-12-31 23:00:07.000
@@ -253,55 +253,6 @@ exports[`Request Component should render correctly 1`] = ` /> - - -
- - : - - - -
- - @@ -621,55 +572,6 @@ exports[`Response Component should render correctly 1`] = ` /> - - -
- - : - - - -
- - diff --git a/web/src/js/__tests__/ducks/_tflow.js b/web/src/js/__tests__/ducks/_tflow.js index cd5cf1460..27b294a8c 100644 --- a/web/src/js/__tests__/ducks/_tflow.js +++ b/web/src/js/__tests__/ducks/_tflow.js @@ -1,3 +1,4 @@ +/** Auto-generated by test_app.py:TestApp._test_generate_tflow_js */ export default function(){ return { "client_conn": { @@ -7,21 +8,21 @@ export default function(){ ], "alpn_proto_negotiated": "http/1.1", "cipher_name": "cipher", - "clientcert": null, "id": "4a18d1a0-50a1-48dd-9aa6-d45d74282939", "sni": "address", - "ssl_established": false, - "timestamp_end": 3.0, - "timestamp_ssl_setup": 2.0, - "timestamp_start": 1.0, + "timestamp_end": 946681206, + "timestamp_start": 946681200, + "timestamp_tls_setup": 946681201, + "tls_established": true, "tls_version": "TLSv1.2" }, "error": { "msg": "error", - "timestamp": 1495370312.4814785 + "timestamp": 946681207.0 }, "id": "d91165be-ca1f-4612-88a9-c0f8696f3e29", "intercepted": false, + "is_replay": null, "marked": false, "modified": false, "request": { @@ -45,16 +46,12 @@ export default function(){ "port": 22, "pretty_host": "address", "scheme": "http", - "timestamp_end": null, - "timestamp_start": null, + "timestamp_end": 946681201, + "timestamp_start": 946681200, "trailers": [ [ "trailer", "qvalue" - ], - [ - "content-length", - "7" ] ] }, @@ -75,16 +72,12 @@ export default function(){ "is_replay": false, "reason": "OK", "status_code": 200, - "timestamp_end": 1495370312.4814625, - "timestamp_start": 1495370312.481462, + "timestamp_end": 946681203, + "timestamp_start": 946681202, "trailers": [ [ "trailer", "qvalue" - ], - [ - "content-length", - "7" ] ] }, @@ -93,7 +86,7 @@ export default function(){ "address", 22 ], - "alpn_proto_negotiated": null, + "alpn_proto_negotiated": "http/1.1", "id": "f087e7b2-6d0a-41a8-a8f0-e1a4761395f8", "ip_address": [ "192.168.0.1", @@ -104,13 +97,12 @@ export default function(){ "address", 22 ], - "ssl_established": false, - "timestamp_end": 4.0, - "timestamp_ssl_setup": 3.0, - "timestamp_start": 1.0, - "timestamp_tcp_setup": 2.0, - "tls_version": "TLSv1.2", - "via": null + "timestamp_end": 946681205, + "timestamp_start": 946681202, + "timestamp_tcp_setup": 946681203, + "timestamp_tls_setup": 946681204, + "tls_established": true, + "tls_version": "TLSv1.2" }, "type": "http" }