Add CAD fit checks and revision previews
This commit is contained in:
1 parent
b4ef20db39
commit
78d33d01a6
18 files changed
+250
-23
No files matched your search
+24
-1
@@ -1,3 +1,4 @@
|
||||
from base64 import b64decode
|
||||
import json
|
||||
from pathlib import Path
|
||||
from socket import socket
|
||||
@@ -134,7 +135,20 @@ class DashboardTest(unittest.TestCase):
|
||||
|
||||
def test_http_routes_do_not_serve_files_or_accept_foreign_hosts(self):
|
||||
self.changes.mkdir()
|
||||
(self.changes / "CF-001.md").write_text("# CF-001\n", encoding="utf-8")
|
||||
(self.changes / "CF-001.md").write_text(
|
||||
"# CF-001\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
png = b64decode(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jP4kAAAAASUVORK5CYII="
|
||||
)
|
||||
(self.changes / "CF-001.r2-overview.png").write_bytes(png)
|
||||
(self.changes / "CF-001.r2-detail.png").write_bytes(b"not a PNG")
|
||||
(self.changes / "CF-001.r1-overview.png").write_bytes(png)
|
||||
with ThreadingHTTPServer(("127.0.0.1", 0), Handler) as server:
|
||||
server.root = self.root
|
||||
server.activity = False
|
||||
@@ -146,10 +160,19 @@ class DashboardTest(unittest.TestCase):
|
||||
with urlopen(url + "/api/cards", timeout=2) as response:
|
||||
card, = json.load(response)["cards"]
|
||||
self.assertEqual(card["id"], "CF-001")
|
||||
self.assertEqual([row["file"] for row in card["previews"]],
|
||||
["CF-001.r2-overview.png", "CF-001.r2-detail.png"])
|
||||
self.assertEqual(card["previews"][0]["revision"], "r2")
|
||||
with urlopen(url + "/api/previews/CF-001.r2-overview.png", timeout=2) as response:
|
||||
self.assertEqual(response.headers.get_content_type(), "image/png")
|
||||
self.assertEqual(response.read(), png)
|
||||
with urlopen(url + "/api/activity", timeout=2) as response:
|
||||
self.assertEqual(json.load(response), {"state": "disabled", "agents": []})
|
||||
for request, expected in [
|
||||
(url + "/README.md", 404),
|
||||
(url + "/api/previews/CF-001.r1-overview.png", 404),
|
||||
(url + "/api/previews/CF-001.r2-detail.png", 404),
|
||||
(url + "/api/previews/%2e%2e/CF-001.r2-overview.png", 404),
|
||||
(Request(url + "/api/cards", headers={"Host": "foreign.example"}), 403),
|
||||
(Request(url + "/api/cards", headers={"Sec-Fetch-Site": "cross-site"}), 403),
|
||||
]:
|
||||
|
||||
Reference in new issue
Block a user