mirror of
https://github.com/goauthentik/authentik
synced 2026-05-10 17:12:08 +02:00
* admin/files: support %(theme)s variable in media file paths * wip * Apply suggestion from @rissson Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Dominic R <dominic@sdko.org> --------- Signed-off-by: Dominic R <dominic@sdko.org> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package web
|
|
|
|
import "testing"
|
|
|
|
func TestPathMatchesWithTheme(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
jwtPath string
|
|
requestedPath string
|
|
want bool
|
|
}{
|
|
{
|
|
name: "exact match without theme variable",
|
|
jwtPath: "media/public/logo.png",
|
|
requestedPath: "media/public/logo.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "no match without theme variable",
|
|
jwtPath: "media/public/logo.png",
|
|
requestedPath: "media/public/other.png",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "theme variable matches light theme",
|
|
jwtPath: "media/public/logo-%(theme)s.png",
|
|
requestedPath: "media/public/logo-light.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "theme variable matches dark theme",
|
|
jwtPath: "media/public/logo-%(theme)s.png",
|
|
requestedPath: "media/public/logo-dark.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "theme variable does not match invalid theme",
|
|
jwtPath: "media/public/logo-%(theme)s.png",
|
|
requestedPath: "media/public/logo-blue.png",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "theme variable in directory path",
|
|
jwtPath: "media/%(theme)s/logo.png",
|
|
requestedPath: "media/light/logo.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "multiple theme variables",
|
|
jwtPath: "media/%(theme)s/logo-%(theme)s.png",
|
|
requestedPath: "media/light/logo-light.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "multiple theme variables with dark",
|
|
jwtPath: "media/%(theme)s/logo-%(theme)s.png",
|
|
requestedPath: "media/dark/logo-dark.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "multiple theme variables mixed themes should not match",
|
|
jwtPath: "media/%(theme)s/logo-%(theme)s.png",
|
|
requestedPath: "media/light/logo-dark.png",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "theme variable with nested path",
|
|
jwtPath: "media/public/brand/logo-%(theme)s.svg",
|
|
requestedPath: "media/public/brand/logo-dark.svg",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "empty paths",
|
|
jwtPath: "",
|
|
requestedPath: "",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "theme variable only",
|
|
jwtPath: "%(theme)s",
|
|
requestedPath: "light",
|
|
want: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := pathMatchesWithTheme(tt.jwtPath, tt.requestedPath)
|
|
if got != tt.want {
|
|
t.Errorf("pathMatchesWithTheme(%q, %q) = %v, want %v",
|
|
tt.jwtPath, tt.requestedPath, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|