diff --git a/.github/workflows/zeyple.yml b/.github/workflows/zeyple.yml index 8f65669..263933b 100644 --- a/.github/workflows/zeyple.yml +++ b/.github/workflows/zeyple.yml @@ -28,16 +28,18 @@ jobs: sudo apt-get install debconf-utils sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local only'" sudo debconf-set-selections <<< "postfix postfix/mailname string localhost" - sudo apt-get install -y mailutils ruby ruby-dev rubygems build-essential sudo gnupg python3-gpg + sudo apt-get install -y mailutils ruby ruby-dev rubygems build-essential sudo gnupg python3-gpg libgpgme11 libgpgme-dev sudo gem install --no-document fpm python -m pip install --upgrade pip setuptools wheel - python -m pip install --upgrade tox + python -m pip install --upgrade mock pycodestyle pytest pytest-cov - name: Build deb package run: ./fpm/create - name: End to end test using deb package run: sudo bash -ex ./tests/e2e.sh - - name: Test with tox - run: tox + - name: Lint with pycodestyle + run: pycodestyle --show-pep8 --max-line-length=100 + - name: Test with pytest + run: env PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages python -m pytest --cov=zeyple/ --cov-report=html - name: Upload deb package uses: actions/upload-artifact@v1 with: diff --git a/tests/test_zeyple.py b/tests/test_zeyple.py index a724d41..817c81e 100644 --- a/tests/test_zeyple.py +++ b/tests/test_zeyple.py @@ -1,9 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import absolute_import + from configparser import ConfigParser from textwrap import dedent from unittest.mock import Mock +from gpg import _gpgme import gpg import os import re @@ -14,6 +17,8 @@ from zeyple import zeyple as z +del absolute_import + KEYS_FNAME = os.path.join(os.path.dirname(__file__), 'keys.gpg') TEST1_ID = 'D6513C04E24C1F83' TEST1_EMAIL = 'test1@zeyple.example.com' diff --git a/zeyple/zeyple.py b/zeyple/zeyple.py index 8b14b3c..8f4a28b 100755 --- a/zeyple/zeyple.py +++ b/zeyple/zeyple.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import absolute_import + from configparser import ConfigParser from io import BytesIO import copy @@ -15,13 +17,7 @@ import smtplib import sys - -def message_from_binary(message): - return email.message_from_bytes(message) - - -def as_binary_string(email): - return email.as_bytes() +del absolute_import def encode_string(string): @@ -84,7 +80,7 @@ def process_message(self, message_data, recipients): """Encrypts the message with recipient keys""" message_data = encode_string(message_data) - in_message = message_from_binary(message_data) + in_message = email.message_from_bytes(message_data) logging.info( "Processing outgoing message %s", in_message['Message-id']) @@ -190,7 +186,7 @@ def _encrypt_message(self, in_message, key_id): # remove superfluous header del mixed['MIME-Version'] - payload = as_binary_string(mixed) + payload = mixed.as_bytes() encrypted_payload = self._encrypt_payload(payload, [key_id])