-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(users): add secret validation on registration
Add secret validation on the service layer when registering users. Updated HTTP status codes and adjusted test cases for issue token and client creation validation with missing either identity or secret. Signed-off-by: Rodney Osodo <[email protected]>
- Loading branch information
1 parent
163ccbb
commit 152eedf
Showing
8 changed files
with
51 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ func TestCreateClient(t *testing.T) { | |
user := sdk.User{ | ||
Name: "clientname", | ||
Tags: []string{"tag1", "tag2"}, | ||
Credentials: sdk.Credentials{Identity: "[email protected]", Secret: "secret"}, | ||
Credentials: sdk.Credentials{Identity: "[email protected]", Secret: "12345678"}, | ||
Status: mgclients.EnabledStatus.String(), | ||
} | ||
conf := sdk.Config{ | ||
|
@@ -96,7 +96,7 @@ func TestCreateClient(t *testing.T) { | |
client: sdk.User{}, | ||
response: sdk.User{}, | ||
token: token, | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, errors.ErrMalformedEntity), http.StatusBadRequest), | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingIdentity), http.StatusBadRequest), | ||
}, | ||
{ | ||
desc: "register a user that can't be marshalled", | ||
|
@@ -135,7 +135,7 @@ func TestCreateClient(t *testing.T) { | |
}, | ||
response: sdk.User{}, | ||
token: token, | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, errors.ErrMalformedEntity), http.StatusBadRequest), | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingIdentity), http.StatusBadRequest), | ||
}, | ||
{ | ||
desc: "register user with empty identity", | ||
|
@@ -147,14 +147,7 @@ func TestCreateClient(t *testing.T) { | |
}, | ||
response: sdk.User{}, | ||
token: token, | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, errors.ErrMalformedEntity), http.StatusBadRequest), | ||
}, | ||
{ | ||
desc: "register empty user", | ||
client: sdk.User{}, | ||
response: sdk.User{}, | ||
token: token, | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, errors.ErrMalformedEntity), http.StatusBadRequest), | ||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingIdentity), http.StatusBadRequest), | ||
}, | ||
{ | ||
desc: "register user with every field defined", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,34 @@ func TestCreateClientReqValidate(t *testing.T) { | |
}, | ||
err: apiutil.ErrNameSize, | ||
}, | ||
{ | ||
desc: "missing identity in request", | ||
req: createClientReq{ | ||
token: valid, | ||
client: mgclients.Client{ | ||
ID: validID, | ||
Name: valid, | ||
Credentials: mgclients.Credentials{ | ||
Secret: valid, | ||
}, | ||
}, | ||
}, | ||
err: apiutil.ErrMissingIdentity, | ||
}, | ||
{ | ||
desc: "missing secret in request", | ||
req: createClientReq{ | ||
token: valid, | ||
client: mgclients.Client{ | ||
ID: validID, | ||
Name: valid, | ||
Credentials: mgclients.Credentials{ | ||
Identity: "[email protected]", | ||
}, | ||
}, | ||
}, | ||
err: apiutil.ErrMissingSecret, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
err := tc.req.validate() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters