make dashboard URL check more strict

pull/10509/head
Steven Powell 2021-02-18 17:34:22 -07:00
parent af4364ba6f
commit d9aca3d0c9
1 changed files with 10 additions and 3 deletions

View File

@ -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
}
}