okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
714ff8242
main
1"""serve/test_security.py - the Host check (DNS rebinding) and the Origin check for requests without an API key, 2against the mock engine (no GPU, no pack). 3 4python -m unittest serve.test_security -v 5""" 6from __future__import annotations 7 8import contextlib 9import errno 10import http .client 11import io 12import json 13import socket 14import sys 15import unittest 16from http .server import BaseHTTPRequestHandler 17from pathlib import Path 18from unittest import mock 19 20sys .path .insert (0 ,str (Path (__file__ ).resolve ().parents [1 ])) 21from serve .frontend import ChatTemplate # noqa: E402 22from serve .server import (ByteTokenizer ,MockEngine ,Server ,Service ,allowed_hosts_of ,host_allowed ,# noqa: E402 23host_name ,host_names_for ,origin_allowed ,serve ) 24 25ROOT = Path (__file__ ).resolve ().parents [1 ] 26LOCAL = {"localhost" ,"127.0.0.1" ,"::1" } 27 28 29class HostNames (unittest .TestCase ): 30def test_host_name (self ): 31self .assertEqual (host_name ("Example.COM:8080" ),"example.com" ) 32self .assertEqual (host_name ("localhost" ),"localhost" ) 33self .assertEqual (host_name ("[::1]:8095" ),"::1" ) 34self .assertEqual (host_name ("[::1]" ),"::1" ) 35self .assertEqual (host_name ("strata.example.com." ),"strata.example.com" ) 36for bad in ("" ,"a:b" ,"[::1" ,"[::1]x" ,"a b" ,"evil.com/x" ): 37self .assertEqual (host_name (bad ),"" ,bad ) 38 39def test_allowed_hosts_of (self ): 40self .assertEqual (allowed_hosts_of (None ), []) 41self .assertEqual (allowed_hosts_of ("Strata.Example.com" ), ["strata.example.com" ]) 42self .assertEqual (allowed_hosts_of (["https://a.example.com:8443/x" ,".example.org" ,"*" ],"box, nas.lan " ), 43 ["a.example.com" ,".example.org" ,"*" ,"box" ,"nas.lan" ]) 44for bad in (["bad name" ],5 , [3 ],"http://" ): 45with self .assertRaises (ValueError ): 46allowed_hosts_of (bad ) 47 48def test_names_from_the_bind_address (self ): 49with mock .patch ("serve.server.lan_addresses" ,return_value = ["192.168.1.20" ]): 50self .assertEqual (host_names_for ("127.0.0.1" ),LOCAL )# this PC only: nothing else 51self .assertEqual (host_names_for ("localhost" ),LOCAL ) 52names = host_names_for ("0.0.0.0" )# other devices too 53self .assertIn (socket .gethostname ().lower (),names ) 54self .assertIn (socket .gethostname ().lower ()+ ".local" ,names ) 55self .assertIn ("192.168.1.20" ,names ) 56self .assertIn ("10.0.0.7" ,host_names_for ("10.0.0.7" )) 57names = host_names_for ("127.0.0.1" , ["strata.example.com" ,"*" ], ["https://chat.example.net" ]) 58self .assertTrue ({"strata.example.com" ,"chat.example.net" }<= names ) 59self .assertNotIn ("*" ,names ) 60 61 62class ListenAddress (unittest .TestCase ): 63def test_bind_does_not_look_up_a_host_name (self ): 64"""http.server's own server_bind asks socket.getfqdn for the address: on a Mac whose reverse lookup stalls (GitHub's macOS runner: 6535 s for the first lookup of every new process) a start listened that much later. No network answer may delay a start.""" 66with mock .patch .object (socket ,"getfqdn" ,side_effect = AssertionError ("server_bind looked up a host name" )), \ 67mock .patch .object (socket ,"gethostbyaddr" ,side_effect = AssertionError ("server_bind looked up a host name" )): 68with Server (("127.0.0.1" ,0 ),BaseHTTPRequestHandler )as s : 69self .assertNotEqual (s .server_address [1 ],0 ) 70 71def test_bind_sets_server_name_to_the_address_and_server_port (self ): 72# (http.server set server_name to the looked-up name, "localhost" for 127.0.0.1; no Strata code reads it) 73with Server (("127.0.0.1" ,0 ),BaseHTTPRequestHandler )as s : 74self .assertEqual ((s .server_name ,s .server_port ), ("127.0.0.1" ,s .server_address [1 ])) 75self .assertGreater (s .server_port ,0 ) 76 77def test_ipv4_address_family (self ): 78with Server (("127.0.0.1" ,0 ),BaseHTTPRequestHandler ,bind_and_activate = False )as s : 79self .assertEqual (s .address_family ,socket .AF_INET ) 80 81@ unittest . skipUnless ( socket . has_ipv6 , "IPv6 is not available" ) 82def test_ipv6_loopback (self ): 83for host in ("::1" ,"2001:db8::7" ): 84try : 85with Server ((host ,0 ),BaseHTTPRequestHandler ,bind_and_activate = False )as s : 86self .assertEqual (s .address_family ,socket .AF_INET6 ) 87except OSError as e : 88self .skipTest (f"IPv6 socket is not available: { e } " ) 89tok = ByteTokenizer () 90svc = Service (MockEngine (tok ,"</think>\n\nok" ,max_context = 4096 ),tok , 91ChatTemplate (ROOT / "serve/chat_template.jinja" )) 92try : 93httpd = serve (svc ,host = "::" ,port = 0 ) 94except OSError as e : 95self .skipTest (f"IPv6 loopback is not available: { e } " ) 96try : 97self .assertEqual (httpd .address_family ,socket .AF_INET6 ) 98c = http .client .HTTPConnection ("::1" ,httpd .server_address [1 ],timeout = 10 ) 99try : 100try : 101c .connect () 102except OSError as e : 103# a box whose loopback has no ::1 (IPv6 off for lo: Boston) can listen on :: but not reach ::1 104if e .errno in (errno .EADDRNOTAVAIL ,errno .ENETUNREACH ,errno .EAFNOSUPPORT ): 105self .skipTest (f"no IPv6 loopback address (::1) on this computer: { e } " ) 106raise 107c .request ("GET" ,"/health" ) 108r = c .getresponse () 109self .assertEqual (r .status ,200 ) 110r .read () 111finally : 112c .close () 113finally : 114httpd .shutdown () 115httpd .server_close () 116 117 118class HostCheck (unittest .TestCase ): 119def test_accepted (self ): 120for host in ("localhost:8095" ,"LOCALHOST" ,"127.0.0.1:1" ,"[::1]:8095" ,"192.168.1.20:8095" ,"[fe80::1]" , 121"app.localhost:8095" ,None ,"" ,"box:8095" ,"a.example.org" ,"example.org:443" ): 122self .assertTrue (host_allowed (host ,LOCAL | {"box" ,".example.org" }),host ) 123 124def test_refused (self ): 125# a rebinding page sends its own name; lookalikes of allowed names stay out 126for host in ("evil.example.com" ,"evil.example.com:8095" ,"localhost.evil.com" ,"127.0.0.1.nip.io" , 127"box.evil.com" ,"xexample.org" ,"bad host" ,"a:b:c:d:e:f:g:h:i" ): 128self .assertFalse (host_allowed (host ,LOCAL | {"box" ,".example.org" }),host ) 129 130def test_any_host (self ): 131self .assertTrue (host_allowed ("evil.example.com" ,LOCAL ,any_host = True )) 132 133 134class OriginCheck (unittest .TestCase ): 135def test_accepted (self ): 136names = LOCAL | {"box" } 137self .assertTrue (origin_allowed ("http://127.0.0.1:8095" ,"127.0.0.1:8095" ,names ))# Strata's own page 138self .assertTrue (origin_allowed ("http://192.168.1.20:8095" ,"192.168.1.20:8095" ,names ))# ... by LAN IP 139self .assertTrue (origin_allowed ("http://localhost:3000" ,"127.0.0.1:8095" ,names ))# a local app 140self .assertTrue (origin_allowed ("http://[::1]:3000/" ,"127.0.0.1:8095" ,names )) 141self .assertTrue (origin_allowed ("https://box" ,"127.0.0.1:8095" ,names )) 142self .assertTrue (origin_allowed ("https://chat.example.com" ,"x" ,names , ["https://chat.example.com" ])) 143self .assertTrue (origin_allowed ("https://any.example.com" ,"x" ,names , ["*" ]))# cors_origins ["*"] 144# browser extensions and desktop apps: no web site can send another scheme than http(s) (or "null") 145for origin in ("chrome-extension://abcdef" ,"moz-extension://1234-5678" ,"app://." ): 146self .assertTrue (origin_allowed (origin ,"127.0.0.1:8095" ,names ),origin ) 147 148def test_refused (self ): 149names = LOCAL | {"box" } 150for origin in ("http://evil.example.com" ,"http://1.2.3.4" ,"http://192.168.1.99:8095" ,"null" ,"" , 151"http://localhost.evil.com" ,"https://box.evil.com" ,"://x" ): 152self .assertFalse (origin_allowed (origin ,"127.0.0.1:8095" ,names , ["https://chat.example.com" ]),origin ) 153 154 155class OverHttp (unittest .TestCase ): 156"""The checks in the running server, as a browser and as curl/the SDKs send their requests.""" 157 158def setUp (self ): 159tok = ByteTokenizer () 160self .svc = Service (MockEngine (tok ,"</think>\n\nok" ,max_context = 4096 ),tok , 161ChatTemplate (ROOT / "serve/chat_template.jinja" )) 162self .httpd = None 163 164def start (self ,** attrs ): 165for k ,v in attrs .items (): 166setattr (self .svc ,k ,v ) 167self .httpd = serve (self .svc ,port = 0 ) 168self .port = self .httpd .server_address [1 ] 169 170def tearDown (self ): 171if self .httpd : 172self .httpd .shutdown () 173self .httpd .server_close () 174 175def req (self ,method ,path ,body = None ,headers = None ,host = None ): 176"""(status, JSON, what the server printed); `host` replaces the Host header http.client sends.""" 177c = http .client .HTTPConnection ("127.0.0.1" ,self .port ,timeout = 30 ) 178h = dict (headers or {}) 179if host is not None : 180h ["Host" ]= host 181data = body if isinstance (body , (bytes ,type (None )))else json .dumps (body ).encode () 182out = io .StringIO () 183try : 184with contextlib .redirect_stdout (out ): 185c .request (method ,path ,body = data ,headers = h ) 186r = c .getresponse () 187raw = r .read () 188return r .status ,json .loads (raw )if raw [:1 ]in (b"{" ,b"[" )else raw ,out .getvalue () 189finally : 190c .close () 191 192def chat_body (self ): 193return {"model" :"m" ,"messages" : [{"role" :"user" ,"content" :"hi" }],"max_tokens" :64 } 194 195# --- Host 196def test_rebinding_name_is_refused_everywhere (self ): 197self .start () 198for method ,path in (("GET" ,"/status" ), ("GET" ,"/metrics" ), ("GET" ,"/" ), ("GET" ,"/health" ), 199 ("POST" ,"/settings" ), ("POST" ,"/v1/chat/completions" ), ("OPTIONS" ,"/v1/models" )): 200code ,body ,log = self .req (method ,path , {}if method == "POST" else None , 201 {"Content-Type" :"application/json" },host = f"evil.example.com: { self . port } " ) 202self .assertEqual (code ,403 ,path ) 203if method != "OPTIONS" : 204self .assertIn ("allowed_hosts" ,body ["error" ]["message" ]) 205self .assertEqual (log .count ("\n" ),1 ,path )# one log line each 206self .assertIn ("evil.example.com" ,log ) 207 208def test_local_names_and_ips_pass (self ): 209self .start () 210for host in (f"127.0.0.1: { self . port } " ,f"localhost: { self . port } " ,f"[::1]: { self . port } " , 211f"192.168.1.20: { self . port } " ): 212self .assertEqual (self .req ("GET" ,"/status" ,host = host )[0 ],200 ,host ) 213 214def test_no_host_header_passes (self ): 215self .start () 216with socket .create_connection (("127.0.0.1" ,self .port ),timeout = 10 )as s :# an HTTP/1.0 client 217s .sendall (b"GET /health HTTP/1.0\r\n\r\n" ) 218raw = b"" 219while chunk := s .recv (65536 ): 220raw += chunk 221self .assertTrue (raw .startswith (b"HTTP/1.0 200" ),raw [:40 ]) 222 223def test_allowed_hosts_and_wildcard (self ): 224self .start (allowed_hosts = ["strata.example.com" ,".home.arpa" ]) 225self .assertEqual (self .req ("GET" ,"/status" ,host = "strata.example.com" )[0 ],200 ) 226self .assertEqual (self .req ("GET" ,"/status" ,host = "nas.home.arpa:8095" )[0 ],200 ) 227self .assertEqual (self .req ("GET" ,"/status" ,host = "evil.example.com" )[0 ],403 ) 228self .svc .allowed_hosts = ["*" ] 229self .assertEqual (self .req ("GET" ,"/status" ,host = "evil.example.com" )[0 ],200 ) 230 231def test_refusal_names_both_ways_out (self ): 232self .start () 233message = self .req ("GET" ,"/status" ,host = "evil.example.com" )[1 ]["error" ]["message" ] 234self .assertIn ("allowed_hosts" ,message ) 235self .assertIn ("api_key" ,message ) 236 237def test_with_a_key_the_host_check_is_off (self ): 238# a rebinding page cannot authenticate; tunnels and proxies that pass their own name on keep working 239self .start (api_key = "s3cret" ) 240tunnel = "random-words.trycloudflare.com" 241self .assertEqual (self .req ("GET" ,"/status" ,host = tunnel )[0 ],401 ) 242self .assertEqual (self .req ("GET" ,"/status" ,headers = {"Authorization" :"Bearer s3cret" },host = tunnel )[0 ],200 ) 243self .assertEqual (self .req ("GET" ,"/health" ,host = tunnel )[0 ],200 ) 244code ,_ ,log = self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 245 {"Content-Type" :"application/json" ,"Authorization" :"Bearer s3cret" },host = tunnel ) 246self .assertEqual (code ,200 ) 247self .assertNotIn ("refused" ,log ) 248 249def test_a_trusted_origin_s_host_is_allowed (self ): 250self .start (trusted_origins = ["https://strata.example.com" ]) 251self .assertEqual (self .req ("GET" ,"/status" ,host = "strata.example.com" )[0 ],200 ) 252 253# --- Origin on /v1 without an API key 254def test_curl_and_sdks_without_origin (self ): 255self .start () 256for ctype in ("application/json" ,"text/plain" ,None ):# curl -d sends a form type 257code ,body ,_ = self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 258 {"Content-Type" :ctype }if ctype else {}) 259self .assertEqual (code ,200 ,ctype ) 260self .assertEqual (body ["choices" ][0 ]["message" ]["content" ],"ok" ) 261 262def test_cross_site_page_is_refused (self ): 263self .start () 264for path in ("/v1/chat/completions" ,"/v1/messages" ,"/v1/messages/count_tokens" ): 265for ctype in ("text/plain" ,"application/json" ): 266code ,body ,log = self .req ("POST" ,path ,self .chat_body (), 267 {"Content-Type" :ctype ,"Origin" :"http://evil.example.com" }) 268self .assertEqual (code ,403 , (path ,ctype )) 269self .assertIn ("api_key" ,body ["error" ]["message" ]) 270self .assertIn ("evil.example.com" ,log ) 271self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 272 {"Content-Type" :"text/plain" ,"Origin" :"null" })[0 ],403 ) 273 274def test_own_and_local_pages_pass (self ): 275self .start () 276json_type = {"Content-Type" :"application/json" } 277for origin in (f"http://127.0.0.1: { self . port } " ,"http://localhost:3000" ,"chrome-extension://abcdef" ): 278self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 279 {** json_type ,"Origin" :origin })[0 ],200 ,origin ) 280# a browser page sends JSON; text/plain from a page is the cross-site "simple request" shape 281self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 282 {"Content-Type" :"text/plain" ,"Origin" :f"http://127.0.0.1: { self . port } " })[0 ],415 ) 283 284def test_configured_origins_pass (self ): 285self .start (cors_origins = ["https://chat.example.com" ],trusted_origins = ["https://strata.example.com" ], 286allowed_hosts = ["webui.lan" ]) 287for origin in ("https://chat.example.com" ,"https://strata.example.com" ,"http://webui.lan:3000" ): 288self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 289 {"Content-Type" :"application/json" ,"Origin" :origin })[0 ],200 ,origin ) 290 291def test_with_a_key_the_key_decides (self ): 292self .start (api_key = "s3cret" ) 293headers = {"Content-Type" :"text/plain" ,"Origin" :"http://evil.example.com" } 294self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (),headers )[0 ],401 ) 295self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 296 {** headers ,"Authorization" :"Bearer s3cret" })[0 ],200 ) 297 298def test_terminal_telemetry_requires_the_existing_key (self ): 299self .start (api_key = "s3cret" ) 300self .assertEqual (self .req ("GET" ,"/v1/telemetry" )[0 ],401 ) 301code ,body ,_ = self .req ("GET" ,"/v1/telemetry" ,headers = {"Authorization" :"Bearer s3cret" }) 302self .assertEqual (code ,200 ) 303self .assertEqual (body ["schema_version" ],1 ) 304self .assertNotIn ("input" ,json .dumps (body )) 305 306def test_read_only_telemetry_key_does_not_authorize_inference_or_management (self ): 307self .start (api_key = "inference-secret" ,telemetry_key = "read-secret" ) 308header = {"Authorization" :"Bearer read-secret" } 309self .assertEqual (self .req ("GET" ,"/v1/telemetry" ,headers = header )[0 ],200 ) 310self .assertEqual (self .req ("GET" ,"/metrics" ,headers = header )[0 ],401 ) 311self .assertEqual (self .req ("GET" ,"/v1/models" ,headers = header )[0 ],401 ) 312self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,self .chat_body (), 313 {** header ,"Content-Type" :"application/json" })[0 ],401 ) 314self .assertEqual (self .req ("POST" ,"/unload" , {}, 315 {** header ,"Content-Type" :"application/json" })[0 ],401 ) 316 317def test_read_only_key_gets_bounded_redacted_request_activity (self ): 318self .start (api_key = "inference-secret" ,telemetry_key = "read-secret" ) 319prompt = "DO_NOT_LEAK_PROMPT_ACTIVITY" 320request = {** self .chat_body (),"messages" : [{"role" :"user" ,"content" :prompt }]} 321self .assertEqual (self .req ("POST" ,"/v1/chat/completions" ,request , 322 {"Authorization" :"Bearer inference-secret" , 323"Content-Type" :"application/json" })[0 ],200 ) 324code ,body ,_ = self .req ("GET" ,"/v1/telemetry" , 325headers = {"Authorization" :"Bearer read-secret" }) 326self .assertEqual (code ,200 ) 327activity = body ["activity" ] 328self .assertEqual (activity ["last_seq" ],len (activity ["events" ])) 329self .assertLessEqual (len (activity ["events" ]),32 ) 330self .assertEqual (activity ["events" ][0 ]["event" ],"queued" ) 331self .assertEqual (activity ["events" ][- 1 ]["event" ],"finished" ) 332self .assertEqual ([e ["seq" ]for e in activity ["events" ]], 333list (range (1 ,activity ["last_seq" ]+ 1 ))) 334self .assertEqual (len ({e ["request_id" ]for e in activity ["events" ]}),1 ) 335serialized = json .dumps (activity ) 336for secret in (prompt ,"inference-secret" ,"read-secret" ,"</think>" ): 337self .assertNotIn (secret ,serialized ) 338with self .svc .status_lock : 339for i in range (140 ): 340self .svc ._terminal_event_locked (f" { i :012x } " ,"queued" ) 341bounded = self .req ("GET" ,"/v1/telemetry" , 342headers = {"Authorization" :"Bearer read-secret" })[1 ]["activity" ] 343self .assertEqual (len (self .svc .terminal_events ),128 ) 344self .assertEqual (len (bounded ["events" ]),32 ) 345self .assertEqual (bounded ["events" ][- 1 ]["seq" ],bounded ["last_seq" ]) 346 347# --- /unload and /load 348def test_control_body_arrives_before_the_operation_and_reply (self ): 349self .start () 350for body ,expected in ((b"{}" ,200 ), (b"{" ,400 )): 351c = http .client .HTTPConnection ("127.0.0.1" ,self .port ,timeout = 5 ) 352try : 353with mock .patch .object (self .svc ,"unload" ,return_value = "unloaded" )as unload : 354c .putrequest ("POST" ,"/unload" ) 355c .putheader ("Content-Type" ,"application/json" ) 356c .putheader ("Content-Length" ,"2" ) 357c .endheaders () 358c .sock .settimeout (0.1 ) 359with self .assertRaises (socket .timeout ): 360c .sock .recv (1 ) 361unload .assert_not_called () 362c .sock .settimeout (5 ) 363c .send (body ) 364if len (body )< 2 : 365c .sock .shutdown (socket .SHUT_WR ) 366r = c .getresponse () 367self .assertEqual (r .status ,expected ) 368r .read () 369self .assertEqual (unload .call_count ,int (expected == 200 )) 370finally : 371c .close () 372 373def test_unload_and_load_need_json_from_the_own_page (self ): 374self .start () 375form = {"Content-Type" :"application/x-www-form-urlencoded" } 376for path in ("/unload" ,"/load" ): 377self .assertEqual (self .req ("POST" ,path ,b"a=1" ,form )[0 ],415 ,path ) 378self .assertEqual (self .req ("POST" ,path ,b"" , {})[0 ],415 ,path ) 379self .assertEqual (self .req ("POST" ,path , {}, {"Content-Type" :"application/json" , 380"Origin" :"http://evil.example.com" })[0 ],403 ,path ) 381self .assertEqual (self .req ("POST" ,"/unload" , {}, {"Content-Type" :"application/json" })[0 ],200 ) 382self .assertEqual (self .req ("POST" ,"/load" , {}, {"Content-Type" :"application/json" , 383"Origin" :f"http://127.0.0.1: { self . port } " })[0 ],200 ) 384 385# --- /slots/0?action=save|restore (session files) 386def test_slots_need_json_from_the_own_page (self ): 387self .start () 388body = {"filename" :"a.bin" } 389for action in ("save" ,"restore" ): 390path = f"/slots/0?action= { action } " 391self .assertEqual (self .req ("POST" ,path ,b"filename=a.bin" , 392 {"Content-Type" :"application/x-www-form-urlencoded" })[0 ],415 ,path ) 393self .assertEqual (self .req ("POST" ,path ,body , {"Content-Type" :"text/plain" })[0 ],415 ,path ) 394for origin in ("http://evil.example.com" ,"null" ): 395self .assertEqual (self .req ("POST" ,path ,body , {"Content-Type" :"application/json" , 396"Origin" :origin })[0 ],403 , (path ,origin )) 397# JSON without an Origin (curl, scripts) or from the own page reaches the slot API: off here, so 501 398self .assertEqual (self .req ("POST" ,path ,body , {"Content-Type" :"application/json" })[0 ],501 ,path ) 399self .assertEqual (self .req ("POST" ,path ,body , {"Content-Type" :"application/json" , 400"Origin" :f"http://127.0.0.1: { self . port } " })[0 ],501 ,path ) 401self .assertEqual (self .req ("POST" ,"/slots/0?action=save" ,body , {"Content-Type" :"application/json" }, 402host = "rebind.example.com" )[0 ],403 ) 403 404 405class NoApiKey (unittest .TestCase ): 406"""A key is recommended on a network, never required (owner decision 2026-10-20).""" 407 408def test_none_means_no_key_on_purpose (self ): 409from serve .server import explicit_no_key 410for v in ("none" ," None " ,"NONE" ): 411self .assertTrue (explicit_no_key (v )) 412for v in ("" ,None ,"sk-none" , ["none" ],"none,x" ): 413self .assertFalse (explicit_no_key (v )) 414 415def test_the_warning_is_plain (self ): 416from serve .server import open_server_warning 417w = open_server_warning (8080 ) 418self .assertIn ("anyone who can reach port 8080 can use the model" ,w ) 419self .assertNotIn ("tools" ,w ) 420self .assertIn ("and its tools" ,open_server_warning (8080 ,tools = True )) 421self .assertIn ("public internet" ,open_server_warning (8080 ,public = True )) 422 423 424if __name__ == "__main__" : 425unittest .main ()