From b3ddae7f856ec4e798e7a0595ba1644b4b96e873 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Thu, 9 Jan 2020 17:38:22 +0300 Subject: [PATCH] * clients: manual clients don't exclude auto-clients anymore --- home/clients.go | 6 ------ home/clients_test.go | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/home/clients.go b/home/clients.go index 5fb1115b..65ce78e2 100644 --- a/home/clients.go +++ b/home/clients.go @@ -494,12 +494,6 @@ func (clients *clientsContainer) AddHost(ip, host string, source clientSource) ( clients.lock.Lock() defer clients.lock.Unlock() - // check existing clients first - _, ok := clients.findByIP(ip) - if ok { - return false, nil - } - // check auto-clients index ch, ok := clients.ipHost[ip] if ok && ch.Source > source { diff --git a/home/clients_test.go b/home/clients_test.go index 3315adb3..4468de35 100644 --- a/home/clients_test.go +++ b/home/clients_test.go @@ -179,7 +179,7 @@ func TestClientsWhois(t *testing.T) { _ = clients.Del("client1") } -func TestClientsAddExistingHost(t *testing.T) { +func TestClientsAddExisting(t *testing.T) { var c Client clients := clientsContainer{} clients.testing = true @@ -198,9 +198,9 @@ func TestClientsAddExistingHost(t *testing.T) { assert.True(t, ok) 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) - assert.False(t, ok) + assert.True(t, ok) assert.Nil(t, err) // now some more complicated stuff @@ -218,13 +218,21 @@ func TestClientsAddExistingHost(t *testing.T) { }) assert.Nil(t, err) - // try adding a duplicate IP which for a Mac-based client - ok, err = clients.AddHost(testIP, "test", ClientSourceRDNS) - assert.False(t, ok) + // add a new client with the same IP as for a client with MAC + c = Client{ + IDs: []string{testIP}, + Name: "client2", + } + ok, err = clients.Add(c) + assert.True(t, ok) assert.Nil(t, err) - // don't allow duplicates by CIDR - ok, err = clients.AddHost("2.2.2.2", "test", ClientSourceRDNS) - assert.False(t, ok) + // add a new client with the IP from the client1's IP range + c = Client{ + IDs: []string{"2.2.2.2"}, + Name: "client3", + } + ok, err = clients.Add(c) + assert.True(t, ok) assert.Nil(t, err) }