diff --git a/plugins/CryptMessage/Test/TestCrypt.py b/plugins/CryptMessage/Test/TestCrypt.py index dbd18d71..63156c24 100644 --- a/plugins/CryptMessage/Test/TestCrypt.py +++ b/plugins/CryptMessage/Test/TestCrypt.py @@ -46,60 +46,54 @@ class TestCrypt: pub2 = ui_websocket.testAction("UserPublickey", 0) assert pub1 != pub2 - - def testEcies(self, ui_websocket): ui_websocket.actionUserPublickey(0, 0) - pub = ui_websocket.ws.result + pub = ui_websocket.ws.getResult() ui_websocket.actionEciesEncrypt(0, "hello", pub) - encrypted = ui_websocket.ws.result + encrypted = ui_websocket.ws.getResult() assert len(encrypted) == 180 # Don't allow decrypt using other privatekey index ui_websocket.actionEciesDecrypt(0, encrypted, 123) - decrypted = ui_websocket.ws.result + decrypted = ui_websocket.ws.getResult() assert decrypted != "hello" # Decrypt using correct privatekey ui_websocket.actionEciesDecrypt(0, encrypted) - decrypted = ui_websocket.ws.result + decrypted = ui_websocket.ws.getResult() assert decrypted == "hello" # Decrypt batch ui_websocket.actionEciesDecrypt(0, [encrypted, "baad", encrypted]) - decrypted = ui_websocket.ws.result + decrypted = ui_websocket.ws.getResult() assert decrypted == ["hello", None, "hello"] - def testEciesUtf8(self, ui_websocket): # Utf8 test - utf8_text = u'\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9p' - ui_websocket.actionEciesEncrypt(0, utf8_text) - encrypted = ui_websocket.ws.result + ui_websocket.actionEciesEncrypt(0, self.utf8_text) + encrypted = ui_websocket.ws.getResult() ui_websocket.actionEciesDecrypt(0, encrypted) - assert ui_websocket.ws.result == utf8_text - + assert ui_websocket.ws.getResult() == self.utf8_text def testEciesAes(self, ui_websocket): ui_websocket.actionEciesEncrypt(0, "hello", return_aes_key=True) - ecies_encrypted, aes_key = ui_websocket.ws.result + ecies_encrypted, aes_key = ui_websocket.ws.getResult() # Decrypt using Ecies ui_websocket.actionEciesDecrypt(0, ecies_encrypted) - assert ui_websocket.ws.result == "hello" + assert ui_websocket.ws.getResult() == "hello" # Decrypt using AES - aes_iv, aes_encrypted = CryptMessage.split(ecies_encrypted.decode("base64")) - - ui_websocket.actionAesDecrypt(0, aes_iv.encode("base64"), aes_encrypted.encode("base64"), aes_key) - assert ui_websocket.ws.result == "hello" + aes_iv, aes_encrypted = CryptMessage.split(base64.b64decode(ecies_encrypted)) + ui_websocket.actionAesDecrypt(0, base64.b64encode(aes_iv), base64.b64encode(aes_encrypted), aes_key) + assert ui_websocket.ws.getResult() == "hello" def testAes(self, ui_websocket): ui_websocket.actionAesEncrypt(0, "hello") - key, iv, encrypted = ui_websocket.ws.result + key, iv, encrypted = ui_websocket.ws.getResult() assert len(key) == 44 assert len(iv) == 24 @@ -107,26 +101,25 @@ class TestCrypt: # Single decrypt ui_websocket.actionAesDecrypt(0, iv, encrypted, key) - assert ui_websocket.ws.result == "hello" + assert ui_websocket.ws.getResult() == "hello" # Batch decrypt ui_websocket.actionAesEncrypt(0, "hello") - key2, iv2, encrypted2 = ui_websocket.ws.result + key2, iv2, encrypted2 = ui_websocket.ws.getResult() assert [key, iv, encrypted] != [key2, iv2, encrypted2] # 2 correct key ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key]) - assert ui_websocket.ws.result == ["hello", "hello", None, None] + assert ui_websocket.ws.getResult() == ["hello", "hello", None, None] # 3 key ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key, key2]) - assert ui_websocket.ws.result == ["hello", "hello", None, "hello"] + assert ui_websocket.ws.getResult() == ["hello", "hello", None, "hello"] def testAesUtf8(self, ui_websocket): - utf8_text = u'\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9' - ui_websocket.actionAesEncrypt(0, utf8_text) - key, iv, encrypted = ui_websocket.ws.result + ui_websocket.actionAesEncrypt(0, self.utf8_text) + key, iv, encrypted = ui_websocket.ws.getResult() ui_websocket.actionAesDecrypt(0, iv, encrypted, key) - assert ui_websocket.ws.result == utf8_text + assert ui_websocket.ws.getResult() == self.utf8_text