From f4eeafd0f7381cbb07211431a06508df6635d6c6 Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Fri, 31 Oct 2025 12:36:48 +0100 Subject: [PATCH 01/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c2bec0368b7..3856be055a3 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,4 @@ go build -o notely && ./notely *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! +Basel Saadeh's Version of Boot.dev's Notely app. From 68b7c28f81b32305178d2958606fbffe460cc1fc Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Sun, 2 Nov 2025 17:18:12 +0000 Subject: [PATCH 02/14] Move CI workflow to correct folder --- .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..f75218588bf --- /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 cc5d55d0f32a876415b5a9ff987caf4882eb40ff Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Sun, 2 Nov 2025 17:58:20 +0000 Subject: [PATCH 03/14] Make CI pass: print GO version --- .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 f75218588bf..7754e39cf03 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: Print GO Version + run: go version \ No newline at end of file From 6bdc4557c0b2069385d02f3a356cfe46074c48eb Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 09:56:10 +0000 Subject: [PATCH 04/14] CI:make it pass by printing Go version --- .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 7754e39cf03..a54d8248d54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Print GO Version - run: go version \ No newline at end of file + - name: Force Failure + run: (exit 1) \ No newline at end of file From 82a9a126ccf4fb98ba78cc5005fde9d69f24f58b Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 11:24:47 +0000 Subject: [PATCH 05/14] Intentionally breaking test for CI check --- .github/workflows/ci.yml | 4 ++-- internal/auth/auth_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 internal/auth/auth_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a54d8248d54..115f96b9952 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: Run unit test + run: go test ./... \ No newline at end of file diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 00000000000..a95cac82660 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,29 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey_ValidHeader(t *testing.T) { + header := http.Header{} + header.Set("Authorization", "ApiKey 12345") + + key, err := GetAPIKey(header) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + if key != "WRONG_KEY" { + t.Errorf("expected key '12345', got %q", key) + } +} + +func TestGetAPIKey_MissingPrefix(t *testing.T) { + header := http.Header{} + header.Set("Authorization", "12345") + + _, err := GetAPIKey(header) + if err == nil { + t.Fatal("expected an error, got nil") + } +} From b431045142532ccbc6714e27593a4535b71cad9b Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 11:36:34 +0000 Subject: [PATCH 06/14] Trim and validate API key in GetAPIKey --- internal/auth/auth.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf638..a1d7f0998a7 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -10,14 +10,21 @@ var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") // GetAPIKey - func GetAPIKey(headers http.Header) (string, error) { - authHeader := headers.Get("Authorization") - if authHeader == "" { - return "", ErrNoAuthHeaderIncluded - } - splitAuth := strings.Split(authHeader, " ") - if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" { - return "", errors.New("malformed authorization header") - } + authHeader := strings.TrimSpace(headers.Get("Authorization")) + if authHeader == "" { + return "", ErrNoAuthHeaderIncluded + } - return splitAuth[1], nil + // Must start with "ApiKey " and then a non-empty key + const prefix = "ApiKey " + if !strings.HasPrefix(authHeader, prefix) { + return "", errors.New("malformed authorization header") + } + + key := strings.TrimSpace(strings.TrimPrefix(authHeader, prefix)) + if key == "" { + return "", errors.New("malformed authorization header") + } + + return key, nil } From 225ad3869fdd9b26951733b1cc32a747bf19ef6b Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 11:42:26 +0000 Subject: [PATCH 07/14] Fix GetAPIKey trimming issue --- internal/auth/auth.go | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index a1d7f0998a7..27856376831 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -1,30 +1,28 @@ package auth import ( - "errors" - "net/http" - "strings" + "errors" + "net/http" + "strings" ) var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") -// GetAPIKey - func GetAPIKey(headers http.Header) (string, error) { - authHeader := strings.TrimSpace(headers.Get("Authorization")) - if authHeader == "" { - return "", ErrNoAuthHeaderIncluded - } + authHeader := strings.TrimSpace(headers.Get("Authorization")) + if authHeader == "" { + return "", ErrNoAuthHeaderIncluded + } - // Must start with "ApiKey " and then a non-empty key - const prefix = "ApiKey " - if !strings.HasPrefix(authHeader, prefix) { - return "", errors.New("malformed authorization header") - } + const prefix = "ApiKey " + if !strings.HasPrefix(authHeader, prefix) { + return "", errors.New("malformed authorization header") + } - key := strings.TrimSpace(strings.TrimPrefix(authHeader, prefix)) - if key == "" { - return "", errors.New("malformed authorization header") - } + key := strings.TrimSpace(strings.TrimPrefix(authHeader, prefix)) + if key == "" { + return "", errors.New("malformed authorization header") + } - return key, nil + return key, nil } From dfc03a1dd315c3ff82303fe1b9213203a10e4a90 Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 12:11:13 +0000 Subject: [PATCH 08/14] Fix GetAPIKey implementation for CI tests --- internal/auth/auth.go | 10 +++------- internal/auth/auth_test.go | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 27856376831..fe3ec9afda5 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -14,15 +14,11 @@ func GetAPIKey(headers http.Header) (string, error) { return "", ErrNoAuthHeaderIncluded } - const prefix = "ApiKey " - if !strings.HasPrefix(authHeader, prefix) { - return "", errors.New("malformed authorization header") - } - - key := strings.TrimSpace(strings.TrimPrefix(authHeader, prefix)) - if key == "" { + parts := strings.Fields(authHeader) + if len(parts) != 2 || parts[0] != "ApiKey" { return "", errors.New("malformed authorization header") } + key := strings.TrimSpace(parts[1]) return key, nil } diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index a95cac82660..d016f5b9a6a 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -1,29 +1,29 @@ package auth import ( - "net/http" - "testing" + "net/http" + "testing" ) func TestGetAPIKey_ValidHeader(t *testing.T) { - header := http.Header{} - header.Set("Authorization", "ApiKey 12345") + h := http.Header{} + h.Set("Authorization", "ApiKey 12345") - key, err := GetAPIKey(header) - if err != nil { - t.Fatalf("expected no error, got %v", err) - } - if key != "WRONG_KEY" { - t.Errorf("expected key '12345', got %q", key) - } + key, err := GetAPIKey(h) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + if key != "12345" { + t.Errorf("expected key '12345', got '%s'", key) + } } func TestGetAPIKey_MissingPrefix(t *testing.T) { - header := http.Header{} - header.Set("Authorization", "12345") + h := http.Header{} + h.Set("Authorization", "12345") - _, err := GetAPIKey(header) - if err == nil { - t.Fatal("expected an error, got nil") - } + _, err := GetAPIKey(h) + if err == nil { + t.Fatal("expected an error, got nil") + } } From 3e80ccdc925c11ba77a83e4bd8e80d674fc93eca Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 13:16:00 +0000 Subject: [PATCH 09/14] Add code coverage flag to CI tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 115f96b9952..73c6413ee7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.25.1" - name: Run unit test - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From 11f8ba4e47d5ae9ff71a62eb791d3c022c2fdc03 Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 14:15:43 +0000 Subject: [PATCH 10/14] Fix README badge syntax --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3856be055a3..662959d2354 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Tests](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml) # 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). From 748fce8abf8325ad64aec36d3362d3652c28e70d Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Mon, 3 Nov 2025 14:24:53 +0000 Subject: [PATCH 11/14] Fix CI badge syntax once and for all --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 662959d2354..6ff15846cef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Tests](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml) +[![Tests](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main) # 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). From c26c848c5f14af307ad5bf0fa2f6e0fd2d6853ff Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Tue, 4 Nov 2025 08:58:47 +0000 Subject: [PATCH 12/14] ADD CI status badge to README.me --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ff15846cef..3eb615b41a1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[![Tests](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main) +![CI](https://github.com/basel-saadeh/go-ci-exercise/actions/workflows/ci.yml/badge.svg?branch=main) + # 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). From e884a3c46e6804022e75fcfb867447215c2f8973 Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Tue, 4 Nov 2025 10:52:32 +0000 Subject: [PATCH 13/14] hopping it will work this time --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3eb615b41a1..5aeb0983fe8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -![CI](https://github.com/basel-saadeh/go-ci-exercise/actions/workflows/ci.yml/badge.svg?branch=main) - +![CI](https://github.com/Basel-saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) # 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). From eab20ec0d36b3eceb6fbfcf5410fcaa491b9836a Mon Sep 17 00:00:00 2001 From: Basel-Saadeh Date: Tue, 4 Nov 2025 11:03:43 +0000 Subject: [PATCH 14/14] ONE MORE TRY --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5aeb0983fe8..d91640f014f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -![CI](https://github.com/Basel-saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) # 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). +![CI](https://github.com/Basel-Saadeh/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) + +This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).gi ## Local Development