From cba11d0a6a4b23a52d98616c722b8ffc4ed55eaf Mon Sep 17 00:00:00 2001 From: bjoern-m Date: Wed, 11 Dec 2024 16:50:08 +0100 Subject: [PATCH] chore: adjust tests wip chore: resolve import cycle --- backend/handler/email.go | 17 +++--- backend/handler/email_test.go | 43 ++----------- backend/handler/password_test.go | 16 +---- backend/handler/public_router.go | 2 +- backend/handler/test_helpers.go | 40 ++++++++++++ backend/handler/user_test.go | 101 +++++++------------------------ backend/handler/webauthn_test.go | 71 +++------------------- backend/session/session_test.go | 21 +------ 8 files changed, 89 insertions(+), 222 deletions(-) create mode 100644 backend/handler/test_helpers.go diff --git a/backend/handler/email.go b/backend/handler/email.go index 7a2999dad..5e47437ea 100644 --- a/backend/handler/email.go +++ b/backend/handler/email.go @@ -12,7 +12,6 @@ import ( "github.com/teamhanko/hanko/backend/dto" "github.com/teamhanko/hanko/backend/persistence" "github.com/teamhanko/hanko/backend/persistence/models" - "github.com/teamhanko/hanko/backend/session" "github.com/teamhanko/hanko/backend/webhooks/events" "github.com/teamhanko/hanko/backend/webhooks/utils" "net/http" @@ -20,18 +19,16 @@ import ( ) type EmailHandler struct { - persister persistence.Persister - cfg *config.Config - sessionManager session.Manager - auditLogger auditlog.Logger + persister persistence.Persister + cfg *config.Config + auditLogger auditlog.Logger } -func NewEmailHandler(cfg *config.Config, persister persistence.Persister, sessionManager session.Manager, auditLogger auditlog.Logger) *EmailHandler { +func NewEmailHandler(cfg *config.Config, persister persistence.Persister, auditLogger auditlog.Logger) *EmailHandler { return &EmailHandler{ - persister: persister, - cfg: cfg, - sessionManager: sessionManager, - auditLogger: auditLogger, + persister: persister, + cfg: cfg, + auditLogger: auditLogger, } } diff --git a/backend/handler/email_test.go b/backend/handler/email_test.go index db6dd83fa..ccb89c96a 100644 --- a/backend/handler/email_test.go +++ b/backend/handler/email_test.go @@ -7,9 +7,7 @@ import ( "github.com/gofrs/uuid" "github.com/stretchr/testify/suite" "github.com/teamhanko/hanko/backend/config" - "github.com/teamhanko/hanko/backend/crypto/jwk" "github.com/teamhanko/hanko/backend/dto" - "github.com/teamhanko/hanko/backend/session" "github.com/teamhanko/hanko/backend/test" "net/http" "net/http/httptest" @@ -26,7 +24,7 @@ type emailSuite struct { } func (s *emailSuite) TestEmailHandler_New() { - emailHandler := NewEmailHandler(&config.Config{}, s.Storage, sessionManager{}, test.NewAuditLogger()) + emailHandler := NewEmailHandler(&config.Config{}, s.Storage, test.NewAuditLogger()) s.NotEmpty(emailHandler) } @@ -40,11 +38,6 @@ func (s *emailSuite) TestEmailHandler_List() { e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - s.Require().NoError(err) - tests := []struct { name string userId uuid.UUID @@ -64,9 +57,7 @@ func (s *emailSuite) TestEmailHandler_List() { for _, currentTest := range tests { s.Run(currentTest.name, func() { - token, _, err := sessionManager.GenerateJWT(currentTest.userId, nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, currentTest.userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodGet, "/emails", nil) @@ -172,14 +163,7 @@ func (s *emailSuite) TestEmailHandler_Create() { cfg.Email.RequireVerification = currentTest.requiresVerification cfg.Email.Limit = currentTest.maxNumberOfAddresses e := NewPublicRouter(&cfg, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(cfg.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, cfg) - s.Require().NoError(err) - - token, _, err := sessionManager.GenerateJWT(currentTest.userId, nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, currentTest.userId) s.Require().NoError(err) body := dto.EmailCreateRequest{ @@ -235,19 +219,11 @@ func (s *emailSuite) TestEmailHandler_SetPrimaryEmail() { e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - s.Require().NoError(err) - oldPrimaryEmailId := uuid.FromStringOrNil("51b7c175-ceb6-45ba-aae6-0092221c1b84") newPrimaryEmailId := uuid.FromStringOrNil("8bb4c8a7-a3e6-48bb-b54f-20e3b485ab33") userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") - - token, _, err := sessionManager.GenerateJWT(userId, nil) - s.NoError(err) - cookie, err := sessionManager.GenerateCookie(token) - s.NoError(err) + cookie, err := generateSessionCookie(s.Storage, userId) + s.Require().NoError(err) req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/emails/%s/set_primary", newPrimaryEmailId), nil) req.AddCookie(cookie) @@ -280,16 +256,9 @@ func (s *emailSuite) TestEmailHandler_Delete() { e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) - token, _, err := sessionManager.GenerateJWT(userId, nil) - s.NoError(err) - cookie, err := sessionManager.GenerateCookie(token) - s.NoError(err) - tests := []struct { name string emailId uuid.UUID diff --git a/backend/handler/password_test.go b/backend/handler/password_test.go index 0deeb6d9b..d3805ef78 100644 --- a/backend/handler/password_test.go +++ b/backend/handler/password_test.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/teamhanko/hanko/backend/config" - "github.com/teamhanko/hanko/backend/crypto/jwk" - "github.com/teamhanko/hanko/backend/session" "github.com/teamhanko/hanko/backend/test" "golang.org/x/crypto/bcrypt" "net/http" @@ -90,10 +88,7 @@ func (s *passwordSuite) TestPasswordHandler_Set_Create() { err := s.LoadFixtures("../test/fixtures/password") s.Require().NoError(err) - sessionManager := s.GetDefaultSessionManager() - token, _, err := sessionManager.GenerateJWT(currentTest.userId, nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, currentTest.userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodPut, "/password", strings.NewReader(currentTest.body)) @@ -196,15 +191,6 @@ func (s *passwordSuite) TestPasswordHandler_Login() { } } -func (s *passwordSuite) GetDefaultSessionManager() session.Manager { - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - s.Require().NoError(err) - - return sessionManager -} - // TestMaxPasswordLength bcrypt since version 0.5.0 only accepts passwords at least 72 bytes long. This test documents this behaviour. func TestMaxPasswordLength(t *testing.T) { tests := []struct { diff --git a/backend/handler/public_router.go b/backend/handler/public_router.go index 0f0958837..cb2120ba5 100644 --- a/backend/handler/public_router.go +++ b/backend/handler/public_router.go @@ -169,7 +169,7 @@ func NewPublicRouter(cfg *config.Config, persister persistence.Persister, promet wellKnown.GET("/jwks.json", wellKnownHandler.GetPublicKeys) wellKnown.GET("/config", wellKnownHandler.GetConfig) - emailHandler := NewEmailHandler(cfg, persister, sessionManager, auditLogger) + emailHandler := NewEmailHandler(cfg, persister, auditLogger) if cfg.Passkey.Enabled { webauthnHandler, err := NewWebauthnHandler(cfg, persister, sessionManager, auditLogger, authenticatorMetadata) diff --git a/backend/handler/test_helpers.go b/backend/handler/test_helpers.go new file mode 100644 index 000000000..498558734 --- /dev/null +++ b/backend/handler/test_helpers.go @@ -0,0 +1,40 @@ +package handler + +import ( + "github.com/gofrs/uuid" + "github.com/teamhanko/hanko/backend/crypto/jwk" + "github.com/teamhanko/hanko/backend/persistence" + "github.com/teamhanko/hanko/backend/persistence/models" + "github.com/teamhanko/hanko/backend/session" + "github.com/teamhanko/hanko/backend/test" + "net/http" + "time" +) + +func getDefaultSessionManager(storage persistence.Persister) session.Manager { + jwkManager, _ := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, storage.GetJwkPersister()) + sessionManager, _ := session.NewManager(jwkManager, test.DefaultConfig) + return sessionManager +} + +func generateSessionCookie(storage persistence.Persister, userId uuid.UUID) (*http.Cookie, error) { + manager := getDefaultSessionManager(storage) + token, rawToken, err := manager.GenerateJWT(userId, nil) + if err != nil { + return nil, err + } + sessionID, _ := rawToken.Get("session_id") + _ = storage.GetSessionPersister().Create(models.Session{ + ID: uuid.FromStringOrNil(sessionID.(string)), + UserID: userId, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + ExpiresAt: nil, + LastUsed: time.Now(), + }) + cookie, err := manager.GenerateCookie(token) + if err != nil { + return nil, err + } + return cookie, nil +} diff --git a/backend/handler/user_test.go b/backend/handler/user_test.go index 10ab070ab..d7ecbcf74 100644 --- a/backend/handler/user_test.go +++ b/backend/handler/user_test.go @@ -7,10 +7,8 @@ import ( "github.com/gofrs/uuid" _ "github.com/lib/pq" "github.com/stretchr/testify/suite" - "github.com/teamhanko/hanko/backend/crypto/jwk" "github.com/teamhanko/hanko/backend/dto" "github.com/teamhanko/hanko/backend/persistence/models" - "github.com/teamhanko/hanko/backend/session" "github.com/teamhanko/hanko/backend/test" "golang.org/x/exp/slices" "net/http" @@ -249,24 +247,14 @@ func (s *userSuite) TestUserHandler_Get() { err := s.LoadFixtures("../test/fixtures/user") s.Require().NoError(err) - userId := "b5dd5267-b462-48be-b70d-bcd6f1bbe7a5" + userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) - req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/users/%s", userId), nil) + req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/users/%s", userId.String()), nil) req.AddCookie(cookie) rec := httptest.NewRecorder() @@ -277,7 +265,7 @@ func (s *userSuite) TestUserHandler_Get() { user := models.User{} err := json.Unmarshal(rec.Body.Bytes(), &user) s.NoError(err) - s.Equal(userId, user.ID.String()) + s.Equal(userId.String(), user.ID.String()) s.Equal(len(user.WebauthnCredentials), 0) } } @@ -289,24 +277,14 @@ func (s *userSuite) TestUserHandler_GetUserWithWebAuthnCredential() { err := s.LoadFixtures("../test/fixtures/user_with_webauthn_credential") s.Require().NoError(err) - userId := "b5dd5267-b462-48be-b70d-bcd6f1bbe7a5" + userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) - req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/users/%s", userId), nil) + req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/users/%s", userId.String()), nil) rec := httptest.NewRecorder() req.AddCookie(cookie) @@ -317,7 +295,7 @@ func (s *userSuite) TestUserHandler_GetUserWithWebAuthnCredential() { user := models.User{} err := json.Unmarshal(rec.Body.Bytes(), &user) s.Require().NoError(err) - s.Equal(userId, user.ID.String()) + s.Equal(userId.String(), user.ID.String()) s.Equal(len(user.WebauthnCredentials), 1) } } @@ -328,19 +306,12 @@ func (s *userSuite) TestUserHandler_Get_InvalidUserId() { } e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - userId := "b5dd5267-b462-48be-b70d-bcd6f1bbe7a5" - - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) + err := s.LoadFixtures("../test/fixtures/user") s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + + userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") + + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodGet, "/users/invalidUserId", nil) @@ -463,21 +434,11 @@ func (s *userSuite) TestUserHandler_Me() { err := s.LoadFixtures("../test/fixtures/user_with_webauthn_credential") s.Require().NoError(err) - userId := "b5dd5267-b462-48be-b70d-bcd6f1bbe7a5" + userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodGet, "/me", nil) @@ -493,7 +454,7 @@ func (s *userSuite) TestUserHandler_Me() { }{} err = json.Unmarshal(rec.Body.Bytes(), &response) s.NoError(err) - s.Equal(userId, response.UserId) + s.Equal(userId.String(), response.UserId) } } @@ -501,20 +462,14 @@ func (s *userSuite) TestUserHandler_Logout() { if testing.Short() { s.T().Skip("skipping test in short mode.") } - userId, _ := uuid.NewV4() - e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(userId, nil) + err := s.LoadFixtures("../test/fixtures/user") s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + + userId := uuid.FromStringOrNil("b5dd5267-b462-48be-b70d-bcd6f1bbe7a5") + e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) + + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodPost, "/logout", nil) @@ -545,17 +500,7 @@ func (s *userSuite) TestUserHandler_Delete() { cfg.Account.AllowDeletion = true e := NewPublicRouter(&cfg, s.Storage, nil, nil) - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - if err != nil { - panic(fmt.Errorf("failed to create jwk manager: %w", err)) - } - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - if err != nil { - panic(fmt.Errorf("failed to create session generator: %w", err)) - } - token, _, err := sessionManager.GenerateJWT(userId, nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodDelete, "/user", nil) diff --git a/backend/handler/webauthn_test.go b/backend/handler/webauthn_test.go index 8c457dbc0..62a1d060d 100644 --- a/backend/handler/webauthn_test.go +++ b/backend/handler/webauthn_test.go @@ -6,12 +6,8 @@ import ( "github.com/go-webauthn/webauthn/protocol" "github.com/gofrs/uuid" "github.com/labstack/echo/v4" - "github.com/lestrrat-go/jwx/v2/jwt" "github.com/stretchr/testify/suite" - "github.com/teamhanko/hanko/backend/crypto/jwk" - "github.com/teamhanko/hanko/backend/dto" "github.com/teamhanko/hanko/backend/persistence/models" - "github.com/teamhanko/hanko/backend/session" "github.com/teamhanko/hanko/backend/test" "net/http" "net/http/httptest" @@ -32,7 +28,8 @@ func (s *webauthnSuite) TestWebauthnHandler_NewHandler() { if testing.Short() { s.T().Skip("skipping test in short mode") } - handler, err := NewWebauthnHandler(&test.DefaultConfig, s.Storage, s.GetDefaultSessionManager(), test.NewAuditLogger(), nil) + manager := getDefaultSessionManager(s.Storage) + handler, err := NewWebauthnHandler(&test.DefaultConfig, s.Storage, manager, test.NewAuditLogger(), nil) s.NoError(err) s.NotEmpty(handler) } @@ -45,14 +42,11 @@ func (s *webauthnSuite) TestWebauthnHandler_BeginRegistration() { err := s.LoadFixtures("../test/fixtures/webauthn") s.Require().NoError(err) - userId := "ec4ef049-5b88-4321-a173-21b0eff06a04" + userId := uuid.FromStringOrNil("ec4ef049-5b88-4321-a173-21b0eff06a04") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - sessionManager := s.GetDefaultSessionManager() - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) req := httptest.NewRequest(http.MethodPost, "/webauthn/registration/initialize", nil) @@ -70,7 +64,7 @@ func (s *webauthnSuite) TestWebauthnHandler_BeginRegistration() { s.Require().NoError(err) s.NotEmpty(creationOptions.Response.Challenge) - s.Equal(uuid.FromStringOrNil(userId).Bytes(), uId) + s.Equal(uuid.FromStringOrNil(userId.String()).Bytes(), uId) s.Equal(test.DefaultConfig.Webauthn.RelyingParty.Id, creationOptions.Response.RelyingParty.ID) s.Equal(protocol.ResidentKeyRequirementRequired, creationOptions.Response.AuthenticatorSelection.ResidentKey) s.Equal(protocol.VerificationPreferred, creationOptions.Response.AuthenticatorSelection.UserVerification) @@ -86,14 +80,11 @@ func (s *webauthnSuite) TestWebauthnHandler_FinalizeRegistration() { err := s.LoadFixtures("../test/fixtures/webauthn_registration") s.Require().NoError(err) - userId := "ec4ef049-5b88-4321-a173-21b0eff06a04" + userId := uuid.FromStringOrNil("ec4ef049-5b88-4321-a173-21b0eff06a04") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - sessionManager := s.GetDefaultSessionManager() - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) body := `{ @@ -132,14 +123,11 @@ func (s *webauthnSuite) TestWebauthnHandler_FinalizeRegistration_SessionDataExpi err := s.LoadFixtures("../test/fixtures/webauthn_registration") s.Require().NoError(err) - userId := "ec4ef049-5b88-4321-a173-21b0eff06a04" + userId := uuid.FromStringOrNil("ec4ef049-5b88-4321-a173-21b0eff06a04") e := NewPublicRouter(&test.DefaultConfig, s.Storage, nil, nil) - sessionManager := s.GetDefaultSessionManager() - token, _, err := sessionManager.GenerateJWT(uuid.FromStringOrNil(userId), nil) - s.Require().NoError(err) - cookie, err := sessionManager.GenerateCookie(token) + cookie, err := generateSessionCookie(s.Storage, userId) s.Require().NoError(err) body := `{ @@ -318,49 +306,8 @@ func (s *webauthnSuite) TestWebauthnHandler_FinalizeAuthentication_TokenInHeader } } -func (s *webauthnSuite) GetDefaultSessionManager() session.Manager { - jwkManager, err := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, s.Storage.GetJwkPersister()) - s.Require().NoError(err) - sessionManager, err := session.NewManager(jwkManager, test.DefaultConfig) - s.Require().NoError(err) - - return sessionManager -} - var userId = "ec4ef049-5b88-4321-a173-21b0eff06a04" -type sessionManager struct { -} - -func (s sessionManager) GenerateJWT(_ uuid.UUID, _ *dto.EmailJwt, _ ...session.JWTOptions) (string, jwt.Token, error) { - return userId, nil, nil -} - -func (s sessionManager) GenerateCookie(token string) (*http.Cookie, error) { - return &http.Cookie{ - Name: "hanko", - Value: token, - Secure: true, - HttpOnly: true, - SameSite: http.SameSiteLaxMode, - }, nil -} - -func (s sessionManager) DeleteCookie() (*http.Cookie, error) { - return &http.Cookie{ - Name: "hanko", - Value: "", - Secure: true, - HttpOnly: true, - SameSite: http.SameSiteLaxMode, - MaxAge: -1, - }, nil -} - -func (s sessionManager) Verify(_ string) (jwt.Token, error) { - return nil, nil -} - var uId, _ = uuid.FromString(userId) var emails = []models.Email{ diff --git a/backend/session/session_test.go b/backend/session/session_test.go index 29009958b..50e3c019e 100644 --- a/backend/session/session_test.go +++ b/backend/session/session_test.go @@ -153,26 +153,9 @@ func Test_GenerateJWT_SessionID(t *testing.T) { tokenShouldHaveSessionID bool }{ { - name: "token has no session id claim if server side sessions are disabled", + name: "token has a session id claim", config: config.Config{ - Session: config.Session{ - Lifespan: "5m", - ServerSide: config.ServerSide{ - Enabled: false, - }, - }, - }, - tokenShouldHaveSessionID: false, - }, - { - name: "token has a session id claim if server side sessions are disabled", - config: config.Config{ - Session: config.Session{ - Lifespan: "5m", - ServerSide: config.ServerSide{ - Enabled: true, - }, - }, + Session: config.Session{Lifespan: "5m"}, }, tokenShouldHaveSessionID: true, },