From 072563a34333ed8d902850e3233f576713076aeb Mon Sep 17 00:00:00 2001 From: juga Date: Mon, 26 Oct 2020 10:52:22 +0000 Subject: [PATCH 1/3] tests: Update pytests created with older version Closes PYADPT-98. --- tests/test_message.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/test_message.py b/tests/test_message.py index 062b65b..c6bc979 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -46,14 +46,24 @@ def test_msg_enc_dec_roundtrip(tmpdir, alice_sec_key_data, bob_pub_key_data): # Decrypt message. dec_msg, key_list, rating, r = enc_msg.decrypt() assert r == 0 - assert rating == pEp.PEP_rating.PEP_rating_reliable + # pEp version 2.2 throws this error: + # AttributeError: module 'pEp' has no attribute 'PEP_rating' + # assert rating == pEp.PEP_rating.PEP_rating_reliable + # It seems to have changed to the following. + assert rating == pEp.native_pEp.rating.reliable - # It is not known which key is generated for Alice, so check only the - # one for Bob. + # The first 2 keys are Alice's ones, the last is Bob's one. + assert key_list[0] == key_list[1] == constants.ALICE_FP assert key_list[-1] == constants.BOB_FP assert dec_msg.shortmsg == constants.SUBJECT assert dec_msg.longmsg.replace("\r", "") == msg.longmsg dec_lines = str(dec_msg).replace("\r", "").split("\n") + # pEp version 2.2 seems to have fixed some of the replaced characters. + # and changed also: + # Content-Type: doesn't pring `; charset="utf-8"` anymore. + # Content-Transfer-Encoding: doesn't print `quoted-printable` anymore. + # Content-Disposition: is not present anymore. + # `!` is not replaced by `=21` anymore. expected_dec_lines = """From: Alice Lovelace To: Bob Babagge Subject: This is a subject @@ -62,11 +72,10 @@ X-EncStatus: reliable X-KeyList: X,X,D1A66E1A23B182C9980F788CFBFCC82A015E7330 MIME-Version: 1.0 -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: quoted-printable -Content-Disposition: inline; filename="msg.txt" +Content-Type: text/plain +Content-Transfer-Encoding: 7bit -Hi world=21 +Hi world! """.split("\n") assert dec_lines[:5] == expected_dec_lines[:5] assert dec_lines[7:] == expected_dec_lines[7:] From d0a94e20cd7b09aaf3aa0726bd94ffd0cd938720 Mon Sep 17 00:00:00 2001 From: juga Date: Mon, 26 Oct 2020 10:55:17 +0000 Subject: [PATCH 2/3] tests: Create identities fixture to use in message Since the identities are not being tested in the message tests, facilitate to create them. --- tests/conftest.py | 30 ++++++++++++++++++++++++++++++ tests/test_message.py | 16 +++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1aa45d7..cac2a3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,9 @@ """pytest configuration for the unit tests.""" +import os import pytest +from . import constants + @pytest.fixture() def datadir(request): @@ -43,3 +46,30 @@ def alice_sec_key_data(datadir): def bob_pub_key_data(datadir): key_data = datadir.read('bob@openpgp.example.pub.asc') return key_data + + +@pytest.fixture() +def create_alice_identity(tmpdir, alice_sec_key_data, bob_pub_key_data): + os.environ["HOME"] = str(tmpdir) + import pEp + + pEp.import_key(alice_sec_key_data) + alice = pEp.Identity( + constants.ALICE_ADDRESS, constants.ALICE_NAME, + constants.ALICE_NAME_ADDR, constants.ALICE_FP, 0, '' + ) + pEp.set_own_key(alice, constants.ALICE_FP) + return alice + + +@pytest.fixture() +def create_bob_identity(tmpdir, bob_pub_key_data): + os.environ["HOME"] = str(tmpdir) + import pEp + + pEp.import_key(bob_pub_key_data) + bob = pEp.Identity( + constants.BOB_ADDRESS, constants.BOB_NAME, '', + constants.BOB_FP, 56, '' + ) + return bob diff --git a/tests/test_message.py b/tests/test_message.py index c6bc979..10b59fd 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,23 +1,13 @@ """Message unit tests.""" -import os from . import constants -def test_msg_enc_dec_roundtrip(tmpdir, alice_sec_key_data, bob_pub_key_data): - os.environ["HOME"] = str(tmpdir) +def test_msg_enc_dec_roundtrip(create_alice_identity, create_bob_identity): import pEp - alice = pEp.Identity( - constants.ALICE_ADDRESS, constants.ALICE_NAME, - constants.ALICE_NAME_ADDR, constants.ALICE_FP, 0, '' - ) - - pEp.import_key(bob_pub_key_data) - bob = pEp.Identity( - constants.BOB_ADDRESS, constants.BOB_NAME, '', - constants.BOB_FP, 56, '' - ) + alice = create_alice_identity + bob = create_bob_identity msg = pEp.Message(constants.OUTGOING_MSG, alice) msg.to = [bob] From c4487042659b5f2111348a1ee2384189064cad2f Mon Sep 17 00:00:00 2001 From: juga Date: Mon, 26 Oct 2020 10:55:53 +0000 Subject: [PATCH 3/3] tests: Remove unused constant myself --- tests/constants.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/constants.py b/tests/constants.py index cf5e02b..f83f3bb 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -8,9 +8,6 @@ INCOMING_MSG = 2 ANGLE_ADDR = "<{}>" NAME_ADDR = "{} {}" -PEP_NAME = "myself" -PEP_ADDRESS = "myself@pep.fundation" - BOB_NAME = "Bob Babagge" BOB_ADDRESS = "bob@openpgp.example" BOB_FP = "D1A66E1A23B182C9980F788CFBFCC82A015E7330"