Skip to content

Commit

Permalink
tests(router): test main routes
Browse files Browse the repository at this point in the history
Closes: #71
  • Loading branch information
Stefan Jacobi committed Jun 6, 2024
1 parent e5d64bf commit 09b5a1c
Show file tree
Hide file tree
Showing 35 changed files with 3,405 additions and 25 deletions.
2 changes: 1 addition & 1 deletion server/api/dto/request/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ type InitLoginDto struct {
}

type InitMfaLoginDto struct {
UserId *string `json:"user_id" validate:"required,min=1"`
UserId string `json:"user_id" validate:"required,min=1"`
}
25 changes: 19 additions & 6 deletions server/api/handler/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ func (credHandler *credentialsHandler) List(ctx echo.Context) error {
return err
}

service := services.NewCredentialService(ctx, *h.Tenant, credHandler.persister.GetWebauthnCredentialPersister(nil))
dtos, err := service.List(*requestDto)
if err != nil {
return err
}
return credHandler.persister.Transaction(func(tx *pop.Connection) error {
user, err := credHandler.persister.GetWebauthnUserPersister(tx).GetByUserId(requestDto.UserId, h.Tenant.ID)
if err != nil {
ctx.Logger().Error(err)
return echo.NewHTTPError(http.StatusInternalServerError, "Unable to get credentials for user").SetInternal(err)
}

if user == nil {
return echo.NewHTTPError(http.StatusNotFound, "User not found")
}

service := services.NewCredentialService(ctx, *h.Tenant, credHandler.persister.GetWebauthnCredentialPersister(tx))
dtos, err := service.List(*requestDto)
if err != nil {
return err
}

return ctx.JSON(http.StatusOK, dtos)
})

return ctx.JSON(http.StatusOK, dtos)
}

func (credHandler *credentialsHandler) Update(ctx echo.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions server/api/handler/mfa_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ func (lh *mfaLoginHandler) Init(ctx echo.Context) error {
Ctx: ctx,
Tenant: *h.Tenant,
WebauthnClient: *h.WebauthnClient,
UserId: dto.UserId,
UserId: &dto.UserId,
UserPersister: userPersister,
SessionPersister: sessionPersister,
CredentialPersister: credentialPersister,
UseMFA: true,
})

credentialAssertion, err := service.Initialize()
err = lh.handleError(h.AuditLog, models.AuditLogMfaAuthenticationInitFailed, tx, ctx, dto.UserId, nil, err)
err = lh.handleError(h.AuditLog, models.AuditLogMfaAuthenticationInitFailed, tx, ctx, &dto.UserId, nil, err)
if err != nil {
return err
}

auditErr := h.AuditLog.CreateWithConnection(tx, models.AuditLogMfaAuthenticationInitSucceeded, dto.UserId, nil, nil)
auditErr := h.AuditLog.CreateWithConnection(tx, models.AuditLogMfaAuthenticationInitSucceeded, &dto.UserId, nil, nil)
if auditErr != nil {
ctx.Logger().Error(auditErr)
return fmt.Errorf(auditlog.CreationFailureFormat, auditErr)
Expand Down
Loading

0 comments on commit 09b5a1c

Please sign in to comment.