Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not send an error message for authentication failure #23

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/console/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func (s *service) TokenHandler(request *restful.Request, response *restful.Respo

authToken := getAuthToken(request)
if authToken == "" {
_ = response.WriteError(http.StatusUnauthorized, fmt.Errorf("authenticating token cannot be empty"))
_ = response.WriteError(http.StatusUnauthorized, nil)
return
}

err = s.checkVncRbac(request.Request.Context(), authToken, params.name, params.namespace)
if err != nil {
_ = response.WriteError(http.StatusUnauthorized, err)
_ = response.WriteError(http.StatusUnauthorized, nil)
return
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/console/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = Describe("Service", func() {
testService.TokenHandler(request, response)

Expect(recorder.Code).To(Equal(http.StatusUnauthorized))
Expect(recorder.Body.String()).To(Equal("authenticating token cannot be empty"))
akrejcir marked this conversation as resolved.
Show resolved Hide resolved
Expect(recorder.Body.String()).To(BeEmpty())
})

It("should fail if Authorization header is not Bearer", func() {
Expand All @@ -156,7 +156,7 @@ var _ = Describe("Service", func() {
testService.TokenHandler(request, response)

Expect(recorder.Code).To(Equal(http.StatusUnauthorized))
Expect(recorder.Body.String()).To(Equal("authenticating token cannot be empty"))
Expect(recorder.Body.String()).To(BeEmpty())
})

It("should fail if authorization token is invalid", func() {
Expand All @@ -170,7 +170,7 @@ var _ = Describe("Service", func() {
testService.TokenHandler(request, response)

Expect(recorder.Code).To(Equal(http.StatusUnauthorized))
Expect(recorder.Body.String()).To(Equal("token is not authenticated"))
Expect(recorder.Body.String()).To(BeEmpty())
})

It("should fail if authorization token does not have permission to access virtualmachineinstances/vnc", func() {
Expand All @@ -184,7 +184,7 @@ var _ = Describe("Service", func() {
testService.TokenHandler(request, response)

Expect(recorder.Code).To(Equal(http.StatusUnauthorized))
Expect(recorder.Body.String()).To(ContainSubstring("does not have permission to access virtualmachineinstances/vnc endpoint"))
Expect(recorder.Body.String()).To(BeEmpty())
})

It("should pass user info from TokenReview to SubjectAccessReview", func() {
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = Describe("Kubevirt proxy", func() {
code, body, err := httpGet(tokenUrl, "", TestHttpClient)
Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal(http.StatusUnauthorized))
Expect(string(body)).To(ContainSubstring("authenticating token cannot be empty"))
Expect(string(body)).To(BeEmpty())
})

It("should fail if not authorized to access vmi/vnc endpoint", func() {
Expand All @@ -74,7 +74,7 @@ var _ = Describe("Kubevirt proxy", func() {
code, body, err := httpGet(tokenUrl, saToken, TestHttpClient)
Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal(http.StatusUnauthorized))
Expect(string(body)).To(ContainSubstring("does not have permission to access virtualmachineinstances/vnc endpoint"))
Expect(string(body)).To(BeEmpty())
})

It("should fail if VM does not exist", func() {
Expand Down