diff options
author | Pietro Francesco Tirenna <pietrotirenna.pt@gmail.com> | 2018-07-24 16:26:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 16:26:10 +0200 |
commit | 9c949bd2f852fb5f5a314e6faa45e4869571628c (patch) | |
tree | bf2718f6ca8bd1088ccc9945c7d1b9be4ff62a59 /test | |
parent | 16e07996d983483bb732269c921e89e8bda6ee20 (diff) | |
parent | 8c7793b91a2a182ec7d7831f2c03283dad3488cc (diff) | |
download | mitmproxy-9c949bd2f852fb5f5a314e6faa45e4869571628c.tar.gz mitmproxy-9c949bd2f852fb5f5a314e6faa45e4869571628c.tar.bz2 mitmproxy-9c949bd2f852fb5f5a314e6faa45e4869571628c.zip |
Merge pull request #3252 from madt1m/session-db
Session - Hybrid DB
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_session.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/mitmproxy/addons/test_session.py b/test/mitmproxy/addons/test_session.py new file mode 100644 index 00000000..d4b1109b --- /dev/null +++ b/test/mitmproxy/addons/test_session.py @@ -0,0 +1,58 @@ +import sqlite3 +import pytest +import os + +from mitmproxy.addons import session +from mitmproxy.exceptions import SessionLoadException +from mitmproxy.utils.data import pkg_data + + +class TestSession: + def test_session_temporary(self): + s = session.SessionDB() + td = s.tempdir + filename = os.path.join(td, 'tmp.sqlite') + assert session.SessionDB.is_session_db(filename) + assert os.path.isdir(td) + del s + assert not os.path.isdir(td) + + def test_session_not_valid(self, tdata): + 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_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_le.sqlite' + if os.path.isfile(path): + os.remove(path) + con = sqlite3.connect(path) + script_path = pkg_data.path("io/sql/session_create.sql") + qry = open(script_path, 'r').read() + with con: + con.executescript(qry) + blob = b'blob_of_data' + con.execute(f'INSERT INTO FLOW VALUES(1, "{blob}");') + con.close() + session.SessionDB(path) + con = sqlite3.connect(path) + with con: + cur = con.cursor() + cur.execute('SELECT * FROM FLOW;') + rows = cur.fetchall() + assert len(rows) == 1 + con.close() + os.remove(path) |