diff --git a/lib/web/app/handler_test.go b/lib/web/app/handler_test.go index 0a262a6164ff1..a4ad3324b72ab 100644 --- a/lib/web/app/handler_test.go +++ b/lib/web/app/handler_test.go @@ -103,6 +103,42 @@ func TestAuthPOST(t *testing.T) { } } +func TestHasName(t *testing.T) { + for _, test := range []struct { + desc string + addrs []string + reqHost string + reqURL string + expectedURL string + hasName bool + }{ + { + desc: "NOK - invalid host", + addrs: []string{"proxy.com"}, + reqURL: "badurl.com", + expectedURL: "", + hasName: false, + }, + { + desc: "OK - adds path", + addrs: []string{"proxy.com"}, + reqURL: "https://app1.proxy.com/foo", + expectedURL: "https://proxy.com/web/launch/app1.proxy.com%3Fpath=/foo", + hasName: true, + }, + } { + t.Run(test.desc, func(t *testing.T) { + req, err := http.NewRequest(http.MethodGet, test.reqURL, nil) + require.NoError(t, err) + + addrs := utils.MustParseAddrList(test.addrs...) + u, ok := HasName(req, addrs) + require.Equal(t, test.expectedURL, u) + require.Equal(t, test.hasName, ok) + }) + } +} + func TestMatchApplicationServers(t *testing.T) { clusterName := "test-cluster" publicAddr := "app.example.com"