Skip to content

Conversation

alexluong
Copy link
Collaborator

This is a fairly loaded PR. Here are everything it does:

  • Tenant's CRUD based on spec (with just ID & created at timestamp for now)
  • JWT generation & verification
  • JWT middleware mechanism
  • Refactor router to have 2 different authentication scopes: admin-only and tenant-scope

Added tests for a lot of the new code here. Just a sidenote, I really do enjoy writing tests in Go and the workflow so far. Caught a bug in the auth middleware from writing a more semi-comprehensive test suite.

Comment on lines +1 to +17
package api_test

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/google/uuid"
"github.com/hookdeck/EventKit/internal/destination"
"github.com/hookdeck/EventKit/internal/services/api"
"github.com/hookdeck/EventKit/internal/tenant"
"github.com/hookdeck/EventKit/internal/util/testutil"
"github.com/stretchr/testify/assert"
)

func TestRouterWithAPIKey(t *testing.T) {
t.Parallel()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you go over this test suite (this file)? I'm trying to test the router with a strong emphasis on the auth mechanism. Some questions:

  1. Can you follow the thought process / auth mechanism logic here? Is this the right approach? Any case I'm missing here?
  2. Do you feel this is too "auth-focused" and should be moved to auth_middleware_test.go instead? In that case, we can set up a smaller router vs this router with tenant & destination routes. Personally I'm fine with this and continue moving forward and we can consider that refactor after but curious if you share the sentiment.

Port int
Hostname string
APIKey string
JWTSecret string
Copy link
Collaborator Author

@alexluong alexluong Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we would need to add a JWT_SECRET env here, correct?

Base automatically changed from auth to main September 6, 2024 15:48
# Conflicts:
#	internal/config/config.go
#	internal/services/api/api.go
#	internal/services/api/auth_middleware.go
#	internal/services/api/router.go
#	internal/util/testutil/testutil.go
@alexluong alexluong merged commit cb5f9fe into main Sep 6, 2024
@alexluong alexluong deleted the tenant branch September 6, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant