Skip to content

Commit 488e5e7

Browse files
fix: fix health endpoint requiring auth (#15)
* fix: fix health endpoint requiring auth * chore: Updated coverage badge. * chore: updated README --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 5d35b4b commit 488e5e7

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
2-
![Coverage](https://img.shields.io/badge/Coverage-56.1%25-yellow)
2+
![Coverage](https://img.shields.io/badge/Coverage-54.2%25-yellow)
33

44
# Hello Universe API
55

@@ -22,8 +22,8 @@ A Postman collection is available to help you explore the API. Review the [Postm
2222
The quickest method to start the API server locally is by using the Docker image.
2323

2424
```shell
25-
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.11
26-
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.11
25+
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.12
26+
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.12
2727
```
2828

2929
To start the API server you must have connectivity to a Postgres instance. Use [environment variables](#environment-variables) to customize the API server start parameters.
@@ -60,6 +60,10 @@ curl --location --request POST 'http://localhost:3000/api/v1/counter' \
6060
--header 'Authorization: Bearer 931A3B02-8DCC-543F-A1B2-69423D1A0B94'
6161
```
6262

63+
> [!NOTE]
64+
>
65+
> Authorization does not apply to the `/health` endpoint.
66+
6367
## Image Verification
6468

6569
We sign our images through [Cosign](https://docs.sigstore.dev/signing/quickstart/). Review the [Image Verification](./docs/image-verification.md) page to learn more.

endpoints/healthRoute.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010

1111
"github.com/rs/zerolog/log"
12-
"spectrocloud.com/hello-universe-api/internal"
1312
)
1413

1514
// NewHandlerContext returns a new CounterRoute with a database connection.
@@ -23,15 +22,6 @@ func (health *HealthRoute) HealthHTTPHandler(writer http.ResponseWriter, request
2322
writer.Header().Set("Access-Control-Allow-Origin", "*")
2423
var payload []byte
2524

26-
if health.authorization {
27-
validation := internal.ValidateToken(request.Header.Get("Authorization"))
28-
if !validation {
29-
log.Info().Msg("Invalid token")
30-
http.Error(writer, "Invalid credentials", http.StatusUnauthorized)
31-
return
32-
}
33-
}
34-
3525
switch request.Method {
3626
case "GET":
3727
value, err := health.getHandler(request)

endpoints/healthRoute_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ func TestHealthHTTPHandlerInvalidToken(t *testing.T) {
9999
handler := http.HandlerFunc(health.HealthHTTPHandler)
100100
handler.ServeHTTP(rr, req)
101101

102-
if status := rr.Code; status != http.StatusUnauthorized {
102+
if status := rr.Code; status != http.StatusOK {
103103
t.Errorf("handler returned wrong status code: got %v want %v",
104104
status, http.StatusOK)
105105
}
106106

107-
expected := `Invalid credentials`
107+
expected := `{"status":"OK"}`
108108
msg := strings.TrimSpace(rr.Body.String())
109109
if msg != expected {
110110
t.Errorf("handler returned unexpected body: got %v want %v",

0 commit comments

Comments
 (0)