allow to limit the number of per-host connections

This commit is contained in:
Nicola Murino
2021-05-08 19:45:21 +02:00
parent 8f736da4b8
commit 8f6cdacd00
21 changed files with 356 additions and 105 deletions

View File

@@ -747,7 +747,7 @@ func TestDefender(t *testing.T) {
cfg := config.GetCommonConfig()
cfg.DefenderConfig.Enabled = true
cfg.DefenderConfig.Threshold = 3
cfg.DefenderConfig.ScoreRateExceeded = 2
cfg.DefenderConfig.ScoreLimitExceeded = 2
err := common.Initialize(cfg)
assert.NoError(t, err)
@@ -934,6 +934,33 @@ func TestMaxConnections(t *testing.T) {
common.Config.MaxTotalConnections = oldValue
}
func TestMaxPerHostConnections(t *testing.T) {
oldValue := common.Config.MaxPerHostConnections
common.Config.MaxPerHostConnections = 1
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err)
client := getWebDavClient(user, true, nil)
assert.NoError(t, checkBasicFunc(client))
// now add a fake connection
addrs, err := net.LookupHost("localhost")
assert.NoError(t, err)
for _, addr := range addrs {
common.Connections.AddClientConnection(addr)
}
assert.Error(t, checkBasicFunc(client))
for _, addr := range addrs {
common.Connections.RemoveClientConnection(addr)
}
_, err = httpdtest.RemoveUser(user, http.StatusOK)
assert.NoError(t, err)
err = os.RemoveAll(user.GetHomeDir())
assert.NoError(t, err)
assert.Len(t, common.Connections.GetStats(), 0)
common.Config.MaxPerHostConnections = oldValue
}
func TestMaxSessions(t *testing.T) {
u := getTestUser()
u.MaxSessions = 1