forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiali_test.go
47 lines (41 loc) · 1.1 KB
/
kiali_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"testing"
"github.com/kiali/kiali/config"
)
func TestValidateWebRoot(t *testing.T) {
// create a base config that we know is valid
conf := config.NewConfig()
conf.Server.StaticContentRootDirectory = "."
conf.Auth.Strategy = "anonymous"
// now test some web roots, both valid ones and invalid ones
validWebRoots := []string{
"/",
"/kiali",
"/abc/clustername/api/v1/namespaces/istio-system/services/kiali:80/proxy/kiali",
"/a/0/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%aa",
"/kiali0-._~!$&'()*+,;=:@%aa",
}
invalidWebRoots := []string{
"/kiali/",
"kiali/",
"/^kiali",
"/foo/../bar",
"/../bar",
"../bar",
}
for _, webroot := range validWebRoots {
conf.Server.WebRoot = webroot
config.Set(conf)
if err := validateConfig(); err != nil {
t.Errorf("Web root validation should have succeeded for [%v]: %v", conf.Server.WebRoot, err)
}
}
for _, webroot := range invalidWebRoots {
conf.Server.WebRoot = webroot
config.Set(conf)
if err := validateConfig(); err == nil {
t.Errorf("Web root validation should have failed [%v]", conf.Server.WebRoot)
}
}
}