1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildPythonPackage,
6 pythonOlder,
7 # Mitmproxy requirements
8 aioquic,
9 asgiref,
10 blinker,
11 brotli,
12 certifi,
13 cryptography,
14 flask,
15 h11,
16 h2,
17 hyperframe,
18 kaitaistruct,
19 ldap3,
20 mitmproxy-macos,
21 mitmproxy-rs,
22 msgpack,
23 passlib,
24 protobuf5,
25 publicsuffix2,
26 pyopenssl,
27 pyparsing,
28 pyperclip,
29 ruamel-yaml,
30 setuptools,
31 sortedcontainers,
32 tornado,
33 urwid,
34 wsproto,
35 zstandard,
36 # Additional check requirements
37 hypothesis,
38 parver,
39 pytest-asyncio,
40 pytest-timeout,
41 pytest-xdist,
42 pytestCheckHook,
43 requests,
44}:
45
46buildPythonPackage rec {
47 pname = "mitmproxy";
48 version = "11.0.2";
49 pyproject = true;
50
51 disabled = pythonOlder "3.9";
52
53 src = fetchFromGitHub {
54 owner = "mitmproxy";
55 repo = "mitmproxy";
56 tag = "v${version}";
57 hash = "sha256-qcsPOISQjHVHh4TrQ/UihZaxB/jWBfq7AVI4U1gQPVs=";
58 };
59
60 pythonRelaxDeps = [
61 "passlib"
62 "protobuf"
63 "urwid"
64 ];
65
66 propagatedBuildInputs = [
67 aioquic
68 asgiref
69 blinker
70 brotli
71 certifi
72 cryptography
73 flask
74 h11
75 h2
76 hyperframe
77 kaitaistruct
78 ldap3
79 mitmproxy-rs
80 msgpack
81 passlib
82 protobuf5
83 publicsuffix2
84 pyopenssl
85 pyparsing
86 pyperclip
87 ruamel-yaml
88 setuptools
89 sortedcontainers
90 tornado
91 urwid
92 wsproto
93 zstandard
94 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ mitmproxy-macos ];
95
96 nativeCheckInputs = [
97 hypothesis
98 parver
99 pytest-asyncio
100 pytest-timeout
101 pytest-xdist
102 pytestCheckHook
103 requests
104 ];
105
106 __darwinAllowLocalNetworking = true;
107
108 preCheck = ''
109 export HOME=$(mktemp -d)
110 '';
111
112 disabledTests = [
113 # Tests require a git repository
114 "test_get_version"
115 # https://github.com/mitmproxy/mitmproxy/commit/36ebf11916704b3cdaf4be840eaafa66a115ac03
116 # Tests require terminal
117 "test_commands_exist"
118 "test_contentview_flowview"
119 "test_flowview"
120 "test_get_hex_editor"
121 "test_integration"
122 "test_spawn_editor"
123 "test_statusbar"
124 # FileNotFoundError: [Errno 2] No such file or directory
125 # likely wireguard is also not working in the sandbox
126 "test_tun_mode"
127 "test_wireguard"
128 # test require a DNS server
129 # RuntimeError: failed to get dns servers: io error: entity not found
130 "test_errorcheck"
131 "test_errorcheck"
132 "test_dns"
133 "test_order"
134 ];
135
136 disabledTestPaths = [
137 # test require a DNS server
138 # RuntimeError: failed to get dns servers: io error: entity not found
139 "test/mitmproxy/addons/test_dns_resolver.py"
140 "test/mitmproxy/tools/test_dump.py"
141 "test/mitmproxy/tools/test_main.py"
142 "test/mitmproxy/tools/web/test_app.py"
143 "test/mitmproxy/tools/web/test_app.py" # 2 out of 31 tests work
144 "test/mitmproxy/tools/web/test_master.py"
145 ];
146
147 dontUsePytestXdist = true;
148
149 pythonImportsCheck = [ "mitmproxy" ];
150
151 meta = with lib; {
152 description = "Man-in-the-middle proxy";
153 homepage = "https://mitmproxy.org/";
154 changelog = "https://github.com/mitmproxy/mitmproxy/blob/${version}/CHANGELOG.md";
155 license = licenses.mit;
156 maintainers = with maintainers; [ SuperSandro2000 ];
157 };
158}