* clients: manual clients don't exclude auto-clients anymore
This commit is contained in:
parent
995373c74b
commit
b3ddae7f85
|
@ -494,12 +494,6 @@ func (clients *clientsContainer) AddHost(ip, host string, source clientSource) (
|
||||||
clients.lock.Lock()
|
clients.lock.Lock()
|
||||||
defer clients.lock.Unlock()
|
defer clients.lock.Unlock()
|
||||||
|
|
||||||
// check existing clients first
|
|
||||||
_, ok := clients.findByIP(ip)
|
|
||||||
if ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// check auto-clients index
|
// check auto-clients index
|
||||||
ch, ok := clients.ipHost[ip]
|
ch, ok := clients.ipHost[ip]
|
||||||
if ok && ch.Source > source {
|
if ok && ch.Source > source {
|
||||||
|
|
|
@ -179,7 +179,7 @@ func TestClientsWhois(t *testing.T) {
|
||||||
_ = clients.Del("client1")
|
_ = clients.Del("client1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientsAddExistingHost(t *testing.T) {
|
func TestClientsAddExisting(t *testing.T) {
|
||||||
var c Client
|
var c Client
|
||||||
clients := clientsContainer{}
|
clients := clientsContainer{}
|
||||||
clients.testing = true
|
clients.testing = true
|
||||||
|
@ -198,9 +198,9 @@ func TestClientsAddExistingHost(t *testing.T) {
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// try adding a duplicate by IP
|
// add an auto-client with the same IP - it's allowed
|
||||||
ok, err = clients.AddHost("1.1.1.1", "test", ClientSourceRDNS)
|
ok, err = clients.AddHost("1.1.1.1", "test", ClientSourceRDNS)
|
||||||
assert.False(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// now some more complicated stuff
|
// now some more complicated stuff
|
||||||
|
@ -218,13 +218,21 @@ func TestClientsAddExistingHost(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// try adding a duplicate IP which for a Mac-based client
|
// add a new client with the same IP as for a client with MAC
|
||||||
ok, err = clients.AddHost(testIP, "test", ClientSourceRDNS)
|
c = Client{
|
||||||
assert.False(t, ok)
|
IDs: []string{testIP},
|
||||||
|
Name: "client2",
|
||||||
|
}
|
||||||
|
ok, err = clients.Add(c)
|
||||||
|
assert.True(t, ok)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// don't allow duplicates by CIDR
|
// add a new client with the IP from the client1's IP range
|
||||||
ok, err = clients.AddHost("2.2.2.2", "test", ClientSourceRDNS)
|
c = Client{
|
||||||
assert.False(t, ok)
|
IDs: []string{"2.2.2.2"},
|
||||||
|
Name: "client3",
|
||||||
|
}
|
||||||
|
ok, err = clients.Add(c)
|
||||||
|
assert.True(t, ok)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue