-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added test workflow for PR and upgraded dependencies #76
base: master
Are you sure you want to change the base?
Conversation
61bb7c6
to
0b4bdf0
Compare
ipaddrs.go
Outdated
@@ -67,9 +67,12 @@ func (s SortIPAddrsByNetworkSize) Less(i, j int) bool { | |||
// that have a port (e.g. a host with a /32 and port number is more | |||
// specific and should sort first over a host with a /32 but no port | |||
// set). | |||
if s.IPAddrs[i].IPPort() == 0 || s.IPAddrs[j].IPPort() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is currently incorrectly sorting for scenarios like these -
If we get an order like this, it will return false maintaining that 1>2
- 128.95.120.2:8600
- 128.95.120.2
And if we get input like this, it will still return 1>2
- 128.95.120.2
- 128.95.120.2:8600
It is essentially not sorting for these scenarios. The test TestSockAddr_IPAddrs_IPAddrsByNetworkSize
was failing because of the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note here, proposal to fix this has been in #50 since two years ago. It also includes an explanation why this became an issue with Go 1.19 onwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR will anyways need some changes to go through, I will merge #50 and take a rebase from master to incorporate the fix
cc: @schmichael
template/template_test.go
Outdated
input: `{{GetDefaultInterfaces | include "type" "IPv4" | attr "name" }}`, | ||
output: `en0`, | ||
}, | ||
// { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented out these tests because they are dependent on underlying interfaces of the machine, which may change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds reasonable to me, but maybe just remove the test?
@@ -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"}}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this from GetAllInterfaces
because this caused the test to depend on underlying machine interfaces. We are not getting mock input from getInputList
method
template/template_test.go
Outdated
@@ -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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to include mocked interfaces. Parse
is essentially calling ParseIfAddrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a function that gets called in each test, can we not just create this list once at the top of this test function and then use the value in all the test? Does ParseIfAddrs
mutate the input? If so, could we instead create a copy of the list in each test with copy
? I think I'd prefer not to have this helper function defined at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, removed the function and replaced with a list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, the security vulnerability fix is just the mod update, and I'm guessing you decided to fix the tests because they were failing on your machine? I think that makes sense. I added some comments, let me know what you think!
.github/workflows/build_test.yml
Outdated
- name: Setup Go | ||
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a | ||
with: | ||
go-version: '1.19' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an ancient release. I see that the go.mod
says 1.19, but that just means it's the oldest version supported. We should probably use a matrix here, including 1.19, 1.20, 1.21, 1.22 and 1.23. See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#using-a-matrix-strategy if you're unsure how to create a matrix strategy.
Also CC @schmichael, what is this repositories Go compatibility policy? I'd probably suggest we update the go
directive to 1.22 and use the same policy as the Go team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. This repo doesn't need special treatment. It's just been stable/neglected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a matrix for testing on different versions
template/template_test.go
Outdated
input: `{{GetDefaultInterfaces | include "type" "IPv4" | attr "name" }}`, | ||
output: `en0`, | ||
}, | ||
// { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds reasonable to me, but maybe just remove the test?
template/template_test.go
Outdated
// { | ||
// // 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`, | ||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this test also not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above I'm +1 for removing ancient tests as opposed to commenting them out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is currently failing, so removed it
template/template_test.go
Outdated
// { | ||
// // 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`, | ||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these
template/template_test.go
Outdated
@@ -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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a function that gets called in each test, can we not just create this list once at the top of this test function and then use the value in all the test? Does ParseIfAddrs
mutate the input? If so, could we instead create a copy of the list in each test with copy
? I think I'd prefer not to have this helper function defined at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @johanbrandhorst's comments about bumping Go and dropping commented out tests.
Logic fix looks good.
Can we update the title and description to drop the security vulnerabilities
reference or at least clarify it's a vulnerability in a dependency that is unused by go-sockaddr. go-sockaddr does not have a vulnerability, and I would hate people (or security scanners) to flag the wrong package!
Please correct me if I'm missing something.
template/template_test.go
Outdated
// { | ||
// // 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`, | ||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above I'm +1 for removing ancient tests as opposed to commenting them out.
This will supersede and close #50. Many apologies for missing the opportunity to merge that one! |
1791c24
to
66c72a0
Compare
@@ -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") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed? This isn't the same behavior anymore.
- '1.19' | ||
- '1.20' | ||
- '1.21' | ||
- '1.22' | ||
- '1.23' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this a little more future proof, we can use the stable
and oldstable
aliases to use the current and the previous release for this.
- '1.19' | |
- '1.20' | |
- '1.21' | |
- '1.22' | |
- '1.23' | |
- 'oldstable' | |
- 'stable' |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also change the go
stanza at the top of the file to 1.23
?
Description