예제 #1
0
 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)
예제 #2
0
    def test_invalid_unicode_decrypt(self):
        outbound = OutboundGroupSession()
        inbound = InboundGroupSession(outbound.session_key)

        text = outbound.encrypt(b"\xed")
        plaintext, _ = inbound.decrypt(text)

        print(plaintext)
        assert plaintext == u"�"

        plaintext, _ = inbound.decrypt(text, "ignore")
        assert plaintext == ""
예제 #3
0
 def test_inbound_clear(self):
     outbound = OutboundGroupSession()
     inbound = InboundGroupSession(outbound.session_key)
     del inbound
예제 #4
0
 def test_inbound_fail(self):
     with pytest.raises(TypeError):
         InboundGroupSession()
예제 #5
0
 def test_id(self):
     outbound = OutboundGroupSession()
     inbound = InboundGroupSession(outbound.session_key)
     assert outbound.id == inbound.id
예제 #6
0
 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"))
예제 #7
0
 def test_decrypt(self, benchmark):
     benchmark.weave(InboundGroupSession.decrypt, lazy=True)
     outbound = OutboundGroupSession()
     inbound = InboundGroupSession(outbound.session_key)
     assert "Test" == inbound.decrypt(outbound.encrypt("Test"))
예제 #8
0
 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" == imported.decrypt(outbound.encrypt("Test"))
예제 #9
0
 def test_inbound_pickle(self):
     outbound = OutboundGroupSession()
     inbound = InboundGroupSession(outbound.session_key)
     pickle = inbound.pickle()
     InboundGroupSession.from_pickle(pickle)
예제 #10
0
    def test_invalid_decrypt(self):
        outbound = OutboundGroupSession()
        inbound = InboundGroupSession(outbound.session_key)

        with pytest.raises(ValueError):
            inbound.decrypt("")
예제 #11
0
 def test_inbound_create(self):
     outbound = OutboundGroupSession()
     InboundGroupSession(outbound.session_key)
예제 #12
0
    def test_invalid_unpickle(self):
        with pytest.raises(ValueError):
            OutboundGroupSession.from_pickle(b"")

        with pytest.raises(ValueError):
            InboundGroupSession.from_pickle(b"")
예제 #13
0
 def test_first_index(self):
     outbound = OutboundGroupSession()
     inbound = InboundGroupSession(outbound.session_key)
     index = inbound.first_known_index
     assert isinstance(index, int)