22
.github/workflows/ci.yml
vendored
Normal file
22
.github/workflows/ci.yml
vendored
Normal file
@@ -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.23.0"
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: go test ./... -cover
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ out
|
|||||||
.env
|
.env
|
||||||
learn-cicd-starter
|
learn-cicd-starter
|
||||||
notely
|
notely
|
||||||
|
|
||||||
|
.idea
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|

|
||||||
|
|
||||||
# learn-cicd-starter (Notely)
|
# learn-cicd-starter (Notely)
|
||||||
|
|
||||||
This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).
|
This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).
|
||||||
@@ -21,3 +23,5 @@ go build -o notely && ./notely
|
|||||||
*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
|
*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
|
||||||
|
|
||||||
You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course!
|
You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course!
|
||||||
|
|
||||||
|
RDarius' version of Boot.dev's Notely app
|
||||||
71
internal/auth/auth_test.go
Normal file
71
internal/auth/auth_test.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetAPIKey_ValidHeader(t *testing.T) {
|
||||||
|
headers := http.Header{}
|
||||||
|
headers.Set("Authorization", "ApiKey valid-api-key-123")
|
||||||
|
|
||||||
|
apiKey, err := GetAPIKey(headers)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if apiKey != "valid-api-key-123" {
|
||||||
|
t.Fatalf("expected API key to be 'valid-api-key-123', got '%s'", apiKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAPIKey_MissingHeader(t *testing.T) {
|
||||||
|
headers := http.Header{}
|
||||||
|
|
||||||
|
_, err := GetAPIKey(headers)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, got nil")
|
||||||
|
}
|
||||||
|
if !errors.Is(err, ErrNoAuthHeaderIncluded) {
|
||||||
|
t.Fatalf("expected error to be 'ErrNoAuthHeaderIncluded', got '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAPIKey_MalformedHeader_MissingPrefix(t *testing.T) {
|
||||||
|
headers := http.Header{}
|
||||||
|
headers.Set("Authorization", "Bearer invalid-api-key") // Invalid prefix, should be ApiKey
|
||||||
|
|
||||||
|
_, err := GetAPIKey(headers)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, got nil")
|
||||||
|
}
|
||||||
|
if err.Error() != "malformed authorization header" {
|
||||||
|
t.Fatalf("expected error to be 'malformed authorization header', got '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAPIKey_MalformedHeader_MissingKey(t *testing.T) {
|
||||||
|
headers := http.Header{}
|
||||||
|
headers.Set("Authorization", "ApiKey") // Missing key part
|
||||||
|
|
||||||
|
_, err := GetAPIKey(headers)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, got nil")
|
||||||
|
}
|
||||||
|
if err.Error() != "malformed authorization header" {
|
||||||
|
t.Fatalf("expected error to be 'malformed authorization header', got '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAPIKey_EmptyHeader(t *testing.T) {
|
||||||
|
headers := http.Header{}
|
||||||
|
headers.Set("Authorization", "") // Empty header value
|
||||||
|
|
||||||
|
_, err := GetAPIKey(headers)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, got nil")
|
||||||
|
}
|
||||||
|
if !errors.Is(err, ErrNoAuthHeaderIncluded) {
|
||||||
|
t.Fatalf("expected error to be 'ErrNoAuthHeaderIncluded', got '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user