aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authormadt1m <pietrotirenna.pt@gmail.com>2018-07-24 11:14:39 +0200
committermadt1m <pietrotirenna.pt@gmail.com>2018-07-24 11:58:33 +0200
commit68eb07b668b44074271b358b25e48ffd2b4726e0 (patch)
treef1511aadd514fe12727f5b9196aa1ddcbc60a8fe /test
parent3b5cdf7f67e030fa0887bc309068b727f20918e3 (diff)
downloadmitmproxy-68eb07b668b44074271b358b25e48ffd2b4726e0.tar.gz
mitmproxy-68eb07b668b44074271b358b25e48ffd2b4726e0.tar.bz2
mitmproxy-68eb07b668b44074271b358b25e48ffd2b4726e0.zip
session: modified schema. Now SessionDB uses tempfile module for temp session
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_session.py22
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)