test(web/auth): improve password
This commit is contained in:
parent
36e71f7cba
commit
84fc14679b
|
@ -3,7 +3,6 @@ package auth
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"dev.sum7.eu/genofire/golang-lib/web"
|
||||
|
@ -43,19 +42,15 @@ func init() {
|
|||
return
|
||||
}
|
||||
|
||||
result := ws.DB.Save(&d)
|
||||
if err := result.Error; err != nil {
|
||||
if err := ws.DB.Save(&d).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, web.HTTPError{
|
||||
Message: web.APIErrorInternalDatabase,
|
||||
Error: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
if result.RowsAffected > 1 {
|
||||
log.Panicf("there should not be more then 1 user with the same email, it was %d session", result.RowsAffected)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result.RowsAffected == 1)
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -21,12 +21,17 @@ func TestAPIPassword(t *testing.T) {
|
|||
passwordNew := "test"
|
||||
|
||||
hErr := web.HTTPError{}
|
||||
// invalid
|
||||
// no auth
|
||||
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr)
|
||||
assert.Equal(APIErrorNoSession, hErr.Message)
|
||||
|
||||
s.TestLogin()
|
||||
|
||||
hErr = web.HTTPError{}
|
||||
// invalid
|
||||
s.Request(http.MethodPost, "/api/v1/my/auth/password", nil, http.StatusBadRequest, &hErr)
|
||||
assert.Equal(web.APIErrorInvalidRequestFormat, hErr.Message)
|
||||
|
||||
res := false
|
||||
// set new password
|
||||
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusOK, &res)
|
||||
|
|
Loading…
Reference in New Issue