Skip to content

Commit

Permalink
fix: use normalized lowercased user identifier in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrynenko committed Dec 12, 2024
1 parent befcd8b commit be7e39a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/service/handlers/delete_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func DeleteUser(w http.ResponseWriter, r *http.Request) {
userID, err := requests.DeleteUserByID(r)
userID, err := requests.GetPathUserID(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/service/handlers/get_proof.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package handlers

import (
"net/http"

"github.com/rarimo/verificator-svc/internal/service/requests"
"github.com/rarimo/verificator-svc/internal/service/responses"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
"net/http"
)

func GetProofByUserID(w http.ResponseWriter, r *http.Request) {
userID, err := requests.GetProofByUserID(r)
userID, err := requests.GetPathUserID(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/service/handlers/get_user.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package handlers

import (
"net/http"

"github.com/rarimo/verificator-svc/internal/service/requests"
"github.com/rarimo/verificator-svc/internal/service/responses"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
"net/http"
)

func GetUser(w http.ResponseWriter, r *http.Request) {
userID, err := requests.DeleteUserByID(r)
userID, err := requests.GetPathUserID(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/service/handlers/get_verification_status.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package handlers

import (
"net/http"

"github.com/rarimo/verificator-svc/internal/service/requests"
"github.com/rarimo/verificator-svc/internal/service/responses"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
"net/http"
)

func GetVerificationStatusById(w http.ResponseWriter, r *http.Request) {
userID, err := requests.GetVerificationStatusByID(r)
userID, err := requests.GetPathUserID(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/proof_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func GetProofParamsById(w http.ResponseWriter, r *http.Request) {
userIDHash, err := requests.GetProofParamsByID(r)
userIDHash, err := requests.GetPathUserIDHash(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/proof_params_light.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func GetProofParamsLightById(w http.ResponseWriter, r *http.Request) {
userIDHash, err := requests.GetProofParamsByID(r)
userIDHash, err := requests.GetPathUserIDHash(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand Down
12 changes: 8 additions & 4 deletions internal/service/requests/get_proof_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package requests

import (
"fmt"
"net/http"
"strings"

val "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is"
"gitlab.com/distributed_lab/urlval/v4"
"net/http"
)

type UserInputs struct {
Expand All @@ -21,14 +23,16 @@ func NewGetUserInputs(r *http.Request) (userInputs UserInputs, err error) {
err = newDecodeError("query", err)
return
}

userInputs.UserId = strings.ToLower(userInputs.UserId)

err = val.Errors{
"user_id": val.Validate(userInputs.UserId, val.Required, is.Email),
"user_id": val.Validate(userInputs.UserId, val.Required),
"age_lower_bound": val.Validate(userInputs.AgeLowerBound, val.Required),
"uniqueness": val.Validate(val.Required),
"nationality": val.Validate(userInputs.Nationality, val.Required),
"event_id": val.Validate(userInputs.EventID, is.Hexadecimal),
}.
Filter()
}.Filter()
return
}

Expand Down
17 changes: 17 additions & 0 deletions internal/service/requests/user_id_hash_path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package requests

import (
"net/http"

"github.com/go-chi/chi"
val "github.com/go-ozzo/ozzo-validation/v4"
)

func GetPathUserIDHash(r *http.Request) (userIdHash string, err error) {
userIdHash = chi.URLParam(r, "user_id_hash")

err = val.Errors{
"user_id": val.Validate(userIdHash, val.Required),
}.Filter()
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package requests

import (
"net/http"
"strings"

"github.com/go-chi/chi"
val "github.com/go-ozzo/ozzo-validation/v4"
)

func GetVerificationStatusByID(r *http.Request) (userId string, err error) {
userId = chi.URLParam(r, "user_id")
func GetPathUserID(r *http.Request) (userId string, err error) {
userId = strings.ToLower(chi.URLParam(r, "user_id"))

err = val.Errors{
"user_id": val.Validate(userId, val.Required),
Expand Down

0 comments on commit be7e39a

Please sign in to comment.