MCPcopy
hub / github.com/TecharoHQ/anubis / TestBotEnvironment

Function TestBotEnvironment

lib/policy/expressions/environment_test.go:24–592  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestBotEnvironment(t *testing.T) {
25 dnsObj := newTestDNS(300, 300)
26 env, err := BotEnvironment(dnsObj)
27 if err != nil {
28 t.Fatalf("failed to create bot environment: %v", err)
29 }
30
31 t.Run("missingHeader", func(t *testing.T) {
32 tests := []struct {
33 headers map[string]string
34 name string
35 expression string
36 description string
37 expected types.Bool
38 }{
39 {
40 name: "missing-header",
41 expression: `missingHeader(headers, "Missing-Header")`,
42 headers: map[string]string{
43 "User-Agent": "test-agent",
44 "Content-Type": "application/json",
45 },
46 expected: types.Bool(true),
47 description: "should return true when header is missing",
48 },
49 {
50 name: "existing-header",
51 expression: `missingHeader(headers, "User-Agent")`,
52 headers: map[string]string{
53 "User-Agent": "test-agent",
54 "Content-Type": "application/json",
55 },
56 expected: types.Bool(false),
57 description: "should return false when header exists",
58 },
59 {
60 name: "case-sensitive",
61 expression: `missingHeader(headers, "user-agent")`,
62 headers: map[string]string{
63 "User-Agent": "test-agent",
64 },
65 expected: types.Bool(true),
66 description: "should be case-sensitive (user-agent != User-Agent)",
67 },
68 {
69 name: "empty-headers",
70 expression: `missingHeader(headers, "Any-Header")`,
71 headers: map[string]string{},
72 expected: types.Bool(true),
73 description: "should return true for any header when map is empty",
74 },
75 {
76 name: "real-world-sec-ch-ua",
77 expression: `missingHeader(headers, "Sec-Ch-Ua")`,
78 headers: map[string]string{
79 "User-Agent": "curl/7.68.0",
80 "Accept": "*/*",
81 "Host": "example.com",

Callers

nothing calls this directly

Calls 5

BotEnvironmentFunction · 0.85
CompileFunction · 0.85
newTestDNSFunction · 0.70
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected