mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Plugin assets, external scripts and CSP overrides (#4260)
* Add assets for plugins * Move plugin javascript and css into separate endpoints * Allow loading external scripts * Add csp overrides * Only include enabled plugins * Move URLMap to utils * Use URLMap for assets * Add documentation
This commit is contained in:
70
pkg/utils/urlmap_test.go
Normal file
70
pkg/utils/urlmap_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestURLMap_GetFilesystemLocation(t *testing.T) {
|
||||
// create the URLMap
|
||||
urlMap := make(URLMap)
|
||||
urlMap["/"] = "root"
|
||||
urlMap["/foo"] = "bar"
|
||||
|
||||
empty := make(URLMap)
|
||||
var nilMap URLMap
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
urlMap URLMap
|
||||
url string
|
||||
wantNewURL string
|
||||
wantFsPath string
|
||||
}{
|
||||
{
|
||||
name: "simple",
|
||||
urlMap: urlMap,
|
||||
url: "/foo/bar",
|
||||
wantNewURL: "/bar",
|
||||
wantFsPath: "bar",
|
||||
},
|
||||
{
|
||||
name: "root",
|
||||
urlMap: urlMap,
|
||||
url: "/baz",
|
||||
wantNewURL: "/baz",
|
||||
wantFsPath: "root",
|
||||
},
|
||||
{
|
||||
name: "root",
|
||||
urlMap: urlMap,
|
||||
url: "/baz",
|
||||
wantNewURL: "/baz",
|
||||
wantFsPath: "root",
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
urlMap: empty,
|
||||
url: "/xyz",
|
||||
wantNewURL: "/xyz",
|
||||
wantFsPath: "",
|
||||
},
|
||||
{
|
||||
name: "nil",
|
||||
urlMap: nilMap,
|
||||
url: "/xyz",
|
||||
wantNewURL: "/xyz",
|
||||
wantFsPath: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotNewURL, gotFsPath := tt.urlMap.GetFilesystemLocation(tt.url)
|
||||
if gotNewURL != tt.wantNewURL {
|
||||
t.Errorf("URLMap.GetFilesystemLocation() gotNewURL = %v, want %v", gotNewURL, tt.wantNewURL)
|
||||
}
|
||||
if gotFsPath != tt.wantFsPath {
|
||||
t.Errorf("URLMap.GetFilesystemLocation() gotFsPath = %v, want %v", gotFsPath, tt.wantFsPath)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user