Files
zeekay 34440ff863 feat: add native staticFiles middleware + fix rebrand test breakage
Native staticFiles middleware (compiled-in, not plugin):
- pkg/config/dynamic/middlewares.go: StaticFiles config type
- pkg/middlewares/staticfiles/: full implementation (SPA, dir listing,
  cache-control, custom 404, index files)
- pkg/server/middleware/middlewares.go: wired into builder chain
- pkg/config/dynamic/zz_generated.deepcopy.go: DeepCopy methods

Fix all pre-existing test failures from traefik→ingress rebrand:
- builtins: entrypoint name traefik→ingress in JSON fixtures
- cookie: hash expectations updated for _INGRESS_BACKEND_ salt
- nomad: canary service hash expectations updated
- k8s ingress: remove duplicate map keys, fix ingressClass annotation
- k8s gateway: annotation prefix traefik.io→hanzo.ai, add missing
  IngressService fixture
- k8s ingress-nginx: add CurvePreferences to TLS test fixtures
- auth: fix realm defaults and response body assertions

68 packages tested, 0 failures.
2026-03-18 23:47:06 -07:00

82 lines
1.7 KiB
Go

package cookie
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetName(t *testing.T) {
testCases := []struct {
desc string
cookieName string
backendName string
expectedCookieName string
}{
{
desc: "with backend name, without cookie name",
cookieName: "",
backendName: "/my/BACKEND-v1.0~rc1",
expectedCookieName: "_e1d76",
},
{
desc: "without backend name, with cookie name",
cookieName: "/my/BACKEND-v1.0~rc1",
backendName: "",
expectedCookieName: "_my_BACKEND-v1.0~rc1",
},
{
desc: "with backend name, with cookie name",
cookieName: "cookie",
backendName: "backend",
expectedCookieName: "cookie",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
cookieName := GetName(test.cookieName, test.backendName)
assert.Equal(t, test.expectedCookieName, cookieName)
})
}
}
func Test_sanitizeName(t *testing.T) {
testCases := []struct {
desc string
srcName string
expectedName string
}{
{
desc: "with /",
srcName: "/my/BACKEND-v1.0~rc1",
expectedName: "_my_BACKEND-v1.0~rc1",
},
{
desc: "some chars",
srcName: "!#$%&'()*+-./:<=>?@[]^_`{|}~",
expectedName: "!#$%&'__*+-._________^_`_|_~",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
cookieName := sanitizeName(test.srcName)
assert.Equal(t, test.expectedName, cookieName, "Cookie name")
})
}
}
func TestGenerateName(t *testing.T) {
cookieName := GenerateName("backend")
assert.Len(t, "_8032c", 6)
assert.Equal(t, "_8032c", cookieName)
}