From 8a9e471b21c6911f68af857a2675f70b66e18fa0 Mon Sep 17 00:00:00 2001 From: Arpit Kuriyal Date: Tue, 23 Dec 2025 12:52:13 +0530 Subject: [PATCH 1/5] added workflow --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..a54d8248d54 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From 33f2da5186f5442afdb36fbc66d4c172cf5e8f83 Mon Sep 17 00:00:00 2001 From: Arpit Kuriyal Date: Tue, 23 Dec 2025 17:29:32 +0530 Subject: [PATCH 2/5] remove early exit 1 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a54d8248d54..c8033451c8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Force Failure - run: (exit 1) \ No newline at end of file + - name: Echo Go version + run: go version \ No newline at end of file From dc004fac630d88e96f290938536613bc30722998 Mon Sep 17 00:00:00 2001 From: Arpit Kuriyal Date: Tue, 23 Dec 2025 18:17:58 +0530 Subject: [PATCH 3/5] added test case for auth and added test step in ci --- internal/auth/auth.go | 3 +- internal/auth/auth_test.go | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 internal/auth/auth_test.go diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf638..acfc30431c9 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -7,6 +7,7 @@ import ( ) var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") +var ErrMalformedAuthHeader = errors.New("malformed authorization header") // GetAPIKey - func GetAPIKey(headers http.Header) (string, error) { @@ -16,7 +17,7 @@ func GetAPIKey(headers http.Header) (string, error) { } splitAuth := strings.Split(authHeader, " ") if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" { - return "", errors.New("malformed authorization header") + return "", ErrMalformedAuthHeader } return splitAuth[1], nil diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 00000000000..7d23927b8e9 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,63 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headerValue string + wantKey string + wantErr error + }{ + { + name: "missing authorization header", + headerValue: "", + wantErr: ErrNoAuthHeaderIncluded, + }, + { + name: "malformed header", + headerValue: "ApiKey", + wantErr: ErrMalformedAuthHeader, + }, + { + name: "wrong auth scheme", + headerValue: "Bearer token", + wantErr: ErrMalformedAuthHeader, + }, + { + name: "valid api key", + headerValue: "ApiKey my-key", + wantKey: "my-key", + wantErr: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + headers := http.Header{} + if tt.headerValue != "" { + headers.Set("Authorization", tt.headerValue) + } + + key, err := GetAPIKey(headers) + + if tt.wantErr != nil { + if err != tt.wantErr { + t.Fatalf("expected error %v, got %v", tt.wantErr, err) + } + return + } + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if key != tt.wantKey { + t.Fatalf("expected key %q, got %q", tt.wantKey, key) + } + }) + } +} From 87d5c5c07756bae11923330947abda2c462f7d64 Mon Sep 17 00:00:00 2001 From: Arpit Kuriyal Date: Tue, 23 Dec 2025 18:19:54 +0530 Subject: [PATCH 4/5] typo --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8033451c8d..24af6d65254 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,7 @@ jobs: go-version: "1.25.1" - name: Echo Go version - run: go version \ No newline at end of file + run: go version + + - name: tests + run: go test ../. \ No newline at end of file From a6588e9ff3f52151d2ca88ece9d755435bd48a16 Mon Sep 17 00:00:00 2001 From: Arpit Kuriyal Date: Tue, 23 Dec 2025 18:21:27 +0530 Subject: [PATCH 5/5] checking --- .github/workflows/ci.yml | 3 --- internal/auth/auth_test.go | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24af6d65254..c36ececb0c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,6 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.25.1" - - - name: Echo Go version - run: go version - name: tests run: go test ../. \ No newline at end of file diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 7d23927b8e9..94b42fe78f5 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -20,7 +20,7 @@ func TestGetAPIKey(t *testing.T) { { name: "malformed header", headerValue: "ApiKey", - wantErr: ErrMalformedAuthHeader, + wantErr: ErrNoAuthHeaderIncluded, }, { name: "wrong auth scheme",