-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix address filtering for /ip6, add tests
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
- Loading branch information
Lars Gierth
committed
Apr 11, 2016
1 parent
9ce2eeb
commit 2b226b9
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package filter | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr" | ||
) | ||
|
||
func TestFilter(t *testing.T) { | ||
f := NewFilters() | ||
for _, cidr := range []string{ | ||
"1.2.3.0/24", | ||
"4.3.2.1/32", | ||
"fd00::/8", | ||
"fc00::1/128", | ||
} { | ||
_, ipnet, _ := net.ParseCIDR(cidr) | ||
f.AddDialFilter(ipnet) | ||
} | ||
|
||
for _, blocked := range []string{ | ||
"/ip4/1.2.3.4/tcp/123", | ||
"/ip4/4.3.2.1/udp/123", | ||
"/ip6/fd00::2/tcp/321", | ||
"/ip6/fc00::1/udp/321", | ||
} { | ||
maddr, err := ma.NewMultiaddr(blocked) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if !f.AddrBlocked(maddr) { | ||
t.Fatalf("expected %s to be blocked", blocked) | ||
} | ||
} | ||
|
||
for _, notBlocked := range []string{ | ||
"/ip4/1.2.4.1/tcp/123", | ||
"/ip4/4.3.2.2/udp/123", | ||
"/ip6/fe00::1/tcp/321", | ||
"/ip6/fc00::2/udp/321", | ||
} { | ||
maddr, err := ma.NewMultiaddr(notBlocked) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if f.AddrBlocked(maddr) { | ||
t.Fatalf("expected %s to not be blocked", notBlocked) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters