Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
Signed-off-by: aryan <aryan1bhokare@gmail.com>
  • Loading branch information
aryan-bhokare committed May 24, 2024
1 parent f9c29f1 commit 2e5b970
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion chaoscenter/authentication/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ const docTemplate = `{
},
"message": {
"type": "string",
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/authentication/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@
},
"message": {
"type": "string",
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
"example": "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ definitions:
type: integer
message:
example: Please ensure the password is atleast 8 characters long and atmost
16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet
and 1 special character
16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase
alphabet and 1 special character
type: string
type: object
response.ErrStrictUsernamePolicyViolation:
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/authentication/api/handlers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ErrUserDeactivated struct {

type ErrStrictPasswordPolicyViolation struct {
Code int `json:"code" example:"401"`
Message string `json:"message" example:"Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"`
Message string `json:"message" example:"Please ensure the password is atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character"`
}

type ErrStrictUsernamePolicyViolation struct {
Expand Down
7 changes: 3 additions & 4 deletions chaoscenter/authentication/api/handlers/rest/user_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CreateUser(service services.ApplicationService) gin.HandlerFunc {
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRequest], presenter.CreateErrorResponse(utils.ErrInvalidRequest))
return
}
//username validation
//username validation
err = utils.ValidateStrictUsername(userRequest.Username)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrStrictUsernamePolicyViolation], presenter.CreateErrorResponse(utils.ErrStrictUsernamePolicyViolation))
Expand All @@ -72,7 +72,6 @@ func CreateUser(service services.ApplicationService) gin.HandlerFunc {
c.JSON(utils.ErrorStatusCodes[utils.ErrStrictPasswordPolicyViolation], presenter.CreateErrorResponse(utils.ErrStrictPasswordPolicyViolation))
return
}


// Assigning UID to user
uID := uuid.Must(uuid.NewRandom()).String()
Expand Down Expand Up @@ -436,13 +435,13 @@ func UpdatePassword(service services.ApplicationService) gin.HandlerFunc {
}
username := c.MustGet("username").(string)
userPasswordRequest.Username = username
if userPasswordRequest.NewPassword != "" {
if userPasswordRequest.NewPassword != "" {
err := utils.ValidateStrictPassword(userPasswordRequest.NewPassword)
if err != nil {
c.JSON(utils.ErrorStatusCodes[utils.ErrStrictPasswordPolicyViolation], presenter.CreateErrorResponse(utils.ErrStrictPasswordPolicyViolation))
return
}
}else {
} else {
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRequest], presenter.CreateErrorResponse(utils.ErrInvalidRequest))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func TestCreateUser(t *testing.T) {
}
}


func TestUpdateUser(t *testing.T) {
service := new(mocks.MockedApplicationService)

Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/authentication/pkg/utils/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var ErrorDescriptions = map[AppError]string{
ErrInvalidRequest: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed",
ErrUnauthorized: "The user does not have requested authorization to access this resource",
ErrUserExists: "This username is already assigned to another user",
ErrStrictPasswordPolicyViolation: "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
ErrStrictPasswordPolicyViolation: "Please ensure the password is atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 16 characters long.",
ErrEmptyProjectName: "Project name can't be empty",
ErrInvalidRole: "Role is invalid",
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/pkg/utils/sanitizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func SanitizeString(input string) string {

/*
ValidateStrictPassword represents and checks for the following patterns:
- Input is at least 8 characters long and atmost 16 characters long
- Input is at least 8 characters long and at most 16 characters long
- Input contains at least one special character of these @$!%*?_&
- Input contains at least one digit
- Input contains at least one uppercase alphabet
Expand Down Expand Up @@ -58,4 +58,4 @@ func ValidateStrictUsername(username string) error {
}

return nil
}
}

0 comments on commit 2e5b970

Please sign in to comment.