Pull request: dhcpd: fix interface ipv6 check
Merge in DNS/adguard-home from 2355-dhcpcheck-ipv6 to master Updates #2335. Squashed commit of the following: commit 5ce1cc7bc244ba5dd4a065d47dec8884fa3d45e7 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Nov 25 14:03:24 2020 +0300 dhcpd: fix loop exit condition commit 32b4b946bfa30159326dc295fa1a2607b78172af Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Nov 25 13:26:50 2020 +0300 dhcpd: fix interface ipv6 check
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
||||
"github.com/insomniacslk/dhcp/dhcpv6"
|
||||
"github.com/insomniacslk/dhcp/iana"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -223,3 +224,57 @@ func TestV6GetDynamicLease(t *testing.T) {
|
||||
assert.True(t, ip6InRange(net.ParseIP("2001::2"), net.ParseIP("2001::2")))
|
||||
assert.True(t, ip6InRange(net.ParseIP("2001::2"), net.ParseIP("2001::3")))
|
||||
}
|
||||
|
||||
type fakeIface struct {
|
||||
addrs []net.Addr
|
||||
err error
|
||||
}
|
||||
|
||||
// Addrs implements the netIface interface for *fakeIface.
|
||||
func (iface *fakeIface) Addrs() (addrs []net.Addr, err error) {
|
||||
if iface.err != nil {
|
||||
return nil, iface.err
|
||||
}
|
||||
|
||||
return iface.addrs, nil
|
||||
}
|
||||
|
||||
func TestIfaceIPv6Addrs(t *testing.T) {
|
||||
ip := net.IP{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}
|
||||
ip4 := net.IP{1, 2, 3, 4}
|
||||
addr := &net.IPNet{IP: ip}
|
||||
errTest := agherr.Error("test error")
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
iface netIface
|
||||
want []net.IP
|
||||
wantErr error
|
||||
}{{
|
||||
name: "success",
|
||||
iface: &fakeIface{addrs: []net.Addr{addr}, err: nil},
|
||||
want: []net.IP{ip},
|
||||
wantErr: nil,
|
||||
}, {
|
||||
name: "success_with_ipv4",
|
||||
iface: &fakeIface{
|
||||
addrs: []net.Addr{addr, &net.IPNet{IP: ip4}},
|
||||
err: nil,
|
||||
},
|
||||
want: []net.IP{ip},
|
||||
wantErr: nil,
|
||||
}, {
|
||||
name: "error",
|
||||
iface: &fakeIface{addrs: []net.Addr{addr}, err: errTest},
|
||||
want: nil,
|
||||
wantErr: errTest,
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, gotErr := ifaceIPv6Addrs(tc.iface)
|
||||
assert.Equal(t, tc.want, got)
|
||||
assert.Equal(t, tc.wantErr, gotErr)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user