mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-05 01:09:04 +02:00
Fix E2E (maybe)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user