mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00
NOISSUE - fix response for passwd endpoints (#1393)
* fix response for passwd endpoints Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix test for passwd related responses Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix test for passwd related responses Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
This commit is contained in:
parent
e87715ba31
commit
f9f51470b1
@ -47,7 +47,7 @@ func passwordResetRequestEndpoint(svc users.Service) endpoint.Endpoint {
|
|||||||
if err := req.validate(); err != nil {
|
if err := req.validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res := passwChangeRes{}
|
res := passwResetReqRes{}
|
||||||
email := req.Email
|
email := req.Email
|
||||||
if err := svc.GenerateResetToken(ctx, email, req.Host); err != nil {
|
if err := svc.GenerateResetToken(ctx, email, req.Host); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -71,7 +71,6 @@ func passwordResetEndpoint(svc users.Service) endpoint.Endpoint {
|
|||||||
if err := svc.ResetPassword(ctx, req.Token, req.Password); err != nil {
|
if err := svc.ResetPassword(ctx, req.Token, req.Password); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res.Msg = ""
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,21 +293,12 @@ func TestPasswordReset(t *testing.T) {
|
|||||||
ts := newServer(svc)
|
ts := newServer(svc)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
client := ts.Client()
|
client := ts.Client()
|
||||||
resData := struct {
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
}{
|
|
||||||
"",
|
|
||||||
}
|
|
||||||
reqData := struct {
|
reqData := struct {
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
ConfPass string `json:"confirm_password,omitempty"`
|
ConfPass string `json:"confirm_password,omitempty"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
expectedSuccess := toJSON(resData)
|
|
||||||
|
|
||||||
resData.Msg = users.ErrUserNotFound.Error()
|
|
||||||
|
|
||||||
_, err := svc.Register(context.Background(), user)
|
_, err := svc.Register(context.Background(), user)
|
||||||
require.Nil(t, err, fmt.Sprintf("register user got unexpected error: %s", err))
|
require.Nil(t, err, fmt.Sprintf("register user got unexpected error: %s", err))
|
||||||
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||||
@ -343,7 +334,7 @@ func TestPasswordReset(t *testing.T) {
|
|||||||
res string
|
res string
|
||||||
tok string
|
tok string
|
||||||
}{
|
}{
|
||||||
{"password reset with valid token", reqExisting, contentType, http.StatusCreated, expectedSuccess, token},
|
{"password reset with valid token", reqExisting, contentType, http.StatusCreated, "{}", token},
|
||||||
{"password reset with invalid token", reqNoExist, contentType, http.StatusForbidden, unauthRes, token},
|
{"password reset with invalid token", reqNoExist, contentType, http.StatusForbidden, unauthRes, token},
|
||||||
{"password reset with confirm password not matching", reqPassNoMatch, contentType, http.StatusBadRequest, malformedRes, token},
|
{"password reset with confirm password not matching", reqPassNoMatch, contentType, http.StatusBadRequest, malformedRes, token},
|
||||||
{"password reset request with invalid request format", "{", contentType, http.StatusBadRequest, malformedRes, token},
|
{"password reset request with invalid request format", "{", contentType, http.StatusBadRequest, malformedRes, token},
|
||||||
@ -382,19 +373,12 @@ func TestPasswordChange(t *testing.T) {
|
|||||||
|
|
||||||
tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: 0})
|
tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: 0})
|
||||||
token := tkn.GetValue()
|
token := tkn.GetValue()
|
||||||
resData := struct {
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
}{
|
|
||||||
"",
|
|
||||||
}
|
|
||||||
expectedSuccess := toJSON(resData)
|
|
||||||
|
|
||||||
reqData := struct {
|
reqData := struct {
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
OldPassw string `json:"old_password,omitempty"`
|
OldPassw string `json:"old_password,omitempty"`
|
||||||
}{}
|
}{}
|
||||||
resData.Msg = users.ErrUnauthorizedAccess.Error()
|
|
||||||
|
|
||||||
_, err := svc.Register(context.Background(), user)
|
_, err := svc.Register(context.Background(), user)
|
||||||
require.Nil(t, err, fmt.Sprintf("register user got unexpected error: %s", err))
|
require.Nil(t, err, fmt.Sprintf("register user got unexpected error: %s", err))
|
||||||
@ -413,8 +397,6 @@ func TestPasswordChange(t *testing.T) {
|
|||||||
reqData.Password = invalidPass
|
reqData.Password = invalidPass
|
||||||
reqWeakPass := toJSON(reqData)
|
reqWeakPass := toJSON(reqData)
|
||||||
|
|
||||||
resData.Msg = users.ErrUnauthorizedAccess.Error()
|
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
desc string
|
desc string
|
||||||
req string
|
req string
|
||||||
@ -423,7 +405,7 @@ func TestPasswordChange(t *testing.T) {
|
|||||||
res string
|
res string
|
||||||
tok string
|
tok string
|
||||||
}{
|
}{
|
||||||
{"password change with valid token", dataResExisting, contentType, http.StatusCreated, expectedSuccess, token},
|
{"password change with valid token", dataResExisting, contentType, http.StatusCreated, "{}", token},
|
||||||
{"password change with invalid token", reqNoExist, contentType, http.StatusForbidden, unauthRes, ""},
|
{"password change with invalid token", reqNoExist, contentType, http.StatusForbidden, unauthRes, ""},
|
||||||
{"password change with invalid old password", reqWrongPass, contentType, http.StatusForbidden, unauthRes, token},
|
{"password change with invalid old password", reqWrongPass, contentType, http.StatusForbidden, unauthRes, token},
|
||||||
{"password change with invalid new password", reqWeakPass, contentType, http.StatusBadRequest, weakPassword, token},
|
{"password change with invalid new password", reqWeakPass, contentType, http.StatusBadRequest, weakPassword, token},
|
||||||
|
@ -193,10 +193,25 @@ type errorRes struct {
|
|||||||
Err string `json:"error"`
|
Err string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type passwChangeRes struct {
|
type passwResetReqRes struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (res passwResetReqRes) Code() int {
|
||||||
|
return http.StatusCreated
|
||||||
|
}
|
||||||
|
|
||||||
|
func (res passwResetReqRes) Headers() map[string]string {
|
||||||
|
return map[string]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (res passwResetReqRes) Empty() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type passwChangeRes struct {
|
||||||
|
}
|
||||||
|
|
||||||
func (res passwChangeRes) Code() int {
|
func (res passwChangeRes) Code() int {
|
||||||
return http.StatusCreated
|
return http.StatusCreated
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user