feat!: complete refactoring of server #1
No files matched your search
+1
-1
@@ -322,7 +322,7 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
|
||||
# A plain nochg is not noteworthy, devices poll every minute.
|
||||
if notes:
|
||||
print(
|
||||
f"{time.strftime('%Y-%m-%d %H:%M:%S')} {ip} {status} {'; '.join(notes)}",
|
||||
f"{time.strftime('[%Y-%m-%d %H:%M:%S]')} {ip}: {status} - {'; '.join(notes)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
self._reply(status, body)
|
||||
|
||||
+9
-5
@@ -435,15 +435,19 @@ token_sha256 = "{hashlib.sha256(TOKEN.encode()).hexdigest()}"
|
||||
server = self.start(client_ip_header="X-Forwarded-For")
|
||||
xff = {"X-Forwarded-For": "1.2.3.4"}
|
||||
_, log = self.logged(server, Authorization=basic(HOST, "bad"), **xff)
|
||||
self.assertRegex(log, rf"1\.2\.3\.4 401 {HOST}: badauth: wrong token")
|
||||
self.assertRegex(
|
||||
log,
|
||||
rf"^\[\d{{4}}-\d\d-\d\d \d\d:\d\d:\d\d\] 1\.2\.3\.4: 401 - {HOST}: badauth: wrong token\n$",
|
||||
)
|
||||
_, log = self.logged(server, Authorization=basic("who.example.com", "x"), **xff)
|
||||
self.assertIn("401 badauth: unknown host 'who.example.com'", log)
|
||||
self.assertIn("1.2.3.4: 401 - badauth: unknown host 'who.example.com'", log)
|
||||
_, log = self.logged(server, "/nic/update?hostname=other.example.com", **xff)
|
||||
self.assertIn(
|
||||
"404 home.example.com: nohost: hostname parameter 'other.example.com'", log
|
||||
"1.2.3.4: 404 - home.example.com: nohost: hostname parameter 'other.example.com'",
|
||||
log,
|
||||
)
|
||||
_, log = self.logged(server, **xff)
|
||||
self.assertIn("200 home.example.com: good A unknown -> 1.2.3.4", log)
|
||||
self.assertIn("1.2.3.4: 200 - home.example.com: good A unknown -> 1.2.3.4", log)
|
||||
|
||||
def test_nochg_is_not_logged(self):
|
||||
server = self.start(client_ip_header="X-Forwarded-For")
|
||||
@@ -458,7 +462,7 @@ token_sha256 = "{hashlib.sha256(TOKEN.encode()).hexdigest()}"
|
||||
self.inwx.wrong_login = True
|
||||
_, log = self.logged(server, **{"X-Forwarded-For": "1.2.3.4"})
|
||||
self.assertIn(
|
||||
"502 home.example.com: 911: A update to 1.2.3.4 failed: account.login: 2200",
|
||||
"1.2.3.4: 502 - home.example.com: 911: A update to 1.2.3.4 failed: account.login: 2200",
|
||||
log,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user