Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/71 add tests #75

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
}
19 changes: 13 additions & 6 deletions server/api/handler/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ func NewUserHandler(persister persistence.Persister) UserHandler {

func (uh *userHandler) List(ctx echo.Context) error {
var request adminRequest.UserListRequest
err := (&echo.DefaultBinder{}).BindQueryParams(ctx, &request)
err := ctx.Bind(&request)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "unable to parse request")
ctx.Logger().Error(err)
return echo.NewHTTPError(http.StatusBadRequest, "unable to list users").SetInternal(err)
}

err = ctx.Validate(&request)
if err != nil {
ctx.Logger().Error(err)
return echo.NewHTTPError(http.StatusBadRequest, "unable to list users").SetInternal(err)
}

if request.Page == 0 {
Expand Down Expand Up @@ -92,12 +99,12 @@ func (uh *userHandler) Get(ctx echo.Context) error {

userIdString := ctx.Param("user_id")
if userIdString == "" {
return echo.NewHTTPError(http.StatusBadRequest, "missing user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

userId, err := uuid.FromString(userIdString)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

return uh.persister.GetConnection().Transaction(func(tx *pop.Connection) error {
Expand Down Expand Up @@ -126,12 +133,12 @@ func (uh *userHandler) Remove(ctx echo.Context) error {

userIdString := ctx.Param("user_id")
if userIdString == "" {
return echo.NewHTTPError(http.StatusBadRequest, "missing user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

userId, err := uuid.FromString(userIdString)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

return uh.persister.GetConnection().Transaction(func(tx *pop.Connection) error {
Expand Down
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
Loading