A Python port of the Invisible Internet Project (I2P)
1"""Tests for LocalHTTPServer — TDD: tests before implementation."""
2
3import pytest
4
5from i2p_apps.i2ptunnel.local_http_server import LocalHTTPHandler
6
7
8class TestLocalHTTPHandler:
9 def test_creation(self):
10 h = LocalHTTPHandler()
11 assert h is not None
12
13 def test_health_page(self):
14 h = LocalHTTPHandler()
15 status, body = h.handle_get("/")
16 assert status == 200
17 assert "i2p" in body.lower() or "proxy" in body.lower()
18
19 def test_add_form_get(self):
20 h = LocalHTTPHandler()
21 status, body = h.handle_get("/add?host=example.i2p&dest=AAAA")
22 assert status == 200
23 assert "example.i2p" in body
24 assert "form" in body.lower()
25
26 def test_unknown_path(self):
27 h = LocalHTTPHandler()
28 status, body = h.handle_get("/nonexistent")
29 assert status == 404
30
31 def test_nonce_generation(self):
32 h = LocalHTTPHandler()
33 n1 = h._generate_nonce()
34 n2 = h._generate_nonce()
35 assert n1 != n2
36 assert len(n1) >= 16