8
8
"crypto/x509/pkix"
9
9
"encoding/pem"
10
10
"fmt"
11
- "github.com/kiali/kiali/util"
12
11
"io/ioutil"
13
12
"math/big"
14
13
"net"
@@ -20,6 +19,7 @@ import (
20
19
21
20
"github.com/kiali/kiali/config"
22
21
"github.com/kiali/kiali/config/security"
22
+ "github.com/kiali/kiali/util"
23
23
)
24
24
25
25
const (
@@ -34,6 +34,67 @@ const (
34
34
35
35
var tmpDir = os .TempDir ()
36
36
37
+ func TestRootContextPath (t * testing.T ) {
38
+ testPort , err := getFreePort (testHostname )
39
+ if err != nil {
40
+ t .Fatalf ("Cannot get a free port to run tests on host [%v]" , testHostname )
41
+ } else {
42
+ t .Logf ("Will use free port [%v] on host [%v] for tests" , testPort , testHostname )
43
+ }
44
+
45
+ testServerHostPort := fmt .Sprintf ("%v:%v" , testHostname , testPort )
46
+ testCustomRoot := "/customroot"
47
+
48
+ conf := new (config.Config )
49
+ conf .Server .WebRoot = testCustomRoot
50
+ conf .Server .Address = testHostname
51
+ conf .Server .Port = testPort
52
+ conf .Server .StaticContentRootDirectory = tmpDir
53
+ conf .Server .Credentials .Username = "unused"
54
+ conf .Server .Credentials .Passphrase = "unused"
55
+ conf .Auth .Strategy = "anonymous"
56
+
57
+ serverURL := fmt .Sprintf ("http://%v" , testServerHostPort )
58
+
59
+ config .Set (conf )
60
+
61
+ server := NewServer ()
62
+ server .Start ()
63
+ t .Logf ("Started test http server: %v" , serverURL )
64
+ defer func () {
65
+ server .Stop ()
66
+ t .Logf ("Stopped test server: %v" , serverURL )
67
+ }()
68
+
69
+ // the client
70
+ httpConfig := httpClientConfig {}
71
+ httpClient , err := httpConfig .buildHTTPClient ()
72
+ if err != nil {
73
+ t .Fatalf ("Failed to create http client" )
74
+ }
75
+
76
+ // no credentials
77
+ noCredentials := & security.Credentials {}
78
+
79
+ // wait for our test http server to come up
80
+ checkHTTPReady (httpClient , serverURL )
81
+
82
+ // we should be able to get to our custom web root
83
+ if _ , err = getRequestResults (t , httpClient , serverURL + testCustomRoot , noCredentials ); err != nil {
84
+ t .Fatalf ("Failed: Shouldn't have failed going to the web root: %v" , err )
85
+ }
86
+
87
+ // we should be able to get to "/" root - this just forwards to our custom web root
88
+ if _ , err = getRequestResults (t , httpClient , serverURL , noCredentials ); err != nil {
89
+ t .Fatalf ("Failed: Shouldn't have failed going to / root: %v" , err )
90
+ }
91
+
92
+ // sanity check - make sure we cannot get to a bogus context path
93
+ if _ , err = getRequestResults (t , httpClient , serverURL + "/badroot" , noCredentials ); err == nil {
94
+ t .Fatalf ("Failed: Should have failed going to /badroot" )
95
+ }
96
+ }
97
+
37
98
func TestAnonymousMode (t * testing.T ) {
38
99
testPort , err := getFreePort (testHostname )
39
100
if err != nil {
0 commit comments