Skip to content

Commit

Permalink
Fix tests and Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ulcl committed Sep 28, 2023
1 parent ea45001 commit 89bbd13
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 174 deletions.
126 changes: 82 additions & 44 deletions unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# import sqlite3
import unittest
# from database_utils import *
import database_utils
from utils import database_utils


class TestFunctions(unittest.TestCase):

def setUp(self):
self.verbose = False
self.database_name = 'test_database.db'
self.database = database_utils.connectDatabase(self.database_name, self.verbose)
self.database = database_utils.connectDatabase(self.database_name,
self.verbose)
database_utils.createDatabase(self.database, self.verbose)
database_utils.createViews(self.database, self.verbose)
self.c = self.database.cursor()
Expand Down Expand Up @@ -38,14 +39,16 @@ def test_insertAP(self):
mfpc = 'False'
mfpr = 'False'
# Insert new AP
result = database_utils.insertAP(self.c, self.verbose, self.bssid, essid,
manuf, channel, freqmhz, carrier, encryption,
packets_total, lat, lon, cloaked, mfpc, mfpr, 0)
result = database_utils.insertAP(self.c, self.verbose, self.bssid,
essid, manuf, channel, freqmhz,
carrier, encryption, packets_total,
lat, lon, cloaked, mfpc, mfpr, 0)

self.assertEqual(result, 0)
# TODO Insert existing AP with new values
# manuf = "Updated_Manufacturer"
# result = insertAP(self.c, False, bssid, essid, manuf, channel, freqmhz, carrier,
# result = insertAP(self.c, False, bssid, essid, manuf, channel,
# freqmhz, carrier,
# encryption, packets_total, lat, lon, cloaked)
# self.assertEqual(result, 0)
# self.c.execute("SELECT * FROM AP WHERE bssid=?", (bssid,))
Expand All @@ -59,12 +62,15 @@ def test_insertClients(self):
packets_total = "10"
power = "-70"
# Insert new client
result = database_utils.insertClients(self.c, self.verbose, self.mac, ssid, manuf, packets_total, power, "Misc", 0)
result = database_utils.insertClients(self.c, self.verbose, self.mac,
ssid, manuf, packets_total,
power, "Misc", 0)

self.assertEqual(result, 0)
# TODO Insert existing client with new values
# manuf = "Updated_Manufacturer"
# result = insertClients(self.c, False, mac, ssid, manuf, packets_total, power, "Misc")
# result = insertClients(self.c, False, mac, ssid, manuf,
# packets_total, power, "Misc")
# self.assertEqual(result, 0)
# self.c.execute("SELECT * FROM CLIENT WHERE mac=?", (mac,))
# rows = self.c.fetchall()
Expand All @@ -82,15 +88,20 @@ def test_insertWPS(self):
wps_config_methods_keypad = True

# Insert new WPS
result = database_utils.insertWPS(self.c, self.verbose, self.bssid, wlan_ssid,
wps_version, wps_device_name, wps_model_name,
wps_model_number, wps_config_methods, wps_config_methods_keypad)
result = database_utils.insertWPS(self.c, self.verbose, self.bssid,
wlan_ssid, wps_version,
wps_device_name, wps_model_name,
wps_model_number,
wps_config_methods,
wps_config_methods_keypad)
self.assertEqual(result, 0)

# TODO Insert existing WPS with new values
# wps_device_name = "Updated_Device"
# result = insertWPS(self.c, self.verbose, bssid, wlan_ssid, wps_version,
# wps_device_name, wps_model_name, wps_model_number, wps_config_methods, wps_config_methods_keypad)
# result = insertWPS(self.c, self.verbose, bssid, wlan_ssid,
# wps_version,
# wps_device_name, wps_model_name, wps_model_number,
# wps_config_methods, wps_config_methods_keypad)
# self.assertEqual(result, 0)
# self.c.execute("SELECT * FROM WPS WHERE wlan_ssid=?", (wlan_ssid,))
# rows = self.c.fetchall()
Expand All @@ -112,9 +123,10 @@ def test_insertConnected(self):
mfpc = 'False'
mfpr = 'False'
# Insert new AP
result = database_utils.insertAP(self.c, self.verbose, self.bssid, essid,
manuf, channel, freqmhz, carrier, encryption,
packets_total, lat, lon, cloaked, mfpc, mfpr, 0)
result = database_utils.insertAP(self.c, self.verbose, self.bssid,
essid, manuf, channel, freqmhz,
carrier, encryption, packets_total,
lat, lon, cloaked, mfpc, mfpr, 0)

self.assertEqual(result, 0)

Expand All @@ -123,24 +135,30 @@ def test_insertConnected(self):
packets_total = "10"
power = "-70"
# Insert new client
result = database_utils.insertClients(self.c, self.verbose, self.mac, ssid, manuf, packets_total, power, "Misc", 0)
result = database_utils.insertClients(self.c, self.verbose, self.mac,
ssid, manuf, packets_total,
power, "Misc", 0)

self.assertEqual(result, 0)

# Insert new connected device
result = database_utils.insertConnected(self.c, self.verbose, self.bssid, self.mac)
result = database_utils.insertConnected(self.c, self.verbose,
self.bssid, self.mac)
self.assertEqual(result, 0)

def test_inserFile(self):
path = "file://path"
script_path = os.path.dirname(os.path.abspath(__file__))
path = script_path+"/README.md"

result = database_utils.insertFile(self.c, self.verbose, path)
self.assertEqual(result, 0)

def test_insertHandshake(self):
path = "file://path"
script_path = os.path.dirname(os.path.abspath(__file__))
path = script_path+"/README.md"

result = database_utils.insertHandshake(self.c, self.verbose, self.bssid, self.mac, path)
result = database_utils.insertHandshake(self.c, self.verbose,
self.bssid, self.mac, path)
self.assertEqual(result, 0)

self.c.execute("SELECT * FROM handshake WHERE bssid=?", (self.bssid,))
Expand All @@ -151,9 +169,12 @@ def test_insertHandshake(self):
def test_insertIdentity(self):
identity = "DOMAIN\\username"
method = "EAP-PEAP"
result = database_utils.insertIdentity(self.c, self.verbose, self.bssid, self.mac, identity, method)
result = database_utils.insertIdentity(self.c, self.verbose,
self.bssid, self.mac, identity,
method)
self.assertEqual(result, 0)
self.c.execute("SELECT identity FROM Identity WHERE mac=?", (self.mac,))
self.c.execute("SELECT identity FROM Identity WHERE mac=?",
(self.mac,))
row = self.c.fetchone()
self.assertEqual(row[0], identity)

Expand All @@ -164,8 +185,9 @@ def test_insertSeenClient(self):
packets_total = "10"
power = "-70"
# Insert new client
result = database_utils.insertClients(self.c, self.verbose, self.mac, ssid, manuf, packets_total, power, "Misc", 0)

result = database_utils.insertClients(self.c, self.verbose, self.mac,
ssid, manuf, packets_total,
power, "Misc", 0)

# Insert seenClient
# station = "Test_Station"
Expand All @@ -175,7 +197,9 @@ def test_insertSeenClient(self):
lat = "37.7749"
lon = "-122.4194"
alt = "10000"
result = database_utils.insertSeenClient(self.c, self.verbose, self.mac, time, tool, power, lat, lon, alt)
result = database_utils.insertSeenClient(self.c, self.verbose,
self.mac, time, tool, power,
lat, lon, alt)
self.assertEqual(result, 0)
self.c.execute("SELECT * FROM SeenClient WHERE mac=?", (self.mac,))
row = self.c.fetchone()
Expand All @@ -198,8 +222,9 @@ def test_insertSeenAP(self):
mfpc = 'False'
mfpr = 'False'
# Insert new AP
result = database_utils.insertAP(self.c, self.verbose, self.bssid, essid, manuf,
channel, freqmhz, carrier, encryption, packets_total,
result = database_utils.insertAP(self.c, self.verbose, self.bssid,
essid, manuf, channel, freqmhz,
carrier, encryption, packets_total,
lat, lon, cloaked, mfpc, mfpr, 0)

self.assertEqual(result, 0)
Expand All @@ -213,7 +238,8 @@ def test_insertSeenAP(self):
alt = "10000"
bsstimestamp = "2032-02-23 10:00:00"
result = database_utils.insertSeenAP(self.c, self.verbose, self.bssid,
time, tool, signal_rsi, lat, lon, alt, bsstimestamp)
time, tool, signal_rsi, lat, lon,
alt, bsstimestamp)
self.assertEqual(result, 0)
self.c.execute("SELECT * FROM SeenAP WHERE bssid=?", (self.bssid,))
row = self.c.fetchone()
Expand All @@ -236,8 +262,9 @@ def test_setHashcat(self):
mfpr = 'False'
# Insert new AP
result = database_utils.insertAP(self.c, self.verbose, self.bssid,
essid, manuf, channel, freqmhz, carrier,
encryption, packets_total, lat, lon, cloaked, mfpc, mfpr, 0)
essid, manuf, channel, freqmhz,
carrier, encryption, packets_total,
lat, lon, cloaked, mfpc, mfpr, 0)

self.assertEqual(result, 0)

Expand All @@ -246,20 +273,26 @@ def test_setHashcat(self):
packets_total = "10"
power = "-70"
# Insert new client
result = database_utils.insertClients(self.c, self.verbose, self.mac, ssid, manuf, packets_total, power, "Misc", 0)
result = database_utils.insertClients(self.c, self.verbose, self.mac,
ssid, manuf, packets_total,
power, "Misc", 0)

self.assertEqual(result, 0)

# insert Handshake
path = "file://path"
script_path = os.path.dirname(os.path.abspath(__file__))
path = script_path+"/README.md"

result = database_utils.insertHandshake(self.c, self.verbose, self.bssid, self.mac, path)
result = database_utils.insertHandshake(self.c, self.verbose,
self.bssid, self.mac, path)
self.assertEqual(result, 0)

# Insert hashcat HASH
path = "file://path"
script_path = os.path.dirname(os.path.abspath(__file__))
path = script_path+"/README.md"
test_hashcat = "aa:bb:cc:dd:ee:ff:11:22:33:44:55:66:77"
result = database_utils.setHashcat(self.c, self.verbose, self.bssid, self.mac, path, test_hashcat)
result = database_utils.setHashcat(self.c, self.verbose, self.bssid,
self.mac, path, test_hashcat)
self.assertEqual(result, 0)
self.c.execute("SELECT * FROM handshake WHERE bssid=?", (self.bssid,))
rows = self.c.fetchall()
Expand All @@ -280,9 +313,10 @@ def test_obfuscateDB(self):
mfpc = 'False'
mfpr = 'False'
# Insert new AP
result = database_utils.insertAP(self.c, self.verbose, self.bssid, essid,
manufAP, channel, freqmhz, carrier, encryption,
packets_total, lat, lon, cloaked, mfpc, mfpr, 0)
result = database_utils.insertAP(self.c, self.verbose, self.bssid,
essid, manufAP, channel, freqmhz,
carrier, encryption, packets_total,
lat, lon, cloaked, mfpc, mfpr, 0)

self.assertEqual(result, 0)

Expand All @@ -291,22 +325,26 @@ def test_obfuscateDB(self):
packets_total = "10"
power = "-70"
# Insert new client
result = database_utils.insertClients(self.c, self.verbose, self.mac, ssid,
manufClient, packets_total, power, "Misc", 0)
result = database_utils.insertClients(self.c, self.verbose, self.mac,
ssid, manufClient, packets_total,
power, "Misc", 0)

self.assertEqual(result, 0)

# insert Handshake
path = "file://path"
script_path = os.path.dirname(os.path.abspath(__file__))
path = script_path+"/README.md"

result = database_utils.insertHandshake(self.c, self.verbose, self.bssid, self.mac, path)
result = database_utils.insertHandshake(self.c, self.verbose,
self.bssid, self.mac, path)
self.assertEqual(result, 0)

# obfuscateDB
result = database_utils.obfuscateDB(self.database, self.verbose)
self.assertEqual(result, 0)

# self.c.execute("SELECT * FROM handshake WHERE bssid=?", (self.bssid,))
# self.c.execute("SELECT * FROM handshake WHERE bssid=?",
# (self.bssid,))
self.c.execute("SELECT * FROM AP WHERE ssid=?", (essid,))
rows = self.c.fetchall()
# Same ESSID but different BSSID
Expand Down
Loading

0 comments on commit 89bbd13

Please sign in to comment.