MCPcopy
hub / github.com/bettercap/bettercap / createMockSession

Function createMockSession

modules/http_proxy/http_proxy_test.go:68–121  ·  view source on GitHub ↗

Create a mock session for testing

()

Source from the content-addressed store, hash-verified

66
67// Create a mock session for testing
68func createMockSession() (*session.Session, *MockFirewall) {
69 // Create interface
70 iface := &network.Endpoint{
71 IpAddress: "192.168.1.100",
72 HwAddress: "aa:bb:cc:dd:ee:ff",
73 Hostname: "eth0",
74 }
75 iface.SetIP("192.168.1.100")
76 iface.SetBits(24)
77
78 // Parse interface addresses
79 ifaceIP := net.ParseIP("192.168.1.100")
80 ifaceHW, _ := net.ParseMAC("aa:bb:cc:dd:ee:ff")
81 iface.IP = ifaceIP
82 iface.HW = ifaceHW
83
84 // Create gateway
85 gateway := &network.Endpoint{
86 IpAddress: "192.168.1.1",
87 HwAddress: "11:22:33:44:55:66",
88 }
89 gatewayIP := net.ParseIP("192.168.1.1")
90 gatewayHW, _ := net.ParseMAC("11:22:33:44:55:66")
91 gateway.IP = gatewayIP
92 gateway.HW = gatewayHW
93
94 // Create mock firewall
95 mockFirewall := NewMockFirewall()
96
97 // Create environment
98 env, _ := session.NewEnvironment("")
99
100 // Create LAN
101 aliases, _ := data.NewUnsortedKV("", 0)
102 lan := network.NewLAN(iface, gateway, aliases, func(e *network.Endpoint) {}, func(e *network.Endpoint) {})
103
104 // Create session
105 sess := &session.Session{
106 Interface: iface,
107 Gateway: gateway,
108 Lan: lan,
109 StartedAt: time.Now(),
110 Active: true,
111 Env: env,
112 Queue: &packets.Queue{},
113 Firewall: mockFirewall,
114 Modules: make(session.ModuleList, 0),
115 }
116
117 // Initialize events
118 sess.Events = session.NewEventPool(false, false)
119
120 return sess, mockFirewall
121}
122
123func TestNewHttpProxy(t *testing.T) {
124 sess, _ := createMockSession()

Callers 10

TestNewHttpProxyFunction · 0.70
TestHttpProxyConfigureFunction · 0.70
TestHttpProxyStartStopFunction · 0.70
TestHTTPProxyDoProxyFunction · 0.70
TestHTTPProxyShouldProxyFunction · 0.70

Calls 6

SetIPMethod · 0.95
SetBitsMethod · 0.95
NewEnvironmentFunction · 0.92
NewLANFunction · 0.92
NewEventPoolFunction · 0.92
NewMockFirewallFunction · 0.70

Tested by

no test coverage detected