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

Function createMockSession

modules/arp_spoof/arp_spoof_test.go:195–261  ·  view source on GitHub ↗

Create a mock session for testing

()

Source from the content-addressed store, hash-verified

193
194// Create a mock session for testing
195func createMockSession() (*MockSession, *MockPacketQueue, *MockFirewall) {
196 // Create interface
197 iface := &network.Endpoint{
198 IpAddress: "192.168.1.100",
199 HwAddress: "aa:bb:cc:dd:ee:ff",
200 Hostname: "eth0",
201 }
202 iface.SetIP("192.168.1.100")
203 iface.SetBits(24)
204
205 // Parse interface addresses
206 ifaceIP := net.ParseIP("192.168.1.100")
207 ifaceHW, _ := net.ParseMAC("aa:bb:cc:dd:ee:ff")
208 iface.IP = ifaceIP
209 iface.HW = ifaceHW
210
211 // Create gateway
212 gateway := &network.Endpoint{
213 IpAddress: "192.168.1.1",
214 HwAddress: "11:22:33:44:55:66",
215 }
216 gatewayIP := net.ParseIP("192.168.1.1")
217 gatewayHW, _ := net.ParseMAC("11:22:33:44:55:66")
218 gateway.IP = gatewayIP
219 gateway.HW = gatewayHW
220
221 // Create mock queue and firewall
222 mockQueue := NewMockPacketQueue()
223 mockFirewall := NewMockFirewall()
224
225 // Create environment
226 env, _ := session.NewEnvironment("")
227
228 // Create LAN
229 aliases, _ := data.NewUnsortedKV("", 0)
230 lan := network.NewLAN(iface, gateway, aliases, func(e *network.Endpoint) {}, func(e *network.Endpoint) {})
231
232 // Create session
233 sess := &session.Session{
234 Interface: iface,
235 Gateway: gateway,
236 Lan: lan,
237 StartedAt: time.Now(),
238 Active: true,
239 Env: env,
240 Queue: mockQueue.Queue,
241 Firewall: mockFirewall,
242 Modules: make(session.ModuleList, 0),
243 }
244
245 // Initialize events
246 sess.Events = session.NewEventPool(false, false)
247
248 // Add mock net.recon module
249 mockNetRecon := NewMockNetRecon(sess)
250 sess.Modules = append(sess.Modules, mockNetRecon)
251
252 // Create mock session wrapper

Callers 12

TestNewArpSpooferFunction · 0.70
TestArpSpooferConfigureFunction · 0.70
TestArpSpooferStartStopFunction · 0.70
TestArpSpooferBanModeFunction · 0.70
TestArpSpooferFullDuplexFunction · 0.70
TestArpSpooferGetTargetsFunction · 0.70

Calls 8

SetIPMethod · 0.95
SetBitsMethod · 0.95
NewEnvironmentFunction · 0.92
NewLANFunction · 0.92
NewEventPoolFunction · 0.92
NewMockPacketQueueFunction · 0.85
NewMockFirewallFunction · 0.70
NewMockNetReconFunction · 0.70

Tested by

no test coverage detected