test(web/auth): improve password
This commit is contained in:
parent
36e71f7cba
commit
84fc14679b
|
@ -3,7 +3,6 @@ package auth
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"dev.sum7.eu/genofire/golang-lib/web"
|
"dev.sum7.eu/genofire/golang-lib/web"
|
||||||
|
@ -43,19 +42,15 @@ func init() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result := ws.DB.Save(&d)
|
if err := ws.DB.Save(&d).Error; err != nil {
|
||||||
if err := result.Error; err != nil {
|
|
||||||
c.JSON(http.StatusInternalServerError, web.HTTPError{
|
c.JSON(http.StatusInternalServerError, web.HTTPError{
|
||||||
Message: web.APIErrorInternalDatabase,
|
Message: web.APIErrorInternalDatabase,
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
return
|
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"
|
passwordNew := "test"
|
||||||
|
|
||||||
hErr := web.HTTPError{}
|
hErr := web.HTTPError{}
|
||||||
// invalid
|
// no auth
|
||||||
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr)
|
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr)
|
||||||
assert.Equal(APIErrorNoSession, hErr.Message)
|
assert.Equal(APIErrorNoSession, hErr.Message)
|
||||||
|
|
||||||
s.TestLogin()
|
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
|
res := false
|
||||||
// set new password
|
// set new password
|
||||||
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusOK, &res)
|
s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusOK, &res)
|
||||||
|
|
Loading…
Reference in New Issue