Files
artifactapi/internal/api/v1/scheme_test.go
T
unkin-agent 3b69b58ba3 Harden nuget per-request rewrite and fix HEAD length
- set Cache-Control no-store and Vary on rewritten responses
- accept only http/https X-Forwarded-Proto
- reject invalid Host headers and JSON-escape the injected base URL
- route remote HEAD and serve rewritten HEAD via the GET path
- classify snupkg, readme and icon as immutable
2026-10-17 12:39:02 +11:00

27 lines
803 B
Go

package v1
import (
"crypto/tls"
"net/http"
"testing"
)
func TestScheme(t *testing.T) {
if got := scheme(&http.Request{TLS: &tls.ConnectionState{}}); got != "https" {
t.Errorf("TLS request scheme = %q, want https", got)
}
r := &http.Request{Header: http.Header{"X-Forwarded-Proto": {"https"}}}
if got := scheme(r); got != "https" {
t.Errorf("X-Forwarded-Proto scheme = %q, want https", got)
}
for _, bogus := range []string{"javascript", "HTTPS", "https, http", "ftp"} {
r := &http.Request{Header: http.Header{"X-Forwarded-Proto": {bogus}}}
if got := scheme(r); got != "http" {
t.Errorf("X-Forwarded-Proto %q scheme = %q, want http", bogus, got)
}
}
if got := scheme(&http.Request{Header: http.Header{}}); got != "http" {
t.Errorf("default scheme = %q, want http", got)
}
}