mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 03:57:09 +00:00
feat(inspect): serveHTML route under /api/runs/<id>/html/<name>
Mirrors serveScreenshot path validation; rejects traversal segments and unknown extensions. text/html content-type so the iframe renders cleanly.
This commit is contained in:
1 parent
d2626eeccc
commit
ee3737c831
2 files changed
+64
No files matched your search
@@ -84,6 +84,7 @@ func (s *Server) handleRunsList(responseWriter http.ResponseWriter, request *htt
|
||||
|
||||
var stepPathPattern = regexp.MustCompile(`^([a-zA-Z0-9._-]+)/steps/([^/]+)$`)
|
||||
var screenshotPathPattern = regexp.MustCompile(`^([a-zA-Z0-9._-]+)/screenshots/([a-zA-Z0-9._-]+\.png)$`)
|
||||
var htmlPathPattern = regexp.MustCompile(`^([a-zA-Z0-9._-]+)/html/([a-zA-Z0-9._-]+\.html)$`)
|
||||
var runDetailPathPattern = regexp.MustCompile(`^([a-zA-Z0-9._-]+)/?$`)
|
||||
|
||||
func (s *Server) handleRunsTree(responseWriter http.ResponseWriter, request *http.Request) {
|
||||
@@ -104,6 +105,10 @@ func (s *Server) handleRunsTree(responseWriter http.ResponseWriter, request *htt
|
||||
s.serveScreenshot(responseWriter, request, match[1], match[2])
|
||||
return
|
||||
}
|
||||
if match := htmlPathPattern.FindStringSubmatch(rest); match != nil {
|
||||
s.serveHTML(responseWriter, request, match[1], match[2])
|
||||
return
|
||||
}
|
||||
if match := runDetailPathPattern.FindStringSubmatch(rest); match != nil {
|
||||
s.serveDetail(responseWriter, match[1])
|
||||
return
|
||||
@@ -160,6 +165,20 @@ func (s *Server) serveScreenshot(responseWriter http.ResponseWriter, request *ht
|
||||
http.ServeFile(responseWriter, request, full)
|
||||
}
|
||||
|
||||
func (s *Server) serveHTML(responseWriter http.ResponseWriter, request *http.Request, id, name string) {
|
||||
if !validRunID(id) || strings.Contains(name, "..") {
|
||||
http.Error(responseWriter, "run not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
full := filepath.Join(s.options.RunsDirectory, id, "html", name)
|
||||
if _, err := http.Dir(filepath.Join(s.options.RunsDirectory, id, "html")).Open(name); err != nil {
|
||||
http.NotFound(responseWriter, request)
|
||||
return
|
||||
}
|
||||
responseWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
http.ServeFile(responseWriter, request, full)
|
||||
}
|
||||
|
||||
func (s *Server) handleEvents(responseWriter http.ResponseWriter, request *http.Request) {
|
||||
flusher, ok := responseWriter.(http.Flusher)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user