Skip to content

Commit f535ed7

Browse files
committed
tests: fix handshake test + add a output test
1 parent 135c8a0 commit f535ed7

2 files changed

Lines changed: 79 additions & 4 deletions

File tree

tests/test_Handshake.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@ def testHandshakeTshark(self):
3434
print("\nTesting handshake with tshark...")
3535
hs_file = self.getFile("handshake_exists.cap")
3636
print("Testing file:", hs_file)
37-
hs = Handshake(hs_file, bssid='A4:2B:8C:16:6B:3A')
38-
handshakes = hs.tshark_handshakes()
39-
print(f"Found {len(handshakes)} handshake(s): {handshakes}")
40-
assert len(handshakes) > 0, f'Expected len>0 but got len({len(handshakes)})'
37+
38+
# Copy file to /tmp to work around tshark permission issues
39+
import tempfile
40+
import shutil
41+
import os
42+
43+
with tempfile.NamedTemporaryFile(delete=False, suffix='.cap') as tmp:
44+
temp_file = tmp.name
45+
46+
try:
47+
shutil.copy2(hs_file, temp_file)
48+
hs = Handshake(temp_file, bssid='A4:2B:8C:16:6B:3A')
49+
handshakes = hs.tshark_handshakes()
50+
print(f"Found {len(handshakes)} handshake(s): {handshakes}")
51+
assert len(handshakes) > 0, f'Expected len>0 but got len({len(handshakes)})'
52+
finally:
53+
if os.path.exists(temp_file):
54+
os.unlink(temp_file)
4155

4256
@unittest.skipUnless(Process.exists("cowpatty"), 'cowpatty is missing')
4357
def testHandshakeCowpatty(self):

tests/test_exact_output.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
sys.path.insert(0, '.')
5+
6+
from wifite.tools.airmon import Airmon
7+
8+
# Test with the exact current output
9+
test_output = """
10+
Found 6 processes that could cause trouble.
11+
Kill them using 'airmon-ng check kill' before putting
12+
the card in monitor mode, they will interfere by changing channels
13+
and sometimes putting the interface back in managed mode
14+
15+
PID Name
16+
7044 avahi-daemon
17+
7105 avahi-daemon
18+
7183 wpa_supplicant
19+
25765 NetworkManager
20+
2503235 dhclient
21+
2523490 dhclient
22+
23+
PHY Interface Driver Chipset
24+
25+
phy1 wlp4s0 iwlwifi Intel Corporation Wi-Fi 6E(802.11ax) AX210/AX1675* 2x2 [Typhoon Peak] (rev 1a)
26+
phy0 wlxd037456283c3 rtl8xxxu TP-Link TL-WN821N v5/v6 [RTL8192EU]
27+
(mac80211 monitor mode already enabled for [phy0]wlxd037456283c3 on [phy0]10)
28+
"""
29+
30+
print("Testing exact airmon-ng output...")
31+
result = Airmon._parse_airmon_start(test_output)
32+
print(f"Result: '{result}'")
33+
34+
# Let's debug the regex matching
35+
import re
36+
37+
enabled_on_re = re.compile(r'.*\(mac80211 monitor mode (?:(?:vif )?enabled|already enabled) (?:for [^ ]+ )?on (?:\[\w+])?([a-zA-Z]\w+)\)?.*')
38+
enabled_for_re = re.compile(r'.*\(mac80211 monitor mode (?:(?:vif )?enabled|already enabled) for (?:\[\w+])?(\w+).*on (?:\[\w+])?\d+\)?.*')
39+
40+
lines = test_output.split('\n')
41+
for i, line in enumerate(lines):
42+
if 'mac80211 monitor mode' in line:
43+
print(f"\nLine {i}: {repr(line)}")
44+
45+
match1 = enabled_on_re.match(line)
46+
if match1:
47+
print(f" enabled_on_re matched: '{match1.group(1)}'")
48+
else:
49+
print(" enabled_on_re: no match")
50+
51+
match2 = enabled_for_re.match(line)
52+
if match2:
53+
print(f" enabled_for_re matched: '{match2.group(1)}'")
54+
else:
55+
print(" enabled_for_re: no match")
56+
57+
# Check the legacy fallback
58+
if "monitor mode enabled" in line:
59+
print(f" legacy fallback would return: '{line.split()[-1]}'")
60+
else:
61+
print(" legacy fallback: no match")

0 commit comments

Comments
 (0)