mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
add event manager
auto backup removed from setting. You can now schedule backups with the event manager Fixes #762 Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -701,35 +702,6 @@ func TestConnectionStatus(t *testing.T) {
|
||||
assert.Len(t, stats, 0)
|
||||
}
|
||||
|
||||
func TestQuotaScans(t *testing.T) {
|
||||
username := "username"
|
||||
assert.True(t, QuotaScans.AddUserQuotaScan(username))
|
||||
assert.False(t, QuotaScans.AddUserQuotaScan(username))
|
||||
usersScans := QuotaScans.GetUsersQuotaScans()
|
||||
if assert.Len(t, usersScans, 1) {
|
||||
assert.Equal(t, usersScans[0].Username, username)
|
||||
assert.Equal(t, QuotaScans.UserScans[0].StartTime, usersScans[0].StartTime)
|
||||
QuotaScans.UserScans[0].StartTime = 0
|
||||
assert.NotEqual(t, QuotaScans.UserScans[0].StartTime, usersScans[0].StartTime)
|
||||
}
|
||||
|
||||
assert.True(t, QuotaScans.RemoveUserQuotaScan(username))
|
||||
assert.False(t, QuotaScans.RemoveUserQuotaScan(username))
|
||||
assert.Len(t, QuotaScans.GetUsersQuotaScans(), 0)
|
||||
assert.Len(t, usersScans, 1)
|
||||
|
||||
folderName := "folder"
|
||||
assert.True(t, QuotaScans.AddVFolderQuotaScan(folderName))
|
||||
assert.False(t, QuotaScans.AddVFolderQuotaScan(folderName))
|
||||
if assert.Len(t, QuotaScans.GetVFoldersQuotaScans(), 1) {
|
||||
assert.Equal(t, QuotaScans.GetVFoldersQuotaScans()[0].Name, folderName)
|
||||
}
|
||||
|
||||
assert.True(t, QuotaScans.RemoveVFolderQuotaScan(folderName))
|
||||
assert.False(t, QuotaScans.RemoveVFolderQuotaScan(folderName))
|
||||
assert.Len(t, QuotaScans.GetVFoldersQuotaScans(), 0)
|
||||
}
|
||||
|
||||
func TestProxyProtocolVersion(t *testing.T) {
|
||||
c := Configuration{
|
||||
ProxyProtocol: 0,
|
||||
@@ -1044,6 +1016,110 @@ func TestUserRecentActivity(t *testing.T) {
|
||||
assert.True(t, res)
|
||||
}
|
||||
|
||||
func TestEventRuleMatch(t *testing.T) {
|
||||
conditions := dataprovider.EventConditions{
|
||||
ProviderEvents: []string{"add", "update"},
|
||||
Options: dataprovider.ConditionOptions{
|
||||
Names: []dataprovider.ConditionPattern{
|
||||
{
|
||||
Pattern: "user1",
|
||||
InverseMatch: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res := conditions.ProviderEventMatch(dataprovider.EventParams{
|
||||
Name: "user1",
|
||||
Event: "add",
|
||||
})
|
||||
assert.False(t, res)
|
||||
res = conditions.ProviderEventMatch(dataprovider.EventParams{
|
||||
Name: "user2",
|
||||
Event: "update",
|
||||
})
|
||||
assert.True(t, res)
|
||||
res = conditions.ProviderEventMatch(dataprovider.EventParams{
|
||||
Name: "user2",
|
||||
Event: "delete",
|
||||
})
|
||||
assert.False(t, res)
|
||||
conditions.Options.ProviderObjects = []string{"api_key"}
|
||||
res = conditions.ProviderEventMatch(dataprovider.EventParams{
|
||||
Name: "user2",
|
||||
Event: "update",
|
||||
ObjectType: "share",
|
||||
})
|
||||
assert.False(t, res)
|
||||
res = conditions.ProviderEventMatch(dataprovider.EventParams{
|
||||
Name: "user2",
|
||||
Event: "update",
|
||||
ObjectType: "api_key",
|
||||
})
|
||||
assert.True(t, res)
|
||||
// now test fs events
|
||||
conditions = dataprovider.EventConditions{
|
||||
FsEvents: []string{operationUpload, operationDownload},
|
||||
Options: dataprovider.ConditionOptions{
|
||||
Names: []dataprovider.ConditionPattern{
|
||||
{
|
||||
Pattern: "user*",
|
||||
},
|
||||
{
|
||||
Pattern: "tester*",
|
||||
},
|
||||
},
|
||||
FsPaths: []dataprovider.ConditionPattern{
|
||||
{
|
||||
Pattern: "*.txt",
|
||||
},
|
||||
},
|
||||
Protocols: []string{ProtocolSFTP},
|
||||
MinFileSize: 10,
|
||||
MaxFileSize: 30,
|
||||
},
|
||||
}
|
||||
params := dataprovider.EventParams{
|
||||
Name: "tester4",
|
||||
Event: operationDelete,
|
||||
VirtualPath: "/path.txt",
|
||||
Protocol: ProtocolSFTP,
|
||||
ObjectName: "path.txt",
|
||||
FileSize: 20,
|
||||
}
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.Event = operationDownload
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.True(t, res)
|
||||
params.Name = "name"
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.Name = "user5"
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.True(t, res)
|
||||
params.VirtualPath = "/sub/f.jpg"
|
||||
params.ObjectName = path.Base(params.VirtualPath)
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.VirtualPath = "/sub/f.txt"
|
||||
params.ObjectName = path.Base(params.VirtualPath)
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.True(t, res)
|
||||
params.Protocol = ProtocolHTTP
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.Protocol = ProtocolSFTP
|
||||
params.FileSize = 5
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.FileSize = 50
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.False(t, res)
|
||||
params.FileSize = 25
|
||||
res = conditions.FsEventMatch(params)
|
||||
assert.True(t, res)
|
||||
}
|
||||
|
||||
func BenchmarkBcryptHashing(b *testing.B) {
|
||||
bcryptPassword := "bcryptpassword"
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
Reference in New Issue
Block a user