MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestWhitelistCheck

Function TestWhitelistCheck

pkg/parser/whitelist_test.go:73–298  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestWhitelistCheck(t *testing.T) {
74 node := &Node{
75 Logger: log.NewEntry(log.New()),
76 }
77 tests := []struct {
78 name string
79 whitelist Whitelist
80 event *pipeline.Event
81 expected bool
82 }{
83 {
84 name: "IP Whitelisted",
85 whitelist: Whitelist{
86 Reason: "test",
87 Ips: []string{
88 "127.0.0.1",
89 },
90 },
91 event: &pipeline.Event{
92 Meta: map[string]string{
93 "source_ip": "127.0.0.1",
94 },
95 },
96 expected: true,
97 },
98 {
99 name: "IP Not Whitelisted",
100 whitelist: Whitelist{
101 Reason: "test",
102 Ips: []string{
103 "127.0.0.1",
104 },
105 },
106 event: &pipeline.Event{
107 Meta: map[string]string{
108 "source_ip": "127.0.0.2",
109 },
110 },
111 },
112 {
113 name: "CIDR Whitelisted",
114 whitelist: Whitelist{
115 Reason: "test",
116 Cidrs: []string{
117 "127.0.0.1/32",
118 },
119 },
120 event: &pipeline.Event{
121 Meta: map[string]string{
122 "source_ip": "127.0.0.1",
123 },
124 },
125 expected: true,
126 },
127 {
128 name: "CIDR Not Whitelisted",
129 whitelist: Whitelist{
130 Reason: "test",

Callers

nothing calls this directly

Calls 4

CompileWLsMethod · 0.95
CheckIPsWLMethod · 0.95
CheckExprWLMethod · 0.95
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…