Skip to content

Commit

Permalink
Merge pull request #114 from projectdiscovery/added-ipv6tests-fix-typo
Browse files Browse the repository at this point in the history
feat: added tests for ipv6 validation + fixed typo
  • Loading branch information
Ice3man543 authored Jan 10, 2025
2 parents 5a7657e + ea913dc commit d7a0102
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit d7a0102

Please sign in to comment.