Files
node/server/http/router_case_test.go
zeekayandHanzo Dev 1d4d1041ae a chain answers to either spelling of its alias
/v1/bc/C/rpc served; /v1/bc/c/rpc 404'd. The alias names the chain, not the
shift key, and a caller typing either means the same chain — so the estate
had to memorise which case each node wanted, and got it wrong.

Exact spellings still match first and are unchanged; the folded map only
ever decides a request that would otherwise have been a 404, so it cannot
shadow a route or invent one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-08 18:15:03 -07:00

36 lines
1010 B
Go

package server
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// A chain answers to either spelling of its alias.
func TestRouteFoldsCase(t *testing.T) {
r := newRouter()
hit := 0
h := http.HandlerFunc(func(http.ResponseWriter, *http.Request) { hit++ })
if err := r.AddRouter(Chain("", "C"), "/rpc", h); err != nil {
t.Fatal(err)
}
upper := Chain("", "C") + "/rpc"
for _, path := range []string{upper, strings.ToLower(upper), strings.ToUpper(upper)} {
w := httptest.NewRecorder()
r.ServeHTTP(w, httptest.NewRequest(http.MethodPost, path, nil))
if w.Code != http.StatusOK {
t.Errorf("%s: got %d, want 200", path, w.Code)
}
}
if hit != 3 {
t.Errorf("handler ran %d times, want 3", hit)
}
// A path that names no route is still a 404.
w := httptest.NewRecorder()
r.ServeHTTP(w, httptest.NewRequest(http.MethodPost, Chain("", "D")+"/rpc", nil))
if w.Code == http.StatusOK {
t.Error("an unregistered chain answered 200; case folding must not invent routes")
}
}