diff --git a/src/autoscaler/operator/cmd/operator/operator_test.go b/src/autoscaler/operator/cmd/operator/operator_test.go index 4a13cda514..621cfaac9f 100644 --- a/src/autoscaler/operator/cmd/operator/operator_test.go +++ b/src/autoscaler/operator/cmd/operator/operator_test.go @@ -1,6 +1,7 @@ package main_test import ( + "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" "fmt" "io" "net/http" @@ -340,13 +341,14 @@ var _ = Describe("Operator", Serial, func() { }) }) - Describe("when Health server is ready to serve RESTful API", func() { + Describe("when Health server is ready to serve RESTful API without basic Auth", func() { BeforeEach(func() { basicAuthConfig := cfg basicAuthConfig.Health.HealthCheckUsername = "" basicAuthConfig.Health.HealthCheckPassword = "" + basicAuthConfig.Health.UnprotectedEndpoints = []string{"/", routes.LivenessPath, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath} runner.configPath = writeConfig(&basicAuthConfig).Name() - runner.Start() Eventually(runner.Session.Buffer, 2*time.Second).Should(Say("operator.started")) }) @@ -355,9 +357,10 @@ var _ = Describe("Operator", Serial, func() { runner.ClearLockDatabase() }) - Context("when a request to query health comes", func() { + Context("when a request to query prometheus comes", func() { It("returns with a 200", func() { - rsp, err := healthHttpClient.Get(fmt.Sprintf("http://127.0.0.1:%d", healthport)) + prometheusUrl := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.PrometheusPath) + rsp, err := healthHttpClient.Get(prometheusUrl) Expect(err).NotTo(HaveOccurred()) Expect(rsp.StatusCode).To(Equal(http.StatusOK)) raw, _ := io.ReadAll(rsp.Body) @@ -387,48 +390,8 @@ var _ = Describe("Operator", Serial, func() { Context("when username and password are incorrect for basic authentication during health check", func() { It("should return 401", func() { - - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil) - Expect(err).NotTo(HaveOccurred()) - - req.SetBasicAuth("wrongusername", "wrongpassword") - - rsp, err := healthHttpClient.Do(req) - Expect(err).ToNot(HaveOccurred()) - Expect(rsp.StatusCode).To(Equal(http.StatusUnauthorized)) - }) - }) - - Context("when username and password are correct for basic authentication during health check", func() { - It("should return 200", func() { - - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil) - Expect(err).NotTo(HaveOccurred()) - - req.SetBasicAuth(cfg.Health.HealthCheckUsername, cfg.Health.HealthCheckPassword) - - rsp, err := healthHttpClient.Do(req) - Expect(err).ToNot(HaveOccurred()) - Expect(rsp.StatusCode).To(Equal(http.StatusOK)) - }) - }) - }) - - Describe("when Health server is ready to serve RESTful API with basic Auth", func() { - BeforeEach(func() { - runner.Start() - - Eventually(runner.Session.Buffer, 2*time.Second).Should(Say("operator.started")) - }) - - AfterEach(func() { - runner.ClearLockDatabase() - }) - - Context("when username and password are incorrect for basic authentication during health check", func() { - It("should return 401", func() { - - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil) + livenessUrl := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath) + req, err := http.NewRequest(http.MethodGet, livenessUrl, nil) Expect(err).NotTo(HaveOccurred()) req.SetBasicAuth("wrongusername", "wrongpassword") @@ -441,8 +404,9 @@ var _ = Describe("Operator", Serial, func() { Context("when username and password are correct for basic authentication during health check", func() { It("should return 200", func() { + livenessUrl := fmt.Sprintf("http://127.0.0.1:%d%s", healthport, routes.LivenessPath) - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/health", healthport), nil) + req, err := http.NewRequest(http.MethodGet, livenessUrl, nil) Expect(err).NotTo(HaveOccurred()) req.SetBasicAuth(cfg.Health.HealthCheckUsername, cfg.Health.HealthCheckPassword)