mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
data retention: allow to notify results via e-mail
This commit is contained in:
@@ -480,6 +480,46 @@ func TestUpdateWebAdminInvalidClaims(t *testing.T) {
|
||||
assert.Contains(t, rr.Body.String(), "Invalid token claims")
|
||||
}
|
||||
|
||||
func TestRetentionInvalidTokenClaims(t *testing.T) {
|
||||
username := "retentionuser"
|
||||
user := dataprovider.User{
|
||||
BaseUser: sdk.BaseUser{
|
||||
Username: username,
|
||||
Password: "pwd",
|
||||
HomeDir: filepath.Join(os.TempDir(), username),
|
||||
Status: 1,
|
||||
},
|
||||
}
|
||||
user.Permissions = make(map[string][]string)
|
||||
user.Permissions["/"] = []string{dataprovider.PermAny}
|
||||
user.Filters.AllowAPIKeyAuth = true
|
||||
err := dataprovider.AddUser(&user)
|
||||
assert.NoError(t, err)
|
||||
folderRetention := []common.FolderRetention{
|
||||
{
|
||||
Path: "/",
|
||||
Retention: 0,
|
||||
DeleteEmptyDirs: true,
|
||||
},
|
||||
}
|
||||
asJSON, err := json.Marshal(folderRetention)
|
||||
assert.NoError(t, err)
|
||||
req, _ := http.NewRequest(http.MethodPost, retentionBasePath+"/"+username+"/check?notify=Email", bytes.NewBuffer(asJSON))
|
||||
|
||||
rctx := chi.NewRouteContext()
|
||||
rctx.URLParams.Add("username", username)
|
||||
|
||||
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
|
||||
req = req.WithContext(context.WithValue(req.Context(), jwtauth.ErrorCtxKey, errors.New("error")))
|
||||
rr := httptest.NewRecorder()
|
||||
startRetentionCheck(rr, req)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
assert.Contains(t, rr.Body.String(), "Invalid token claims")
|
||||
|
||||
err = dataprovider.DeleteUser(username)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestCSRFToken(t *testing.T) {
|
||||
// invalid token
|
||||
err := verifyCSRFToken("token")
|
||||
|
||||
Reference in New Issue
Block a user