summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_prefixdelegation_test.go
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2019-12-28 04:05:29 -0800
committerChris K <c@chrisko.ch>2020-03-11 13:52:51 -0700
commit4d26b5e0b42f27fa41d872b15a7d2bc867787975 (patch)
tree08b8a584619b1ba4d1245fc1c0c8a184e193fdef /dhcpv6/option_prefixdelegation_test.go
parent6469ef2f3d85469f0f7cbf3cb40c2f931e406397 (diff)
v6: rename IAPD option to be shorter
Also removes superfluous GetOne/Del proxy functions. Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/option_prefixdelegation_test.go')
-rw-r--r--dhcpv6/option_prefixdelegation_test.go164
1 files changed, 0 insertions, 164 deletions
diff --git a/dhcpv6/option_prefixdelegation_test.go b/dhcpv6/option_prefixdelegation_test.go
deleted file mode 100644
index 1fff283..0000000
--- a/dhcpv6/option_prefixdelegation_test.go
+++ /dev/null
@@ -1,164 +0,0 @@
-package dhcpv6
-
-import (
- "net"
- "testing"
- "time"
-
- "github.com/stretchr/testify/require"
-)
-
-func TestOptIAForPrefixDelegationParseOptIAForPrefixDelegation(t *testing.T) {
- data := []byte{
- 1, 0, 0, 0, // IAID
- 0, 0, 0, 1, // T1
- 0, 0, 0, 2, // T2
- 0, 26, 0, 25, // 26 = IAPrefix Option, 25 = length
- 0xaa, 0xbb, 0xcc, 0xdd, // IAPrefix preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // IAPrefix validLifetime
- 36, // IAPrefix prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // IAPrefix ipv6Prefix
- }
- opt, err := ParseOptIAForPrefixDelegation(data)
- require.NoError(t, err)
- require.Equal(t, OptionIAPD, opt.Code())
- require.Equal(t, [4]byte{1, 0, 0, 0}, opt.IaId)
- require.Equal(t, time.Second, opt.T1)
- require.Equal(t, 2*time.Second, opt.T2)
-}
-
-func TestOptIAForPrefixDelegationParseOptIAForPrefixDelegationInvalidLength(t *testing.T) {
- data := []byte{
- 1, 0, 0, 0, // IAID
- 0, 0, 0, 1, // T1
- // truncated from here
- }
- _, err := ParseOptIAForPrefixDelegation(data)
- require.Error(t, err)
-}
-
-func TestOptIAForPrefixDelegationParseOptIAForPrefixDelegationInvalidOptions(t *testing.T) {
- data := []byte{
- 1, 0, 0, 0, // IAID
- 0, 0, 0, 1, // T1
- 0, 0, 0, 2, // T2
- 0, 26, 0, 25, // 26 = IAPrefix Option, 25 = length
- 0xaa, 0xbb, 0xcc, 0xdd, // IAPrefix preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // IAPrefix validLifetime
- 36, // IAPrefix prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // IAPrefix ipv6Prefix missing last byte
- }
- _, err := ParseOptIAForPrefixDelegation(data)
- require.Error(t, err)
-}
-
-func TestOptIAForPrefixDelegationGetOneOption(t *testing.T) {
- buf := []byte{
- 0xaa, 0xbb, 0xcc, 0xdd, // preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // validLifetime
- 36, // prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // ipv6Prefix
- }
- oaddr, err := ParseOptIAPrefix(buf)
- if err != nil {
- t.Fatal(err)
- }
- opt := OptIAForPrefixDelegation{}
- opt.Options = append(opt.Options, oaddr)
- require.Equal(t, oaddr, opt.GetOneOption(OptionIAPrefix))
-}
-
-func TestOptIAForPrefixDelegationGetOneOptionMissingOpt(t *testing.T) {
- buf := []byte{
- 0xaa, 0xbb, 0xcc, 0xdd, // preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // validLifetime
- 36, // prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // ipv6Prefix
- }
- oaddr, err := ParseOptIAPrefix(buf)
- if err != nil {
- t.Fatal(err)
- }
- opt := OptIAForPrefixDelegation{}
- opt.Options = append(opt.Options, oaddr)
- require.Equal(t, nil, opt.GetOneOption(OptionDNSRecursiveNameServer))
-}
-
-func TestOptIAForPrefixDelegationDelOption(t *testing.T) {
- optiana1 := OptIAForPrefixDelegation{}
- optiana2 := OptIAForPrefixDelegation{}
- optiaaddr := OptIAPrefix{}
- optsc := OptStatusCode{}
-
- optiana1.Options = append(optiana1.Options, &optsc)
- optiana1.Options = append(optiana1.Options, &optiaaddr)
- optiana1.Options = append(optiana1.Options, &optiaaddr)
- optiana1.DelOption(OptionIAPrefix)
- require.Equal(t, len(optiana1.Options), 1)
- require.Equal(t, optiana1.Options[0], &optsc)
-
- optiana2.Options = append(optiana2.Options, &optiaaddr)
- optiana2.Options = append(optiana2.Options, &optsc)
- optiana2.Options = append(optiana2.Options, &optiaaddr)
- optiana2.DelOption(OptionIAPrefix)
- require.Equal(t, len(optiana2.Options), 1)
- require.Equal(t, optiana2.Options[0], &optsc)
-}
-
-func TestOptIAForPrefixDelegationToBytes(t *testing.T) {
- oaddr := OptIAPrefix{}
- oaddr.PreferredLifetime = 0xaabbccdd * time.Second
- oaddr.ValidLifetime = 0xeeff0011 * time.Second
- oaddr.SetPrefixLength(36)
- oaddr.SetIPv6Prefix(net.IPv6loopback)
-
- opt := OptIAForPrefixDelegation{}
- opt.IaId = [4]byte{1, 2, 3, 4}
- opt.T1 = 12345 * time.Second
- opt.T2 = 54321 * time.Second
- opt.Options = append(opt.Options, &oaddr)
-
- expected := []byte{
- 1, 2, 3, 4, // IA ID
- 0, 0, 0x30, 0x39, // T1 = 12345
- 0, 0, 0xd4, 0x31, // T2 = 54321
- 0, 26, 0, 25, // 26 = IAPrefix Option, 25 = length
- 0xaa, 0xbb, 0xcc, 0xdd, // IAPrefix preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // IAPrefix validLifetime
- 36, // IAPrefix prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // IAPrefix ipv6Prefix
- }
- require.Equal(t, expected, opt.ToBytes())
-}
-
-func TestOptIAForPrefixDelegationString(t *testing.T) {
- data := []byte{
- 1, 0, 0, 0, // IAID
- 0, 0, 0, 1, // T1
- 0, 0, 0, 2, // T2
- 0, 26, 0, 25, // 26 = IAPrefix Option, 25 = length
- 0xaa, 0xbb, 0xcc, 0xdd, // IAPrefix preferredLifetime
- 0xee, 0xff, 0x00, 0x11, // IAPrefix validLifetime
- 36, // IAPrefix prefixLength
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // IAPrefix ipv6Prefix
- }
- opt, err := ParseOptIAForPrefixDelegation(data)
- require.NoError(t, err)
-
- str := opt.String()
- require.Contains(
- t, str,
- "IAID=[1 0 0 0]",
- "String() should return the IAID",
- )
- require.Contains(
- t, str,
- "t1=1s, t2=2s",
- "String() should return the T1/T2 options",
- )
- require.Contains(
- t, str,
- "options=[",
- "String() should return a list of options",
- )
-}