[gnome-keysign: 9/16] test_wormhole: add additional tests
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign: 9/16] test_wormhole: add additional tests
- Date: Tue, 1 Jan 2019 16:02:24 +0000 (UTC)
commit 79aee06c0b434e25e6c1bb17a004e9f112935f6f
Author: RyuzakiKK <aasonykk gmail com>
Date: Wed Dec 5 16:23:04 2018 +0100
test_wormhole: add additional tests
tests/test_wormhole.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 2 deletions(-)
---
diff --git a/tests/test_wormhole.py b/tests/test_wormhole.py
index 9a07e3e..6df199c 100644
--- a/tests/test_wormhole.py
+++ b/tests/test_wormhole.py
@@ -23,13 +23,15 @@ gi.require_version('Gtk', '3.0')
from nose.twistedtools import deferred
from nose.tools import *
-from wormhole.errors import WrongPasswordError
+from wormhole.errors import WrongPasswordError, LonelyError
from twisted.internet.defer import inlineCallbacks
from keysign.gpgmh import openpgpkey_from_data
+from keysign.gpgmh import get_public_key_data
+from keysign.offer import Offer
+from keysign.util import mac_generate
from keysign.wormholeoffer import WormholeOffer
from keysign.wormholereceive import WormholeReceive
-from keysign.gpgmh import get_public_key_data
log = logging.getLogger(__name__)
@@ -112,3 +114,66 @@ def test_wrmhl_wrong_code():
assert_is_not_none(message)
assert_equal(message, WrongPasswordError)
+
+@deferred(timeout=10)
+@inlineCallbacks
+def test_wrmhl_wrong_hmac():
+ data = read_fixture_file("seckey-no-pw-1.asc")
+ key = openpgpkey_from_data(data)
+ log.info("Running with key %r", key)
+ hmac = "wrong_hmac_eg_tampered_key"
+ # Start offering the key
+ offer = WormholeOffer(key)
+ info = yield offer.allocate_code()
+ code, _ = info
+ offer.start()
+ receive = WormholeReceive(code, mac=hmac)
+ msg_tuple = yield receive.start()
+ downloaded_key_data, success, message = msg_tuple
+ assert_false(success)
+ assert_is_not_none(message)
+ assert_equal(message, WrongPasswordError)
+
+
+@deferred(timeout=10)
+@inlineCallbacks
+def test_wrmhl_with_hmac():
+ data = read_fixture_file("seckey-no-pw-1.asc")
+ key = openpgpkey_from_data(data)
+ file_key_data = get_public_key_data(key.fingerprint)
+ log.info("Running with key %r", key)
+ hmac = mac_generate(key.fingerprint.encode('ascii'), file_key_data)
+ # Start offering the key
+ offer = WormholeOffer(key)
+ info = yield offer.allocate_code()
+ code, _ = info
+ offer.start()
+ receive = WormholeReceive(code, mac=hmac)
+ msg_tuple = yield receive.start()
+ downloaded_key_data, success, _ = msg_tuple
+ assert_true(success)
+ log.info("Checking with key: %r", downloaded_key_data)
+ assert_equal(downloaded_key_data, file_key_data)
+
+
+@deferred(timeout=10)
+@inlineCallbacks
+def test_offer_cancel():
+
+ def _received(start_data):
+ success, message = start_data
+ assert_is_not_none(message)
+ assert_equal(type(message), LonelyError)
+
+ data = read_fixture_file("seckey-no-pw-1.asc")
+ key = openpgpkey_from_data(data)
+ log.info("Running with key %r", key)
+ # Start offering the key
+ offer = Offer(key)
+ _ = yield offer.allocate_code(worm=True)
+
+ defers = offer.start()
+ for de in defers:
+ de.addCallback(_received)
+
+ offer.stop()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]