From 666b14d57cbe2aed9a47c221793041311872b871 Mon Sep 17 00:00:00 2001 From: Sonam Tenzin Date: Tue, 4 Feb 2025 10:59:14 +0530 Subject: [PATCH 1/5] Test workflow added and test fixes --- .github/workflows/build_test.yml | 21 +++ template/template_test.go | 267 +++++++++++++++++++++++++------ 2 files changed, 235 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/build_test.yml diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 000000000..0a1ccad0f --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,21 @@ +name: Build and Test Workflow + +on: + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Setup Go + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + with: + go-version: '1.19' + - name: Test Go + run: go test -v ./... + - name: Build Go + run: go build ./... \ No newline at end of file diff --git a/template/template_test.go b/template/template_test.go index ec9822e77..356ef8406 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -1,12 +1,173 @@ package template_test import ( + "net" "testing" + sockaddr "github.com/hashicorp/go-sockaddr" socktmpl "github.com/hashicorp/go-sockaddr/template" ) +func getInputList() []sockaddr.IfAddr { + interfaceList := []struct { + SockAddress string + Interface net.Interface + }{ + { + SockAddress: "127.0.0.1/8", + Interface: net.Interface{ + Index: 1, + MTU: 16384, + Name: "lo0", + HardwareAddr: []byte{}, + Flags: net.FlagUp | net.FlagLoopback | net.FlagMulticast, + }, + }, + { + SockAddress: "::1/128", + Interface: net.Interface{ + Index: 1, + MTU: 16384, + Name: "lo0", + HardwareAddr: []byte{}, + Flags: net.FlagUp | net.FlagLoopback | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::1/64", + Interface: net.Interface{ + Index: 1, + MTU: 16384, + Name: "lo0", + HardwareAddr: []byte{}, + Flags: net.FlagUp | net.FlagLoopback | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::603e:5fff:fe48:75ff/64", + Interface: net.Interface{ + Index: 14, + MTU: 1500, + Name: "ap1", + HardwareAddr: []byte{0x62, 0x3e, 0x5f, 0x48, 0x75, 0xff}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::2b:112f:ce21:7b6f/64", + Interface: net.Interface{ + Index: 15, + MTU: 1500, + Name: "en0", + HardwareAddr: []byte{0x60, 0x3e, 0x5f, 0x48, 0x75, 0xff}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "2406:7400:63:ef5:1415:8bc3:fa5e:2578/64", + Interface: net.Interface{ + Index: 15, + MTU: 1500, + Name: "en0", + HardwareAddr: []byte{0x60, 0x3e, 0x5f, 0x48, 0x75, 0xff}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "2406:7400:63:ef5:3c37:71a6:e3b4:b565/64", + Interface: net.Interface{ + Index: 15, + MTU: 1500, + Name: "en0", + HardwareAddr: []byte{0x60, 0x3e, 0x5f, 0x48, 0x75, 0xff}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "192.168.0.102/24", + Interface: net.Interface{ + Index: 15, + MTU: 1500, + Name: "en0", + HardwareAddr: []byte{0x60, 0x3e, 0x5f, 0x48, 0x75, 0xff}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::3871:85ff:fed8:aadc/64", + Interface: net.Interface{ + Index: 16, + MTU: 1500, + Name: "awdl0", + HardwareAddr: []byte{0x3a, 0x71, 0x85, 0xd8, 0xaa, 0xdc}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::3871:85ff:fed8:aadc/64", + Interface: net.Interface{ + Index: 17, + MTU: 1500, + Name: "llw0", + HardwareAddr: []byte{0x3a, 0x71, 0x85, 0xd8, 0xaa, 0xdc}, + Flags: net.FlagUp | net.FlagBroadcast | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::83f9:d7fb:f204:cee5/64", + Interface: net.Interface{ + Index: 18, + MTU: 1500, + Name: "utun0", + HardwareAddr: nil, + Flags: net.FlagUp | net.FlagPointToPoint | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::2023:8d30:551e:18d/64", + Interface: net.Interface{ + Index: 19, + MTU: 1380, + Name: "utun1", + HardwareAddr: nil, + Flags: net.FlagUp | net.FlagPointToPoint | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::f9c1:463:96e6:fa8a/64", + Interface: net.Interface{ + Index: 20, + MTU: 2000, + Name: "utun2", + HardwareAddr: nil, + Flags: net.FlagUp | net.FlagPointToPoint | net.FlagMulticast, + }, + }, + { + SockAddress: "fe80::ce81:b1c:bd2c:69e/64", + Interface: net.Interface{ + Index: 21, + MTU: 1000, + Name: "utun3", + HardwareAddr: nil, + Flags: net.FlagUp | net.FlagPointToPoint | net.FlagMulticast, + }, + }, + } + inputList := []sockaddr.IfAddr{} + for i := range interfaceList { + sockAddr, _ := sockaddr.NewIPAddr(interfaceList[i].SockAddress) + inputList = append(inputList, sockaddr.IfAddr{ + SockAddr: sockAddr, + Interface: interfaceList[i].Interface, + }) + } + + return inputList +} + func TestSockAddr_Parse(t *testing.T) { + tests := []struct { name string input string @@ -16,7 +177,7 @@ func TestSockAddr_Parse(t *testing.T) { }{ { name: `basic include "name"`, - input: `{{GetAllInterfaces | include "name" "lo0" | printf "%v"}}`, + input: `{{. | include "name" "lo0" | printf "%v"}}`, output: `[127.0.0.1/8 {1 16384 lo0 up|loopback|multicast} ::1 {1 16384 lo0 up|loopback|multicast} fe80::1/64 {1 16384 lo0 up|loopback|multicast}]`, }, { @@ -25,14 +186,14 @@ func TestSockAddr_Parse(t *testing.T) { output: ``, fail: true, }, - { - name: "GetDefaultInterface", - input: `{{GetDefaultInterfaces | include "type" "IPv4" | attr "name" }}`, - output: `en0`, - }, + // { + // name: "GetDefaultInterface", + // input: `{{GetDefaultInterfaces | include "type" "IPv4" | attr "name" }}`, + // output: `en0`, + // }, { name: `include "name" regexp`, - input: `{{GetAllInterfaces | include "name" "^(en|lo)0$" | exclude "name" "^en0$" | sort "type" | sort "address" | join "address" " " }}`, + input: `{{. | include "name" "^(en|lo)0$" | exclude "name" "^en0$" | sort "type" | sort "address" | join "address" " " }}`, output: `127.0.0.1 ::1 fe80::1`, }, { @@ -167,46 +328,46 @@ func TestSockAddr_Parse(t *testing.T) { input: `{{. | include "name" "lo0" | include "flag" "up" | sort "-type,+address" | attr "address" }}`, output: `::1`, }, - { - // NOTE(sean@): This is the HashiCorp default in 2016. - // Indented for effect. Using "true" as the output - // instead of printing the correct $rfc*Addrs values. - name: "HashiCorpDefault2016", - input: ` -{{- with $addr := GetAllInterfaces | include "type" "IP" | include "rfc" "1918|6598" | sort "address" | attr "address" -}} + // { + // // NOTE(sean@): This is the HashiCorp default in 2016. + // // Indented for effect. Using "true" as the output + // // instead of printing the correct $rfc*Addrs values. + // name: "HashiCorpDefault2016", + // input: ` + // {{- with $addr := . | include "type" "IP" | include "rfc" "1918|6598" | sort "address" | attr "address" -}} - {{- if ($addr | len) gt 0 -}} - {{- print "true" -}}{{/* print $addr*/ -}} - {{- end -}} -{{- end -}}`, - output: `true`, - }, + // {{- if ($addr | len) gt 0 -}} + // {{- print "true" -}}{{/* print $addr*/ -}} + // {{- end -}} + // {{- end -}}`, + // output: `true`, + // }, { name: "math address +", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+2" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "address" "+2" | sort "+type,+address" | join "address" " " }}`, output: `127.0.0.3 ::3 fe80::3`, }, { name: "math address + overflow", - input: `|{{- with $ifAddrs := GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+16777217" | sort "+type,+address" -}} - {{- range $ifAddrs -}} - {{- attr "address" . }} -- {{ attr "network" . }}/{{ attr "size" . }}|{{ end -}} -{{- end -}}`, + input: `|{{- with $ifAddrs := . | include "name" "^lo0$" | include "type" "IP" | math "address" "+16777217" | sort "+type,+address" -}} + {{- range $ifAddrs -}} + {{- attr "address" . }} -- {{ attr "network" . }}/{{ attr "size" . }}|{{ end -}} + {{- end -}}`, output: `|128.0.0.2 -- 128.0.0.0/16777216|::100:2 -- ::100:2/1|fe80::100:2 -- fe80::/18446744073709551616|`, }, { name: "math address + overflow+wrap", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "+4294967294" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "address" "+4294967294" | sort "+type,+address" | join "address" " " }}`, output: `126.255.255.255 ::ffff:ffff fe80::ffff:ffff`, }, { name: "math address -", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "-256" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "address" "-256" | sort "+type,+address" | join "address" " " }}`, output: `126.255.255.1 fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ff01 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff01`, }, { name: "math address - underflow", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "address" "-4278190082" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "address" "-4278190082" | sort "+type,+address" | join "address" " " }}`, output: `127.255.255.255 fe7f:ffff:ffff:ffff:ffff:ffff:ff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ff:ffff`, }, { @@ -214,18 +375,18 @@ func TestSockAddr_Parse(t *testing.T) { // /128 which means its value never changes and this is expected. lo0's // site-local address has a /64 address and is expected to change. name: "math network", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "+2" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "network" "+2" | sort "+type,+address" | join "address" " " }}`, output: `127.0.0.2 ::1 fe80::2`, }, { // Assume an IPv4 input of 127.0.0.1. With a value of 0xff00ff01, we wrap once on purpose. name: "math network + wrap", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "+4278255368" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "network" "+4278255368" | sort "+type,+address" | join "address" " " }}`, output: `127.0.255.8 ::1 fe80::ff00:ff08`, }, { name: "math network -", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | math "network" "-2" | sort "+type,+address" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "network" "-2" | sort "+type,+address" | join "address" " " }}`, output: `127.255.255.254 ::1 fe80::ffff:ffff:ffff:fffe`, }, { @@ -233,29 +394,29 @@ func TestSockAddr_Parse(t *testing.T) { // should wrap and underflow by 8. Assume an IPv6 input of ::1. With a // value of -0xff000008 the value underflows and wraps. name: "math network - underflow+wrap", - input: `{{GetAllInterfaces | include "name" "^lo0$" | include "type" "IP" | sort "+type,+address" | math "network" "-4278190088" | join "address" " " }}`, + input: `{{. | include "name" "^lo0$" | include "type" "IP" | sort "+type,+address" | math "network" "-4278190088" | join "address" " " }}`, output: `127.255.255.248 ::1 fe80::ffff:ffff:ff:fff8`, }, - { - // Assume the private IPs available on the host are: 10.1.2.3 - // fe80::1025:f732:1001:203 - name: "GetPrivateIPs", - input: `{{GetPrivateIPs}}`, - output: `10.1.2.3 fe80::1025:f732:1001:203`, - }, - { - // Assume the public IPs available on the host are: 1.2.3.4 6.7.8.9 - name: "GetPublicIPs", - input: `{{GetPublicIPs}}`, - output: `1.2.3.4 6.7.8.9`, - }, - { - // Assume the private IPs on this host are just the IPv4 addresses: - // 10.1.2.3 and 172.16.4.6 - name: "GetInterfaceIPs", - input: `{{GetInterfaceIPs "en0"}}`, - output: `10.1.2.3 and 172.16.4.6`, - }, + // { + // // Assume the private IPs available on the host are: 10.1.2.3 + // // fe80::1025:f732:1001:203 + // name: "GetPrivateIPs", + // input: `{{GetPrivateIPs}}`, + // output: `10.1.2.3 fe80::1025:f732:1001:203`, + // }, + // { + // // Assume the public IPs available on the host are: 1.2.3.4 6.7.8.9 + // name: "GetPublicIPs", + // input: `{{GetPublicIPs}}`, + // output: `1.2.3.4 6.7.8.9`, + // }, + // { + // // Assume the private IPs on this host are just the IPv4 addresses: + // // 10.1.2.3 and 172.16.4.6 + // name: "GetInterfaceIPs", + // input: `{{GetInterfaceIPs "en0"}}`, + // output: `10.1.2.3 and 172.16.4.6`, + // }, } for i, test := range tests { @@ -265,7 +426,7 @@ func TestSockAddr_Parse(t *testing.T) { } t.Run(test.name, func(t *testing.T) { t.Parallel() - out, err := socktmpl.Parse(test.input) + out, err := socktmpl.ParseIfAddrs(test.input, getInputList()) if err != nil && !test.fail { t.Fatalf("%q: bad: %v", test.name, err) } From 66c72a038193930e6bf4fc02a2a71acc7e6eb980 Mon Sep 17 00:00:00 2001 From: Sonam Tenzin Date: Tue, 4 Feb 2025 11:04:15 +0530 Subject: [PATCH 2/5] Fixed security vulnerablilities --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5232e9cc3..33ea4988a 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,6 @@ require ( github.com/posener/complete v1.1.1 // indirect github.com/shopspring/decimal v1.2.0 // indirect github.com/spf13/cast v1.3.1 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/crypto v0.32.0 // indirect + golang.org/x/sys v0.29.0 // indirect ) diff --git a/go.sum b/go.sum index 00d76d9fc..618997ca9 100644 --- a/go.sum +++ b/go.sum @@ -61,15 +61,15 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 0d807b7cdd610544b9cf50713f576a42006e9581 Mon Sep 17 00:00:00 2001 From: Sonam Tenzin Date: Thu, 13 Feb 2025 11:44:57 +0530 Subject: [PATCH 3/5] resolved comments --- .github/workflows/build_test.yml | 13 +++++++-- ifaddrs_test.go | 3 +- template/template_test.go | 49 ++------------------------------ 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 0a1ccad0f..1f1b53d00 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -7,14 +7,23 @@ on: jobs: build: runs-on: ubuntu-latest - + strategy: + fail-fast: false + max-parallel: 30 + matrix: + version: + - '1.19' + - '1.20' + - '1.21' + - '1.22' + - '1.23' steps: - name: Checkout Code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Setup Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.19' + go-version: ${{ matrix.version }} - name: Test Go run: go test -v ./... - name: Build Go diff --git a/ifaddrs_test.go b/ifaddrs_test.go index c89af4a05..68a47e75d 100644 --- a/ifaddrs_test.go +++ b/ifaddrs_test.go @@ -5,6 +5,7 @@ import ( "net" "reflect" "runtime" + "strings" "testing" sockaddr "github.com/hashicorp/go-sockaddr" @@ -632,7 +633,7 @@ func TestGetIfAddrs(t *testing.T) { t.Fatalf("No loopback interfaces found, loInt nil") } - if val := sockaddr.IfAddrAttr(*loInt, "flags"); !(val == "up|loopback|multicast" || val == "up|loopback") { + if val := sockaddr.IfAddrAttr(*loInt, "flags"); !strings.Contains(val, "up|loopback") { t.Fatalf("expected different flags from loopback: %q", val) } diff --git a/template/template_test.go b/template/template_test.go index 356ef8406..595a3e989 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -8,7 +8,8 @@ import ( socktmpl "github.com/hashicorp/go-sockaddr/template" ) -func getInputList() []sockaddr.IfAddr { +func TestSockAddr_Parse(t *testing.T) { + interfaceList := []struct { SockAddress string Interface net.Interface @@ -163,11 +164,6 @@ func getInputList() []sockaddr.IfAddr { }) } - return inputList -} - -func TestSockAddr_Parse(t *testing.T) { - tests := []struct { name string input string @@ -186,11 +182,6 @@ func TestSockAddr_Parse(t *testing.T) { output: ``, fail: true, }, - // { - // name: "GetDefaultInterface", - // input: `{{GetDefaultInterfaces | include "type" "IPv4" | attr "name" }}`, - // output: `en0`, - // }, { name: `include "name" regexp`, input: `{{. | include "name" "^(en|lo)0$" | exclude "name" "^en0$" | sort "type" | sort "address" | join "address" " " }}`, @@ -328,20 +319,6 @@ func TestSockAddr_Parse(t *testing.T) { input: `{{. | include "name" "lo0" | include "flag" "up" | sort "-type,+address" | attr "address" }}`, output: `::1`, }, - // { - // // NOTE(sean@): This is the HashiCorp default in 2016. - // // Indented for effect. Using "true" as the output - // // instead of printing the correct $rfc*Addrs values. - // name: "HashiCorpDefault2016", - // input: ` - // {{- with $addr := . | include "type" "IP" | include "rfc" "1918|6598" | sort "address" | attr "address" -}} - - // {{- if ($addr | len) gt 0 -}} - // {{- print "true" -}}{{/* print $addr*/ -}} - // {{- end -}} - // {{- end -}}`, - // output: `true`, - // }, { name: "math address +", input: `{{. | include "name" "^lo0$" | include "type" "IP" | math "address" "+2" | sort "+type,+address" | join "address" " " }}`, @@ -397,26 +374,6 @@ func TestSockAddr_Parse(t *testing.T) { input: `{{. | include "name" "^lo0$" | include "type" "IP" | sort "+type,+address" | math "network" "-4278190088" | join "address" " " }}`, output: `127.255.255.248 ::1 fe80::ffff:ffff:ff:fff8`, }, - // { - // // Assume the private IPs available on the host are: 10.1.2.3 - // // fe80::1025:f732:1001:203 - // name: "GetPrivateIPs", - // input: `{{GetPrivateIPs}}`, - // output: `10.1.2.3 fe80::1025:f732:1001:203`, - // }, - // { - // // Assume the public IPs available on the host are: 1.2.3.4 6.7.8.9 - // name: "GetPublicIPs", - // input: `{{GetPublicIPs}}`, - // output: `1.2.3.4 6.7.8.9`, - // }, - // { - // // Assume the private IPs on this host are just the IPv4 addresses: - // // 10.1.2.3 and 172.16.4.6 - // name: "GetInterfaceIPs", - // input: `{{GetInterfaceIPs "en0"}}`, - // output: `10.1.2.3 and 172.16.4.6`, - // }, } for i, test := range tests { @@ -426,7 +383,7 @@ func TestSockAddr_Parse(t *testing.T) { } t.Run(test.name, func(t *testing.T) { t.Parallel() - out, err := socktmpl.ParseIfAddrs(test.input, getInputList()) + out, err := socktmpl.ParseIfAddrs(test.input, inputList) if err != nil && !test.fail { t.Fatalf("%q: bad: %v", test.name, err) } From 1a0b66f00d7b355e044bf77a66eb8468110a89b9 Mon Sep 17 00:00:00 2001 From: Sonam Tenzin Date: Fri, 14 Feb 2025 12:55:41 +0530 Subject: [PATCH 4/5] resolved comments --- .github/workflows/build_test.yml | 7 ++----- go.mod | 2 +- ifaddrs_test.go | 5 +++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 1f1b53d00..77282e4c4 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -12,11 +12,8 @@ jobs: max-parallel: 30 matrix: version: - - '1.19' - - '1.20' - - '1.21' - - '1.22' - - '1.23' + - 'oldstable' + - 'stable' steps: - name: Checkout Code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 diff --git a/go.mod b/go.mod index 33ea4988a..672e51366 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/go-sockaddr -go 1.19 +go 1.23 require ( github.com/hashicorp/errwrap v1.1.0 diff --git a/ifaddrs_test.go b/ifaddrs_test.go index 68a47e75d..b15e98c2e 100644 --- a/ifaddrs_test.go +++ b/ifaddrs_test.go @@ -5,7 +5,6 @@ import ( "net" "reflect" "runtime" - "strings" "testing" sockaddr "github.com/hashicorp/go-sockaddr" @@ -633,7 +632,9 @@ func TestGetIfAddrs(t *testing.T) { t.Fatalf("No loopback interfaces found, loInt nil") } - if val := sockaddr.IfAddrAttr(*loInt, "flags"); !strings.Contains(val, "up|loopback") { + if val := sockaddr.IfAddrAttr(*loInt, "flags"); !(val == "up|loopback|multicast" || + val == "up|loopback" || + val == "up|loopback|multicast|running") { t.Fatalf("expected different flags from loopback: %q", val) } From f431d59e3c6cc2bde0a682006983076c0a831f57 Mon Sep 17 00:00:00 2001 From: Sonam Tenzin Date: Fri, 14 Feb 2025 13:30:21 +0530 Subject: [PATCH 5/5] test fixes --- ifaddrs_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ifaddrs_test.go b/ifaddrs_test.go index b15e98c2e..fa2fd838a 100644 --- a/ifaddrs_test.go +++ b/ifaddrs_test.go @@ -634,7 +634,8 @@ func TestGetIfAddrs(t *testing.T) { if val := sockaddr.IfAddrAttr(*loInt, "flags"); !(val == "up|loopback|multicast" || val == "up|loopback" || - val == "up|loopback|multicast|running") { + val == "up|loopback|multicast|running" || + val == "up|loopback|running") { t.Fatalf("expected different flags from loopback: %q", val) }