Browse Source

Merge branch PYADAPT-98

master
juga 5 years ago
parent
commit
5a7093b2cc
  1. 30
      tests/conftest.py
  2. 3
      tests/constants.py
  3. 39
      tests/test_message.py

30
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

3
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"

39
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]
@ -46,14 +36,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 <alice@openpgp.example>
To: Bob Babagge <bob@openpgp.example>
Subject: This is a subject
@ -62,11 +62,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:]

Loading…
Cancel
Save