Browse Source

More tests

Volodymyr Tkach 2 years ago
parent
commit
b2c812286a
1 changed files with 17 additions and 0 deletions
  1. 17 0
      utils/http/servauth/servauth_test.go

+ 17 - 0
utils/http/servauth/servauth_test.go

@@ -63,6 +63,23 @@ var _ = Describe("servauth", func() {
 			Expect(string(body)).To(Equal("Index"))
 		})
 
+		It("request credentials with default message", func() {
+			srv.Close()
+			srv = httptest.NewServer(servauth.BasicAuth(getTestHandler(), "user", "pass", ""))
+			client = srv.Client()
+
+			resp, err := client.Get(srv.URL + "/")
+			Expect(err).To(Succeed())
+			defer resp.Body.Close()
+
+			Expect(resp.StatusCode).To(Equal(http.StatusUnauthorized))
+			Expect(resp.Header["Www-Authenticate"]).To(Equal([]string{`Basic realm="Please enter username and password"`}))
+
+			body, err := io.ReadAll(resp.Body)
+			Expect(err).To(Succeed())
+			Expect(string(body)).To(Equal("Unauthorised\n"))
+		})
+
 		It("don't request credentials on empty username", func() {
 			srv.Close()
 			srv = httptest.NewServer(servauth.BasicAuth(getTestHandler(), "", "", ""))