- Modify test_ece.py to stop using nose.

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-http-ece?expand=0&rev=3
This commit is contained in:
Steve Kowalik 2021-09-29 01:27:14 +00:00 committed by Git OBS Bridge
parent c47aae39d0
commit 09d98b1b74
3 changed files with 44 additions and 41 deletions

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Sep 29 01:26:19 UTC 2021 - Steve Kowalik <steven.kowalik@suse.com>
- Modify test_ece.py to stop using nose.
-------------------------------------------------------------------
Sun Jun 7 05:57:06 UTC 2020 - John Vandenberg <jayvdb@gmail.com>

View File

@ -1,7 +1,7 @@
#
# spec file for package python-http-ece
#
# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -35,7 +35,7 @@ BuildArch: noarch
# SECTION test requirements
BuildRequires: %{python_module cryptography >= 2.5}
BuildRequires: %{python_module mock}
BuildRequires: %{python_module nose}
BuildRequires: %{python_module pytest}
# /SECTION
%python_subpackages
@ -54,7 +54,7 @@ cp %{SOURCE1} %{SOURCE2} .
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
%python_exec -m nose
%pytest
%files %{python_files}
%doc README.rst

View File

@ -9,8 +9,6 @@ from cryptography.hazmat.primitives.serialization import (
Encoding, PublicFormat
)
from nose.tools import eq_, assert_raises
import http_ece as ece
from http_ece import ECEException
@ -60,7 +58,7 @@ class TestEce(unittest.TestCase):
self.m_salt = os.urandom(16)
def test_derive_key_invalid_mode(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.derive_key('invalid',
version='aes128gcm',
salt=self.m_salt,
@ -70,10 +68,10 @@ class TestEce(unittest.TestCase):
auth_secret=None,
keyid="valid",
)
eq_(ex.exception.message, "unknown 'mode' specified: invalid")
self.assertEqual(ex.exception.message, "unknown 'mode' specified: invalid")
def test_derive_key_invalid_salt(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.derive_key('encrypt',
version='aes128gcm',
salt=None,
@ -83,10 +81,10 @@ class TestEce(unittest.TestCase):
auth_secret=None,
keyid="valid",
)
eq_(ex.exception.message, "'salt' must be a 16 octet value")
self.assertEqual(ex.exception.message, "'salt' must be a 16 octet value")
def test_derive_key_invalid_version(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.derive_key('encrypt',
version='invalid',
salt=self.m_salt,
@ -96,10 +94,10 @@ class TestEce(unittest.TestCase):
auth_secret=None,
keyid="valid",
)
eq_(ex.exception.message, "Invalid version")
self.assertEqual(ex.exception.message, "Invalid version")
def test_derive_key_no_private_key(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.derive_key('encrypt',
version='aes128gcm',
salt=self.m_salt,
@ -109,10 +107,10 @@ class TestEce(unittest.TestCase):
auth_secret=None,
keyid="valid",
)
eq_(ex.exception.message, "DH requires a private_key")
self.assertEqual(ex.exception.message, "DH requires a private_key")
def test_derive_key_no_secret(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.derive_key('encrypt',
version='aes128gcm',
salt=self.m_salt,
@ -122,12 +120,12 @@ class TestEce(unittest.TestCase):
auth_secret=None,
keyid="valid",
)
eq_(ex.exception.message, "unable to determine the secret")
self.assertEqual(ex.exception.message, "unable to determine the secret")
def test_iv_bad_counter(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.iv(os.urandom(8), pow(2, 64)+1)
eq_(ex.exception.message, "Counter too big")
self.assertEqual(ex.exception.message, "Counter too big")
class TestEceChecking(unittest.TestCase):
@ -141,65 +139,65 @@ class TestEceChecking(unittest.TestCase):
self.m_header += struct.pack('!L', 32) + b'\0'
def test_encrypt_small_rs(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.encrypt(
self.m_input,
version='aes128gcm',
key=self.m_key,
rs=1,
)
eq_(ex.exception.message, "Record size too small")
self.assertEqual(ex.exception.message, "Record size too small")
def test_decrypt_small_rs(self):
header = os.urandom(16) + struct.pack('!L', 2) + b'\0'
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
header + self.m_input,
version='aes128gcm',
key=self.m_key,
rs=1,
)
eq_(ex.exception.message, "Record size too small")
self.assertEqual(ex.exception.message, "Record size too small")
def test_encrypt_bad_version(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.encrypt(
self.m_input,
version='bogus',
key=self.m_key,
)
eq_(ex.exception.message, "Invalid version")
self.assertEqual(ex.exception.message, "Invalid version")
def test_decrypt_bad_version(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
self.m_input,
version='bogus',
key=self.m_key,
)
eq_(ex.exception.message, "Invalid version")
self.assertEqual(ex.exception.message, "Invalid version")
def test_decrypt_bad_header(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
os.urandom(4),
version='aes128gcm',
key=self.m_key,
)
eq_(ex.exception.message, "Could not parse the content header")
self.assertEqual(ex.exception.message, "Could not parse the content header")
def test_encrypt_long_keyid(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.encrypt(
self.m_input,
version='aes128gcm',
key=self.m_key,
keyid=b64e(os.urandom(192)), # 256 bytes
)
eq_(ex.exception.message, "keyid is too long")
self.assertEqual(ex.exception.message, "keyid is too long")
def test_overlong_padding(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
self.m_header + b'\xbb\xc7\xb9ev\x0b\xf0f+\x93\xf4'
b'\xe5\xd6\x94\xb7e\xf0\xcd\x15\x9b(\x01\xa5',
@ -207,10 +205,10 @@ class TestEceChecking(unittest.TestCase):
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
keyid=b64e(os.urandom(192)), # 256 bytes
)
eq_(ex.exception.message, "all zero record plaintext")
self.assertEqual(ex.exception.message, "all zero record plaintext")
def test_bad_early_delimiter(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
self.m_header + b'\xb9\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08C8u'
b'\xa3\x06\xc9x\x06\n\xfc|}\xe9R\x85\x91'
@ -221,10 +219,10 @@ class TestEceChecking(unittest.TestCase):
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
keyid=b64e(os.urandom(192)), # 256 bytes
)
eq_(ex.exception.message, "record delimiter != 1")
self.assertEqual(ex.exception.message, "record delimiter != 1")
def test_bad_final_delimiter(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
self.m_header + b'\xba\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08Ji'
b'\xe4P\x1b\x8dI\xdb\xc6y#MG\xc2W\x16',
@ -232,10 +230,10 @@ class TestEceChecking(unittest.TestCase):
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
keyid=b64e(os.urandom(192)), # 256 bytes
)
eq_(ex.exception.message, "last record delimiter != 2")
self.assertEqual(ex.exception.message, "last record delimiter != 2")
def test_damage(self):
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(
self.m_header + b'\xbb\xc6\xb1\x1dF:~\x0f\x07+\xbe\xaaD'
b'\xe0\xd6.K\xe5\xf9]%\xe3\x86q\xe0}',
@ -243,7 +241,7 @@ class TestEceChecking(unittest.TestCase):
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
keyid=b64e(os.urandom(192)), # 256 bytes
)
eq_(ex.exception.message, "Decryption error: InvalidTag()")
self.assertEqual(ex.exception.message, "Decryption error: InvalidTag()")
class TestEceIntegration(unittest.TestCase):
@ -315,7 +313,7 @@ class TestEceIntegration(unittest.TestCase):
decrypt_rs_default),
version=version)
logbuf("Decrypted", decrypted)
eq_(input, decrypted)
self.assertEqual(input, decrypted)
def use_explicit_key(self, version=None):
params = {
@ -353,9 +351,9 @@ class TestEceIntegration(unittest.TestCase):
chunk = encrypted[0:21+rs]
else:
chunk = encrypted[0:rs+16]
with assert_raises(ECEException) as ex:
with self.assertRaises(ECEException) as ex:
ece.decrypt(chunk, salt=salt, key=key, rs=rs, version=version)
eq_(ex.exception.message, "Message truncated")
self.assertEqual(ex.exception.message, "Message truncated")
def use_dh(self, version):
def pubbytes(k):
@ -493,7 +491,7 @@ class TestNode(unittest.TestCase):
rs=p.get('rs', 4096),
version=p['version'],
)
eq_(b64d(data[outp]), result)
self.assertEqual(b64d(data[outp]), result)
def test_decrypt(self):
self._run('decrypt')