mirror of
https://github.com/TautvydasDerzinskas/Thingport.git
synced 2026-10-18 20:59:55 -05:00
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeFilename(t *testing.T) {
|
|
tests := map[string]string{
|
|
" model.3mf ": "model.3mf",
|
|
"../unsafe:model?.stl": "unsafemodel.stl",
|
|
"\x00\x01": "model",
|
|
"folder\\another/file.step": "file.step",
|
|
}
|
|
|
|
for input, expected := range tests {
|
|
if actual := sanitizeFilename(input); actual != expected {
|
|
t.Fatalf("sanitizeFilename(%q) = %q, expected %q", input, actual, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRedactURLHidesTokenQueryValue(t *testing.T) {
|
|
redacted := redactURL("https://thingport.example/file?id=asset-1&token=secret-value")
|
|
if strings.Contains(redacted, "secret-value") {
|
|
t.Fatalf("redacted URL still contains the token: %s", redacted)
|
|
}
|
|
if !strings.Contains(redacted, "token=REDACTED") {
|
|
t.Fatalf("redacted URL does not contain the marker: %s", redacted)
|
|
}
|
|
}
|
|
|
|
func TestHandleProtocolRejectsUntrustedShapesBeforeDownload(t *testing.T) {
|
|
tests := []string{
|
|
"https://thingport.example/file",
|
|
"thingport://delete?url=https://thingport.example/file",
|
|
"thingport://open",
|
|
"thingport://open?url=file:///tmp/model.stl",
|
|
}
|
|
|
|
for _, raw := range tests {
|
|
if err := handleProtocol(raw, Config{}); err == nil {
|
|
t.Fatalf("handleProtocol(%q) unexpectedly succeeded", raw)
|
|
}
|
|
}
|
|
}
|