coverage++

This commit is contained in:
Maximilian Hils 2021-03-30 12:12:38 +02:00
parent 68c55979fb
commit eefc55f28f
9 changed files with 244 additions and 197 deletions

View File

@ -184,9 +184,6 @@ def tserver_conn() -> connection.Server:
return c return c
def terr(content="error"): def terr(content: str = "error") -> flow.Error:
""" err = flow.Error(content, 946681207)
@return: mitmproxy.proxy.protocol.primitives.Error
"""
err = flow.Error(content)
return err return err

View File

@ -1,9 +1,9 @@
import asyncio
import json as _json import json as _json
import logging import logging
from unittest import mock
import os import os
import asyncio
import sys import sys
from unittest import mock
import pytest 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. # Set some value as constant, so that _tflow.js would not change every time.
_tflow['client_conn']['id'] = "4a18d1a0-50a1-48dd-9aa6-d45d74282939" _tflow['client_conn']['id'] = "4a18d1a0-50a1-48dd-9aa6-d45d74282939"
_tflow['id'] = "d91165be-ca1f-4612-88a9-c0f8696f3e29" _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['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) tflow_json = _json.dumps(_tflow, indent=4, sort_keys=True)
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
web_root = os.path.join(here, os.pardir, os.pardir, os.pardir, os.pardir, 'web') 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') 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: with open(tflow_path, 'w', newline="\n") as f:
f.write(content) f.write(content)

View File

@ -7,6 +7,10 @@ and activate your virtualenv environment before proceeding.**
- Run `yarn run gulp` to start live-compilation. - Run `yarn run gulp` to start live-compilation.
- Run `mitmweb` and open http://localhost:8081/ - Run `mitmweb` and open http://localhost:8081/
## Testing
- Run `yarn run test` to run the testsuite.
## Architecture ## Architecture
There are two components: There are two components:

View File

@ -105,4 +105,12 @@ describe('FlowColumns Components', () => {
tree = timeColumn.toJSON() tree = timeColumn.toJSON()
expect(tree).toMatchSnapshot() expect(tree).toMatchSnapshot()
}) })
it('should render TimeStampColumn', () => {
let timeStampColumn = renderer.create(<Columns.TimeStampColumn flow={tflow}/>),
tree = timeStampColumn.toJSON()
tflow.request.timestamp_start =
expect(tree).toMatchSnapshot()
})
}) })

View File

@ -127,7 +127,7 @@ exports[`FlowColumns Components should render TimeColumn 1`] = `
<td <td
className="col-time" className="col-time"
> >
415381h 3s
</td> </td>
`; `;
@ -139,6 +139,14 @@ exports[`FlowColumns Components should render TimeColumn 2`] = `
</td> </td>
`; `;
exports[`FlowColumns Components should render TimeStampColumn 1`] = `
<td
className="col-start"
>
1999-12-31 23:00:00.000
</td>
`;
exports[`FlowColumns Components should render pathColumn 1`] = ` exports[`FlowColumns Components should render pathColumn 1`] = `
<td <td
className="col-path" className="col-path"

View File

@ -46,7 +46,7 @@ exports[`FlowRow Component should render correctly 1`] = `
<td <td
className="col-time" className="col-time"
> >
415381h 3s
</td> </td>
</tr> </tr>
`; `;

View File

@ -155,6 +155,18 @@ exports[`Details Component should render correctly 1`] = `
TLSv1.2 TLSv1.2
</td> </td>
</tr> </tr>
<tr>
<td>
<abbr
title="ALPN protocol negotiated"
>
ALPN:
</abbr>
</td>
<td>
http/1.1
</td>
</tr>
<tr> <tr>
<td> <td>
Resolved address: Resolved address:
@ -182,24 +194,20 @@ exports[`Details Component should render correctly 1`] = `
className="timing-table" className="timing-table"
> >
<tbody> <tbody>
<tr />
<tr />
<tr> <tr>
<td> <td>
Server conn. initiated Server conn. initiated
: :
</td> </td>
<td> <td>
1970-01-01 00:00:01.000 1999-12-31 23:00:02.000
</td> <span
</tr> className="text-muted"
<tr> >
<td> (
Client conn. established 2s
: )
</td> </span>
<td>
1970-01-01 00:00:01.000
</td> </td>
</tr> </tr>
<tr> <tr>
@ -208,25 +216,57 @@ exports[`Details Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
1970-01-01 00:00:02.000 1999-12-31 23:00:03.000
<span
className="text-muted"
>
(
3s
)
</span>
</td>
</tr>
<tr />
<tr>
<td>
Client conn. established
:
</td>
<td>
1999-12-31 23:00:00.000
<span
className="text-muted"
>
(
0ms
)
</span>
</td>
</tr>
<tr />
<tr>
<td>
First request byte
:
</td>
<td>
1999-12-31 23:00:00.000
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
Client conn. SSL handshake Request complete
: :
</td> </td>
<td> <td>
1970-01-01 00:00:02.000 1999-12-31 23:00:01.000
</td> <span
</tr> className="text-muted"
<tr> >
<td> (
Server conn. SSL handshake 1s
: )
</td> </span>
<td>
1970-01-01 00:00:03.000
</td> </td>
</tr> </tr>
<tr> <tr>
@ -235,7 +275,14 @@ exports[`Details Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:02.000
<span
className="text-muted"
>
(
2s
)
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -244,7 +291,14 @@ exports[`Details Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:03.000
<span
className="text-muted"
>
(
3s
)
</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -323,8 +377,6 @@ exports[`Details Component should render correctly when server address is missin
className="timing-table" className="timing-table"
> >
<tbody> <tbody>
<tr />
<tr />
<tr /> <tr />
<tr /> <tr />
<tr /> <tr />
@ -334,16 +386,40 @@ exports[`Details Component should render correctly when server address is missin
: :
</td> </td>
<td> <td>
1970-01-01 00:00:01.000 1999-12-31 23:00:00.000
<span
className="text-muted"
>
(
0ms
)
</span>
</td>
</tr>
<tr />
<tr>
<td>
First request byte
:
</td>
<td>
1999-12-31 23:00:00.000
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
Client conn. SSL handshake Request complete
: :
</td> </td>
<td> <td>
1970-01-01 00:00:02.000 1999-12-31 23:00:01.000
<span
className="text-muted"
>
(
1s
)
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -352,7 +428,14 @@ exports[`Details Component should render correctly when server address is missin
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:02.000
<span
className="text-muted"
>
(
2s
)
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -361,7 +444,14 @@ exports[`Details Component should render correctly when server address is missin
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:03.000
<span
className="text-muted"
>
(
3s
)
</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -400,24 +490,20 @@ exports[`Timing Component should render correctly 1`] = `
className="timing-table" className="timing-table"
> >
<tbody> <tbody>
<tr />
<tr />
<tr> <tr>
<td> <td>
Server conn. initiated Server conn. initiated
: :
</td> </td>
<td> <td>
1970-01-01 00:00:01.000 1999-12-31 23:00:02.000
</td> <span
</tr> className="text-muted"
<tr> >
<td> (
Client conn. established 2s
: )
</td> </span>
<td>
1970-01-01 00:00:01.000
</td> </td>
</tr> </tr>
<tr> <tr>
@ -426,25 +512,57 @@ exports[`Timing Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
1970-01-01 00:00:02.000 1999-12-31 23:00:03.000
<span
className="text-muted"
>
(
3s
)
</span>
</td>
</tr>
<tr />
<tr>
<td>
Client conn. established
:
</td>
<td>
1999-12-31 23:00:00.000
<span
className="text-muted"
>
(
0ms
)
</span>
</td>
</tr>
<tr />
<tr>
<td>
First request byte
:
</td>
<td>
1999-12-31 23:00:00.000
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
Client conn. SSL handshake Request complete
: :
</td> </td>
<td> <td>
1970-01-01 00:00:02.000 1999-12-31 23:00:01.000
</td> <span
</tr> className="text-muted"
<tr> >
<td> (
Server conn. SSL handshake 1s
: )
</td> </span>
<td>
1970-01-01 00:00:03.000
</td> </td>
</tr> </tr>
<tr> <tr>
@ -453,7 +571,14 @@ exports[`Timing Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:02.000
<span
className="text-muted"
>
(
2s
)
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -462,7 +587,14 @@ exports[`Timing Component should render correctly 1`] = `
: :
</td> </td>
<td> <td>
2017-05-21 12:38:32.481 1999-12-31 23:00:03.000
<span
className="text-muted"
>
(
3s
)
</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -10,7 +10,7 @@ exports[`Error Component should render correctly 1`] = `
error error
<div> <div>
<small> <small>
2017-05-21 12:38:32.481 1999-12-31 23:00:07.000
</small> </small>
</div> </div>
</div> </div>
@ -253,55 +253,6 @@ exports[`Request Component should render correctly 1`] = `
/> />
</td> </td>
</tr> </tr>
<tr>
<td
className="header-name"
>
<div
className="inline-input readonly"
contentEditable={undefined}
dangerouslySetInnerHTML={
Object {
"__html": "content-length",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onInput={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onPaste={[Function]}
tabIndex={undefined}
/>
<span
className="header-colon"
>
:
</span>
</td>
<td
className="header-value"
>
<div
className="inline-input readonly"
contentEditable={undefined}
dangerouslySetInnerHTML={
Object {
"__html": "7",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onInput={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onPaste={[Function]}
tabIndex={undefined}
/>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</article> </article>
@ -621,55 +572,6 @@ exports[`Response Component should render correctly 1`] = `
/> />
</td> </td>
</tr> </tr>
<tr>
<td
className="header-name"
>
<div
className="inline-input readonly"
contentEditable={undefined}
dangerouslySetInnerHTML={
Object {
"__html": "content-length",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onInput={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onPaste={[Function]}
tabIndex={undefined}
/>
<span
className="header-colon"
>
:
</span>
</td>
<td
className="header-value"
>
<div
className="inline-input readonly"
contentEditable={undefined}
dangerouslySetInnerHTML={
Object {
"__html": "7",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onInput={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onPaste={[Function]}
tabIndex={undefined}
/>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</article> </article>

View File

@ -1,3 +1,4 @@
/** Auto-generated by test_app.py:TestApp._test_generate_tflow_js */
export default function(){ export default function(){
return { return {
"client_conn": { "client_conn": {
@ -7,21 +8,21 @@ export default function(){
], ],
"alpn_proto_negotiated": "http/1.1", "alpn_proto_negotiated": "http/1.1",
"cipher_name": "cipher", "cipher_name": "cipher",
"clientcert": null,
"id": "4a18d1a0-50a1-48dd-9aa6-d45d74282939", "id": "4a18d1a0-50a1-48dd-9aa6-d45d74282939",
"sni": "address", "sni": "address",
"ssl_established": false, "timestamp_end": 946681206,
"timestamp_end": 3.0, "timestamp_start": 946681200,
"timestamp_ssl_setup": 2.0, "timestamp_tls_setup": 946681201,
"timestamp_start": 1.0, "tls_established": true,
"tls_version": "TLSv1.2" "tls_version": "TLSv1.2"
}, },
"error": { "error": {
"msg": "error", "msg": "error",
"timestamp": 1495370312.4814785 "timestamp": 946681207.0
}, },
"id": "d91165be-ca1f-4612-88a9-c0f8696f3e29", "id": "d91165be-ca1f-4612-88a9-c0f8696f3e29",
"intercepted": false, "intercepted": false,
"is_replay": null,
"marked": false, "marked": false,
"modified": false, "modified": false,
"request": { "request": {
@ -45,16 +46,12 @@ export default function(){
"port": 22, "port": 22,
"pretty_host": "address", "pretty_host": "address",
"scheme": "http", "scheme": "http",
"timestamp_end": null, "timestamp_end": 946681201,
"timestamp_start": null, "timestamp_start": 946681200,
"trailers": [ "trailers": [
[ [
"trailer", "trailer",
"qvalue" "qvalue"
],
[
"content-length",
"7"
] ]
] ]
}, },
@ -75,16 +72,12 @@ export default function(){
"is_replay": false, "is_replay": false,
"reason": "OK", "reason": "OK",
"status_code": 200, "status_code": 200,
"timestamp_end": 1495370312.4814625, "timestamp_end": 946681203,
"timestamp_start": 1495370312.481462, "timestamp_start": 946681202,
"trailers": [ "trailers": [
[ [
"trailer", "trailer",
"qvalue" "qvalue"
],
[
"content-length",
"7"
] ]
] ]
}, },
@ -93,7 +86,7 @@ export default function(){
"address", "address",
22 22
], ],
"alpn_proto_negotiated": null, "alpn_proto_negotiated": "http/1.1",
"id": "f087e7b2-6d0a-41a8-a8f0-e1a4761395f8", "id": "f087e7b2-6d0a-41a8-a8f0-e1a4761395f8",
"ip_address": [ "ip_address": [
"192.168.0.1", "192.168.0.1",
@ -104,13 +97,12 @@ export default function(){
"address", "address",
22 22
], ],
"ssl_established": false, "timestamp_end": 946681205,
"timestamp_end": 4.0, "timestamp_start": 946681202,
"timestamp_ssl_setup": 3.0, "timestamp_tcp_setup": 946681203,
"timestamp_start": 1.0, "timestamp_tls_setup": 946681204,
"timestamp_tcp_setup": 2.0, "tls_established": true,
"tls_version": "TLSv1.2", "tls_version": "TLSv1.2"
"via": null
}, },
"type": "http" "type": "http"
} }