From 0c061d7f3e0e66a9e63461ec58394356f0b8858f Mon Sep 17 00:00:00 2001 From: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Date: Sat, 18 Jul 2026 10:04:32 -0700 Subject: [PATCH] Fix E2E (maybe) --- backend/internal/bootstrap/services_bootstrap.go | 11 +++++------ backend/internal/webauthn/module.go | 9 ++++----- backend/internal/webauthn/service.go | 12 +++++------- backend/internal/webauthn/service_test.go | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/backend/internal/bootstrap/services_bootstrap.go b/backend/internal/bootstrap/services_bootstrap.go index 20baa984..a8f4f2f4 100644 --- a/backend/internal/bootstrap/services_bootstrap.go +++ b/backend/internal/bootstrap/services_bootstrap.go @@ -81,12 +81,11 @@ func initServices( } svc.customClaimService = service.NewCustomClaimService(db) - svc.webauthnModule, err = webauthn.New(ctx, webauthn.Dependencies{ - DB: db, - AppURL: common.EnvConfig.AppURL, - Signer: svc.jwtService, - AuditLog: svc.auditLogService, - AppConfig: svc.appConfigService, + svc.webauthnModule, err = webauthn.New(webauthn.Dependencies{ + DB: db, + AppURL: common.EnvConfig.AppURL, + Signer: svc.jwtService, + AuditLog: svc.auditLogService, }) if err != nil { return nil, fmt.Errorf("failed to create WebAuthn module: %w", err) diff --git a/backend/internal/webauthn/module.go b/backend/internal/webauthn/module.go index 41a45dce..0da68c53 100644 --- a/backend/internal/webauthn/module.go +++ b/backend/internal/webauthn/module.go @@ -27,9 +27,8 @@ type Dependencies struct { DB *gorm.DB AppURL string - Signer TokenService - AuditLog AuditLogger - AppConfig *appconfig.AppConfigService + Signer TokenService + AuditLog AuditLogger } type Module struct { @@ -37,8 +36,8 @@ type Module struct { handler *handler } -func New(ctx context.Context, deps Dependencies) (*Module, error) { - service, err := newService(ctx, deps) +func New(deps Dependencies) (*Module, error) { + service, err := newService(deps) if err != nil { return nil, err } diff --git a/backend/internal/webauthn/service.go b/backend/internal/webauthn/service.go index 16afb611..00296c6f 100644 --- a/backend/internal/webauthn/service.go +++ b/backend/internal/webauthn/service.go @@ -24,6 +24,8 @@ import ( // It must match the value emitted by the JWT service in the access token's "amr" claim const authenticationMethodPhishingResistant = "phr" +const defaultRPDisplayName = "Pocket ID" + type Service struct { db *gorm.DB webAuthn *gowebauthn.WebAuthn @@ -31,14 +33,10 @@ type Service struct { auditLog AuditLogger } -func newService(ctx context.Context, deps Dependencies) (*Service, error) { - dbConfig, err := deps.AppConfig.GetConfig(ctx) - if err != nil { - return nil, fmt.Errorf("error loading app configuration: %w", err) - } - +func newService(deps Dependencies) (*Service, error) { wa, err := gowebauthn.New(&gowebauthn.Config{ - RPDisplayName: dbConfig.AppName.String(), + // Set a default value, it will be set again later + RPDisplayName: defaultRPDisplayName, RPID: utils.GetHostnameFromURL(deps.AppURL), RPOrigins: []string{deps.AppURL}, AuthenticatorSelection: protocol.AuthenticatorSelection{ diff --git a/backend/internal/webauthn/service_test.go b/backend/internal/webauthn/service_test.go index 7cda9fa9..ef4a9ec2 100644 --- a/backend/internal/webauthn/service_test.go +++ b/backend/internal/webauthn/service_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/pocket-id/pocket-id/backend/internal/appconfig" "github.com/pocket-id/pocket-id/backend/internal/common" "github.com/pocket-id/pocket-id/backend/internal/model" datatype "github.com/pocket-id/pocket-id/backend/internal/model/types" @@ -119,6 +120,20 @@ func TestCreateReauthenticationTokenWithAccessToken(t *testing.T) { }) } +func TestWebAuthnDisplayNameUsesRequestConfig(t *testing.T) { + service, err := newService(Dependencies{ + DB: testutils.NewDatabaseForTest(t), + AppURL: "https://example.com", + }) + require.NoError(t, err) + require.Equal(t, defaultRPDisplayName, service.webAuthn.Config.RPDisplayName) + + ctx := appconfig.NewTestContext(t.Context(), &appconfig.AppConfigModel{AppName: "Custom App"}) + err = service.updateWebAuthnConfig(ctx) + require.NoError(t, err) + require.Equal(t, "Custom App", service.webAuthn.Config.RPDisplayName) +} + func TestConsumeReauthenticationTokenReturnsTokenCreationTime(t *testing.T) { db := testutils.NewDatabaseForTest(t) service := &Service{db: db}