tests: add HTTP server unit tests and fix several identified bugs #1471
Labels
No labels
UX
active development
backlog
blocker
bootstrap
bounty
bug
dependencies
discussion
documentation
duplicate
enhancement
flaky test
help wanted
invalid
javascript
question
release
tendentious
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mighty-gerbils/gerbil!1471
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "hmarcien/net-http-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -65,1 +68,4 @@(catch (e)(void)))));; read request head (executes concurrently with the writer thread)(let* (((values status status-line)Don't we want to thread-join! or otherwise catch any subthread error in the main thread (after maybe using ##thread-end-with-uncaught-exception! in the internal thread)?
My initial intuition, was that we could just let the Gambit runtime silently swallow the EPIPE without needing to join.
However, if we do a synchronous thread-join!, I think we will recreate the TCP deadlock: if the server stops reading (e.g. for a 413) but keeps the socket open, the writer thread will block on I/O and the main thread will deadlock on the join.
Because of this, I will go with your second suggestion and use ##thread-end-with-uncaught-exception! to surface real bugs without blocking the main thread.
@ -12,2 +15,4 @@(make-temporary-file-name "log."))(def tmp-file(string-append (make-temporary-file-name "file") ".js"))make-temporary-file-name now supports a suffix: argument.
@ -50,8 +51,13 @@(serve-dir self.path)I'm not sure what serve-dir does, but shouldn't that only be attempted after the path has been found safe?
serve-dir simply looks for an index.html inside the base directory. It is only called when the requested URL exactly matches the root path, meaning there is no user-provided subpath to sanitize here. The directory traversal check (safe-target?) is applied in the other branch, where a subpath is actually requested.
@ -55,0 +57,4 @@(let ((root (path-normalize self.path)))(let ((root/ (if (string-suffix? "/" root) root (string-append root "/"))))(string-prefix? root/ target))))))(if (and safe-target? (file-exists? target))Wait, is the root a path in the URL or in the filesystem?
Is target absolute or relative? If relative, to what?
The root (from self.path) is a path in the filesystem. target is an absolute filesystem path because path-normalize resolves the URL subpath relative to the physical root. Then, safe-target? simply checks that this final absolute path still starts with the root directory to prevent any ../ escapes.
@ -35,64 +36,75 @@=> :pair(cons "Content-Type" (mime-file-type path)))(defsyntax-case with-requested-file-info ()You might be better off using the new with-identifiers or maybe even the new with-id (in a syntax-rules)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.