aboutsummaryrefslogtreecommitdiff
path: root/python/tests/group_session_test.py
diff options
context:
space:
mode:
authorDamir Jelić <poljar@termina.org.uk>2018-07-08 12:19:16 +0200
committerHubert Chathi <hubert@uhoreg.ca>2018-07-18 17:44:32 -0400
commite3d66733712e161d9287ea3f0116e5b57477b0d8 (patch)
tree846678302027f772f5d8e0ef30d4e0ac79a526f9 /python/tests/group_session_test.py
parent2fccf44015dfb27865ddb50ed66afdedbd4e03e6 (diff)
python: Import improved python bindings.
This commit imports the python bindings from: https://github.com/poljar/python-olm The bindings are imported at commit c44b145818520d69eaaa350fb95afcb846125e0f Minor modifications were made while importing: - Removed travis config - Removed Arch Linux PKGBUILD - Removed the html docs, they can be rebuild by running make html in the docs folder - Slightly modified the README The new bindings feature some improvements over the old ones: - Python 2 and 3 support - Automatic memory management - Automatic memory clearing before it is freed - Type signatures via the python typing module - Full test coverage - Properties are utilized where it makes sense (e.g. account.id) Signed-off-by: Damir Jelić <poljar@termina.org.uk>
Diffstat (limited to 'python/tests/group_session_test.py')
-rw-r--r--python/tests/group_session_test.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/python/tests/group_session_test.py b/python/tests/group_session_test.py
new file mode 100644
index 0000000..c17e84f
--- /dev/null
+++ b/python/tests/group_session_test.py
@@ -0,0 +1,114 @@
+import pytest
+
+from olm import InboundGroupSession, OlmGroupSessionError, OutboundGroupSession
+
+
+class TestClass(object):
+ def test_session_create(self):
+ OutboundGroupSession()
+
+ def test_session_id(self):
+ session = OutboundGroupSession()
+ assert isinstance(session.id, str)
+
+ def test_session_index(self):
+ session = OutboundGroupSession()
+ assert isinstance(session.message_index, int)
+ assert session.message_index == 0
+
+ def test_outbound_pickle(self):
+ session = OutboundGroupSession()
+ pickle = session.pickle()
+
+ assert (session.id == OutboundGroupSession.from_pickle(
+ pickle).id)
+
+ def test_invalid_unpickle(self):
+ with pytest.raises(ValueError):
+ OutboundGroupSession.from_pickle(b"")
+
+ with pytest.raises(ValueError):
+ InboundGroupSession.from_pickle(b"")
+
+ def test_inbound_create(self):
+ outbound = OutboundGroupSession()
+ InboundGroupSession(outbound.session_key)
+
+ def test_invalid_decrypt(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+
+ with pytest.raises(ValueError):
+ inbound.decrypt("")
+
+ def test_inbound_pickle(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ pickle = inbound.pickle()
+ InboundGroupSession.from_pickle(pickle)
+
+ def test_inbound_export(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ imported = InboundGroupSession.import_session(
+ inbound.export_session(inbound.first_known_index)
+ )
+ assert "Test", 0 == imported.decrypt(outbound.encrypt("Test"))
+
+ def test_first_index(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ index = inbound.first_known_index
+ assert isinstance(index, int)
+
+ def test_encrypt(self, benchmark):
+ benchmark.weave(OutboundGroupSession.encrypt, lazy=True)
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ assert "Test", 0 == inbound.decrypt(outbound.encrypt("Test"))
+
+ def test_decrypt(self, benchmark):
+ benchmark.weave(InboundGroupSession.decrypt, lazy=True)
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ assert "Test", 0 == inbound.decrypt(outbound.encrypt("Test"))
+
+ def test_decrypt_twice(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ outbound.encrypt("Test 1")
+ message, index = inbound.decrypt(outbound.encrypt("Test 2"))
+ assert isinstance(index, int)
+ assert ("Test 2", 1) == (message, index)
+
+ def test_decrypt_failure(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ eve_outbound = OutboundGroupSession()
+ with pytest.raises(OlmGroupSessionError):
+ inbound.decrypt(eve_outbound.encrypt("Test"))
+
+ def test_id(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ assert outbound.id == inbound.id
+
+ def test_inbound_fail(self):
+ with pytest.raises(TypeError):
+ InboundGroupSession()
+
+ def test_oubtound_pickle_fail(self):
+ outbound = OutboundGroupSession()
+ pickle = outbound.pickle("Test")
+
+ with pytest.raises(OlmGroupSessionError):
+ OutboundGroupSession.from_pickle(pickle)
+
+ def test_outbound_clear(self):
+ session = OutboundGroupSession()
+ del session
+
+ def test_inbound_clear(self):
+ outbound = OutboundGroupSession()
+ inbound = InboundGroupSession(outbound.session_key)
+ del inbound