|
|
@@ -25413,6 +25413,24 @@ func TestAdminForgotPassword(t *testing.T) {
|
|
|
|
|
|
lastResetCode = ""
|
|
|
form.Set("username", altAdminUsername)
|
|
|
+ // disable the admin
|
|
|
+ admin.Status = 0
|
|
|
+ admin, _, err = httpdtest.UpdateAdmin(admin, http.StatusOK)
|
|
|
+ assert.NoError(t, err)
|
|
|
+
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webAdminForgotPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req.RemoteAddr = defaultRemoteAddr
|
|
|
+ setLoginCookie(req, loginCookie)
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ rr = executeRequest(req)
|
|
|
+ assert.Equal(t, http.StatusFound, rr.Code)
|
|
|
+ assert.Len(t, lastResetCode, 0)
|
|
|
+
|
|
|
+ admin.Status = 1
|
|
|
+ admin, _, err = httpdtest.UpdateAdmin(admin, http.StatusOK)
|
|
|
+ assert.NoError(t, err)
|
|
|
+
|
|
|
req, err = http.NewRequest(http.MethodPost, webAdminForgotPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
assert.NoError(t, err)
|
|
|
req.RemoteAddr = defaultRemoteAddr
|
|
|
@@ -25451,7 +25469,10 @@ func TestAdminForgotPassword(t *testing.T) {
|
|
|
rr = executeRequest(req)
|
|
|
assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nErrorChangePwdGeneric)
|
|
|
- // ok
|
|
|
+ // disable the admin
|
|
|
+ admin.Status = 0
|
|
|
+ admin, _, err = httpdtest.UpdateAdmin(admin, http.StatusOK)
|
|
|
+ assert.NoError(t, err)
|
|
|
form.Set("code", lastResetCode)
|
|
|
req, err = http.NewRequest(http.MethodPost, webAdminResetPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
assert.NoError(t, err)
|
|
|
@@ -25459,6 +25480,19 @@ func TestAdminForgotPassword(t *testing.T) {
|
|
|
setLoginCookie(req, loginCookie)
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
rr = executeRequest(req)
|
|
|
+ assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nErrorChangePwdGeneric)
|
|
|
+
|
|
|
+ admin.Status = 1
|
|
|
+ admin, _, err = httpdtest.UpdateAdmin(admin, http.StatusOK)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ // ok
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webAdminResetPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req.RemoteAddr = defaultRemoteAddr
|
|
|
+ setLoginCookie(req, loginCookie)
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ rr = executeRequest(req)
|
|
|
assert.Equal(t, http.StatusFound, rr.Code)
|
|
|
|
|
|
loginCookie, csrfToken, err = getCSRFTokenMock(webLoginPath, defaultRemoteAddr)
|
|
|
@@ -25593,10 +25627,11 @@ func TestUserForgotPassword(t *testing.T) {
|
|
|
rr = executeRequest(req)
|
|
|
assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nErrorPwdResetForbidded)
|
|
|
+ user.ExpirationDate = util.GetTimeAsMsSinceEpoch(time.Now().Add(-1 * time.Hour))
|
|
|
user.Filters.WebClient = []string{sdk.WebClientAPIKeyAuthChangeDisabled}
|
|
|
user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
|
|
|
assert.NoError(t, err)
|
|
|
-
|
|
|
+ // user is expired
|
|
|
lastResetCode = ""
|
|
|
req, err = http.NewRequest(http.MethodPost, webClientForgotPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
assert.NoError(t, err)
|
|
|
@@ -25605,6 +25640,18 @@ func TestUserForgotPassword(t *testing.T) {
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
rr = executeRequest(req)
|
|
|
assert.Equal(t, http.StatusFound, rr.Code)
|
|
|
+ assert.Len(t, lastResetCode, 0)
|
|
|
+
|
|
|
+ user.ExpirationDate = util.GetTimeAsMsSinceEpoch(time.Now().Add(24 * time.Hour))
|
|
|
+ user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webClientForgotPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req.RemoteAddr = defaultRemoteAddr
|
|
|
+ setLoginCookie(req, loginCookie)
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ rr = executeRequest(req)
|
|
|
+ assert.Equal(t, http.StatusFound, rr.Code)
|
|
|
assert.GreaterOrEqual(t, len(lastResetCode), 20)
|
|
|
// no login token
|
|
|
form = make(url.Values)
|
|
|
@@ -25648,8 +25695,23 @@ func TestUserForgotPassword(t *testing.T) {
|
|
|
rr = executeRequest(req)
|
|
|
assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
assert.Contains(t, rr.Body.String(), util.I18nErrorChangePwdGeneric)
|
|
|
- // ok
|
|
|
+ // Invalid login condition
|
|
|
form.Set("code", lastResetCode)
|
|
|
+ user.Filters.DeniedProtocols = []string{common.ProtocolHTTP}
|
|
|
+ user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, err = http.NewRequest(http.MethodPost, webClientResetPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req.RemoteAddr = defaultRemoteAddr
|
|
|
+ setLoginCookie(req, loginCookie)
|
|
|
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ rr = executeRequest(req)
|
|
|
+ assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
+ assert.Contains(t, rr.Body.String(), util.I18nErrorChangePwdGeneric)
|
|
|
+ // ok
|
|
|
+ user.Filters.DeniedProtocols = []string{common.ProtocolFTP}
|
|
|
+ user, _, err = httpdtest.UpdateUser(user, http.StatusOK, "")
|
|
|
+ assert.NoError(t, err)
|
|
|
req, err = http.NewRequest(http.MethodPost, webClientResetPwdPath, bytes.NewBuffer([]byte(form.Encode())))
|
|
|
assert.NoError(t, err)
|
|
|
req.RemoteAddr = defaultRemoteAddr
|