Skip to content
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

feat: added tests for ipv6 validation + fixed typo #114

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func init() {
DefaultOptions.DenyList = append(DefaultOptions.DenyList, DefaultIPv4DenylistRanges...)
DefaultOptions.DenyList = append(DefaultOptions.DenyList, DefaultIPv6Denylist...)
DefaultOptions.DenyList = append(DefaultOptions.DenyList, DefaultIPv4DenylistRanges...)
DefaultOptions.DenyList = append(DefaultOptions.DenyList, DefaultIPv6DenylistRanges...)
DefaultOptions.DenyList = append(DefaultOptions.DenyList, DefaultIPv6Denylist...)
DefaultOptions.AllowSchemeList = append(DefaultOptions.DenyList, DefaultSchemeAllowList...)
}
Expand Down
18 changes: 18 additions & 0 deletions networkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ func TestValidateAddress(t *testing.T) {
require.Equal(t, true, ok, "Unexpected negative result")
}

func Test_ValidateV6Address(t *testing.T) {
np, err := New(DefaultOptions)
if err != nil {
log.Fatal(err)
}

ok := np.ValidateAddress("::1")
require.Equal(t, false, ok, "IPv6 localhost should be denied")

ok = np.ValidateAddress("2404:6800:4002:81c::200e")
require.Equal(t, true, ok, "Non-localhost IPv6 should be allowed")

t.Run("validate", func(t *testing.T) {
ok := np.Validate("::1")
require.Equal(t, false, ok, "IPv6 localhost should be denied")
})
}

func TestMultipleCases(t *testing.T) {
var testCases = []struct {
address string
Expand Down
Loading