-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4cfadb
commit 3625435
Showing
3 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package goaway2 | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
/***Variables***/ | ||
var cache = NewRedBlackTree() | ||
var kv = NewRedBlackKV() | ||
|
||
/***Benchmarks***/ | ||
|
||
func BenchmarkCache(b *testing.B) { | ||
var i int64 | ||
for i = 0; i < int64(b.N); i++ { | ||
key := strconv.FormatInt(i, 10) | ||
cache.Set(kv, key, "fuck my shit") | ||
} | ||
} | ||
|
||
/***Tests***/ |
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,30 @@ | ||
package goaway2 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
netfilter "github.com/AkihiroSuda/go-netfilter-queue" | ||
) | ||
|
||
func TestFirewallHandler(t *testing.T) { | ||
fw := NewFirewall() | ||
// check if outbound dns packet is dropped | ||
if fw.checkRules(&PacketData{ | ||
SrcIP: "192.168.200.114", | ||
SrcPort: 10048, | ||
DstIP: "8.8.8.8", | ||
DstPort: 53, | ||
}) == netfilter.NF_DROP { | ||
fmt.Println("Packet #1 Dropped") | ||
} | ||
// check if inbound dns packet response is dropped | ||
if fw.checkRules(&PacketData{ | ||
SrcIP: "8.8.8.8", | ||
SrcPort: 53, | ||
DstIP: "192.168.200.114", | ||
DstPort: 10048, | ||
}) == netfilter.NF_DROP { | ||
fmt.Println("Packet #2 Dropped") | ||
} | ||
} |
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,53 @@ | ||
package goaway2 | ||
|
||
import "testing" | ||
|
||
/***Variables***/ | ||
|
||
var exampleRule = &fwRule{ | ||
Zone: zone("any"), | ||
SrcIP: convertIPs("192.168.200.114"), | ||
SrcPort: convertPorts("any"), | ||
DstIP: convertIPs("8.8.8.8"), | ||
DstPort: convertPorts("53"), | ||
} | ||
var examplePktData = &PacketData{ | ||
SrcIP: "192.168.200.114", | ||
SrcPort: 10048, | ||
DstIP: "8.8.8.8", | ||
DstPort: 53, | ||
} | ||
|
||
/***Benchmarks***/ | ||
|
||
func BenchmarkRuleValidate(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
exampleRule.Validate(examplePktData) | ||
} | ||
} | ||
|
||
func BenchmarkZoneValidate(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
exampleRule.Zone.Validate(examplePktData.SrcIP) | ||
} | ||
} | ||
|
||
func BenchmarkIPValidate(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
exampleRule.SrcIP.Validate(examplePktData.SrcIP) | ||
} | ||
} | ||
|
||
func BenchmarkPortValidate(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
exampleRule.SrcPort.Validate(examplePktData.SrcPort) | ||
} | ||
} | ||
|
||
/***Unit-Tests***/ | ||
|
||
func TestRuleVerification(t *testing.T) { | ||
if !exampleRule.Validate(examplePktData) { | ||
t.Fatalf("Unable to validate packet against rule!\n") | ||
} | ||
} |