diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_session.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/test/mitmproxy/addons/test_session.py b/test/mitmproxy/addons/test_session.py index 7089b89e..cb36e283 100644 --- a/test/mitmproxy/addons/test_session.py +++ b/test/mitmproxy/addons/test_session.py @@ -1,38 +1,38 @@ import sqlite3 -import os import pytest +import os -from mitmproxy.exceptions import SessionLoadException from mitmproxy.addons import session +from mitmproxy.exceptions import SessionLoadException from mitmproxy.utils.data import pkg_data class TestSession: def test_session_temporary(self, tdata): - open('tmp.sqlite', 'w') s = session.SessionDB() - assert session.SessionDB.is_session_db('tmp.sqlite') - s.con.close() - os.remove('tmp.sqlite') + filename = s.temp.name + assert session.SessionDB.is_session_db(filename) def test_session_not_valid(self, tdata): - path = tdata.path('mitmproxy/data/') + '/test.sqlite' + path = tdata.path('mitmproxy/data/') + '/test_snv.sqlite' if os.path.isfile(path): os.remove(path) with open(path, 'w') as handle: handle.write("Not valid data") with pytest.raises(SessionLoadException): session.SessionDB(path) + os.remove(path) def test_session_new_persistent(self, tdata): - path = tdata.path('mitmproxy/data/') + '/test.sqlite' + path = tdata.path('mitmproxy/data/') + '/test_np.sqlite' if os.path.isfile(path): os.remove(path) session.SessionDB(path) assert session.SessionDB.is_session_db(path) + os.remove(path) def test_session_load_existing(self, tdata): - path = tdata.path('mitmproxy/data/') + '/test.sqlite' + path = tdata.path('mitmproxy/data/') + '/test_le.sqlite' if os.path.isfile(path): os.remove(path) con = sqlite3.connect(path) @@ -41,7 +41,7 @@ class TestSession: with con: con.executescript(qry) blob = b'blob_of_data' - con.execute(f'INSERT INTO FLOW VALUES(1, 1, 1, "{blob}");') + con.execute(f'INSERT INTO FLOW VALUES(1, "{blob}");') con.close() session.SessionDB(path) con = sqlite3.connect(path) @@ -50,3 +50,5 @@ class TestSession: cur.execute('SELECT * FROM FLOW;') rows = cur.fetchall() assert len(rows) == 1 + con.close() + os.remove(path) |