forked from wchan2/bloodhound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traffic_filters_test.go
64 lines (52 loc) · 1.49 KB
/
traffic_filters_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main_test
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/wchan2/bloodhound"
)
var _ = Describe(`HTTPTrafficFilter`, func() {
Describe(`#Filter`, func() {
var (
trafficFilter TrafficFilter
event Event
filtered bool
)
BeforeEach(func() {
trafficFilter = HTTPTrafficFilter
})
Context(`when a packet is a http request`, func() {
JustBeforeEach(func() {
packet := new(packetMock)
appLayer := new(appLayerMock)
appLayer.payload = []byte(sampleRequest)
packet.appLayer = appLayer
event, filtered = trafficFilter.Filter(packet)
})
It(`returns false to not be filtered`, func() {
Expect(filtered).To(BeFalse())
})
It(`returns a populated event with the current time`, func() {
Expect(event.Time).To(BeTemporally("<=", time.Now()))
})
It(`returns a populated event with the correct destination`, func() {
Expect(event.Destination).To(Equal("a.disquscdn.com/next/embed/alfie.f51946af45e0b561c60f768335c9eb79.js"))
})
})
Context(`when a packet is not a http request`, func() {
JustBeforeEach(func() {
packet := new(packetMock)
appLayer := new(appLayerMock)
appLayer.payload = []byte(`non-http request`)
packet.appLayer = appLayer
event, filtered = trafficFilter.Filter(packet)
})
It(`returns an empty event`, func() {
Expect(event).To(Equal(Event{}))
})
It(`returns true to be filtered`, func() {
Expect(filtered).To(BeTrue())
})
})
})
})