Skip to content

Commit 13add52

Browse files
Merge pull request #17292 from smarterclayton/fix_metrics_extended
Delegated auth for router metrics allows anonymous
2 parents 191bc6a + 87bdb4b commit 13add52

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/extended/router/metrics.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var _ = g.Describe("[Conformance][Area:Networking][Feature:Router] openshift rou
9595
defer func() { oc.AdminKubeClient().Core().Pods(ns).Delete(execPodName, metav1.NewDeleteOptions(1)) }()
9696

9797
g.By("preventing access without a username and password")
98-
err = expectURLStatusCodeExec(ns, execPodName, fmt.Sprintf("http://%s:%d/metrics", host, statsPort), 401)
98+
err = expectURLStatusCodeExec(ns, execPodName, fmt.Sprintf("http://%s:%d/metrics", host, statsPort), 401, 403)
9999
o.Expect(err).NotTo(o.HaveOccurred())
100100

101101
g.By("checking for the expected metrics")
@@ -180,7 +180,7 @@ var _ = g.Describe("[Conformance][Area:Networking][Feature:Router] openshift rou
180180
defer func() { oc.AdminKubeClient().Core().Pods(ns).Delete(execPodName, metav1.NewDeleteOptions(1)) }()
181181

182182
g.By("preventing access without a username and password")
183-
err := expectURLStatusCodeExec(ns, execPodName, fmt.Sprintf("http://%s:%d/debug/pprof/heap", host, statsPort), 401)
183+
err := expectURLStatusCodeExec(ns, execPodName, fmt.Sprintf("http://%s:%d/debug/pprof/heap", host, statsPort), 401, 403)
184184
o.Expect(err).NotTo(o.HaveOccurred())
185185

186186
g.By("at /debug/pprof")
@@ -263,16 +263,18 @@ func findMetricLabels(f *dto.MetricFamily, labels map[string]string, match strin
263263
return result
264264
}
265265

266-
func expectURLStatusCodeExec(ns, execPodName, url string, statusCode int) error {
266+
func expectURLStatusCodeExec(ns, execPodName, url string, statusCodes ...int) error {
267267
cmd := fmt.Sprintf("curl -s -o /dev/null -w '%%{http_code}' %q", url)
268268
output, err := e2e.RunHostCmd(ns, execPodName, cmd)
269269
if err != nil {
270270
return fmt.Errorf("host command failed: %v\n%s", err, output)
271271
}
272-
if output != strconv.Itoa(statusCode) {
273-
return fmt.Errorf("last response from server was not %d: %s", statusCode, output)
272+
for _, statusCode := range statusCodes {
273+
if output == strconv.Itoa(statusCode) {
274+
return nil
275+
}
274276
}
275-
return nil
277+
return fmt.Errorf("last response from server was not any of %v: %s", statusCodes, output)
276278
}
277279

278280
func getAuthenticatedURLViaPod(ns, execPodName, url, user, pass string) (string, error) {

0 commit comments

Comments
 (0)