From d9aca3d0c9fafe1b640f8251fc247d9217ff6f6a Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 18 Feb 2021 17:34:22 -0700 Subject: [PATCH] make dashboard URL check more strict --- test/integration/functional_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index cc7f19cd89..9cf735c840 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -559,7 +559,7 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) { ss.Stop(t) }() - s, err := dashboardURL(ss.Stdout) + s, err := dashboardURL(t, ss.Stdout) if err != nil { if runtime.GOOS == "windows" { t.Skip(err) @@ -587,11 +587,18 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) { } // dashboardURL gets the dashboard URL from the command stdout. -func dashboardURL(b *bufio.Reader) (string, error) { +func dashboardURL(t *testing.T, b *bufio.Reader) (string, error) { s := bufio.NewScanner(b) + + // match http://127.0.0.1:XXXXX/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ + dashURLRegexp, err := regexp.Compile(`^http:\/\/127\.0\.0\.1:[0-9]{5}\/api\/v1\/namespaces\/kubernetes-dashboard\/services\/http:kubernetes-dashboard:\/proxy\/$`) + if err != nil { + t.Fatalf("dashboard URL regex is invalid: %v", err) + } + for s.Scan() { l := s.Text() - if strings.HasPrefix(l, "http") { + if dashURLRegexp.MatchString(l) { return l, nil } }