- 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:
parent
c47aae39d0
commit
09d98b1b74
@ -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>
|
Sun Jun 7 05:57:06 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package python-http-ece
|
# 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
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@ -35,7 +35,7 @@ BuildArch: noarch
|
|||||||
# SECTION test requirements
|
# SECTION test requirements
|
||||||
BuildRequires: %{python_module cryptography >= 2.5}
|
BuildRequires: %{python_module cryptography >= 2.5}
|
||||||
BuildRequires: %{python_module mock}
|
BuildRequires: %{python_module mock}
|
||||||
BuildRequires: %{python_module nose}
|
BuildRequires: %{python_module pytest}
|
||||||
# /SECTION
|
# /SECTION
|
||||||
%python_subpackages
|
%python_subpackages
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ cp %{SOURCE1} %{SOURCE2} .
|
|||||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||||
|
|
||||||
%check
|
%check
|
||||||
%python_exec -m nose
|
%pytest
|
||||||
|
|
||||||
%files %{python_files}
|
%files %{python_files}
|
||||||
%doc README.rst
|
%doc README.rst
|
||||||
|
74
test_ece.py
74
test_ece.py
@ -9,8 +9,6 @@ from cryptography.hazmat.primitives.serialization import (
|
|||||||
Encoding, PublicFormat
|
Encoding, PublicFormat
|
||||||
)
|
)
|
||||||
|
|
||||||
from nose.tools import eq_, assert_raises
|
|
||||||
|
|
||||||
import http_ece as ece
|
import http_ece as ece
|
||||||
from http_ece import ECEException
|
from http_ece import ECEException
|
||||||
|
|
||||||
@ -60,7 +58,7 @@ class TestEce(unittest.TestCase):
|
|||||||
self.m_salt = os.urandom(16)
|
self.m_salt = os.urandom(16)
|
||||||
|
|
||||||
def test_derive_key_invalid_mode(self):
|
def test_derive_key_invalid_mode(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.derive_key('invalid',
|
ece.derive_key('invalid',
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
salt=self.m_salt,
|
salt=self.m_salt,
|
||||||
@ -70,10 +68,10 @@ class TestEce(unittest.TestCase):
|
|||||||
auth_secret=None,
|
auth_secret=None,
|
||||||
keyid="valid",
|
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):
|
def test_derive_key_invalid_salt(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.derive_key('encrypt',
|
ece.derive_key('encrypt',
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
salt=None,
|
salt=None,
|
||||||
@ -83,10 +81,10 @@ class TestEce(unittest.TestCase):
|
|||||||
auth_secret=None,
|
auth_secret=None,
|
||||||
keyid="valid",
|
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):
|
def test_derive_key_invalid_version(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.derive_key('encrypt',
|
ece.derive_key('encrypt',
|
||||||
version='invalid',
|
version='invalid',
|
||||||
salt=self.m_salt,
|
salt=self.m_salt,
|
||||||
@ -96,10 +94,10 @@ class TestEce(unittest.TestCase):
|
|||||||
auth_secret=None,
|
auth_secret=None,
|
||||||
keyid="valid",
|
keyid="valid",
|
||||||
)
|
)
|
||||||
eq_(ex.exception.message, "Invalid version")
|
self.assertEqual(ex.exception.message, "Invalid version")
|
||||||
|
|
||||||
def test_derive_key_no_private_key(self):
|
def test_derive_key_no_private_key(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.derive_key('encrypt',
|
ece.derive_key('encrypt',
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
salt=self.m_salt,
|
salt=self.m_salt,
|
||||||
@ -109,10 +107,10 @@ class TestEce(unittest.TestCase):
|
|||||||
auth_secret=None,
|
auth_secret=None,
|
||||||
keyid="valid",
|
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):
|
def test_derive_key_no_secret(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.derive_key('encrypt',
|
ece.derive_key('encrypt',
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
salt=self.m_salt,
|
salt=self.m_salt,
|
||||||
@ -122,12 +120,12 @@ class TestEce(unittest.TestCase):
|
|||||||
auth_secret=None,
|
auth_secret=None,
|
||||||
keyid="valid",
|
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):
|
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)
|
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):
|
class TestEceChecking(unittest.TestCase):
|
||||||
@ -141,65 +139,65 @@ class TestEceChecking(unittest.TestCase):
|
|||||||
self.m_header += struct.pack('!L', 32) + b'\0'
|
self.m_header += struct.pack('!L', 32) + b'\0'
|
||||||
|
|
||||||
def test_encrypt_small_rs(self):
|
def test_encrypt_small_rs(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.encrypt(
|
ece.encrypt(
|
||||||
self.m_input,
|
self.m_input,
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
key=self.m_key,
|
key=self.m_key,
|
||||||
rs=1,
|
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):
|
def test_decrypt_small_rs(self):
|
||||||
header = os.urandom(16) + struct.pack('!L', 2) + b'\0'
|
header = os.urandom(16) + struct.pack('!L', 2) + b'\0'
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
header + self.m_input,
|
header + self.m_input,
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
key=self.m_key,
|
key=self.m_key,
|
||||||
rs=1,
|
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):
|
def test_encrypt_bad_version(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.encrypt(
|
ece.encrypt(
|
||||||
self.m_input,
|
self.m_input,
|
||||||
version='bogus',
|
version='bogus',
|
||||||
key=self.m_key,
|
key=self.m_key,
|
||||||
)
|
)
|
||||||
eq_(ex.exception.message, "Invalid version")
|
self.assertEqual(ex.exception.message, "Invalid version")
|
||||||
|
|
||||||
def test_decrypt_bad_version(self):
|
def test_decrypt_bad_version(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
self.m_input,
|
self.m_input,
|
||||||
version='bogus',
|
version='bogus',
|
||||||
key=self.m_key,
|
key=self.m_key,
|
||||||
)
|
)
|
||||||
eq_(ex.exception.message, "Invalid version")
|
self.assertEqual(ex.exception.message, "Invalid version")
|
||||||
|
|
||||||
def test_decrypt_bad_header(self):
|
def test_decrypt_bad_header(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
os.urandom(4),
|
os.urandom(4),
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
key=self.m_key,
|
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):
|
def test_encrypt_long_keyid(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.encrypt(
|
ece.encrypt(
|
||||||
self.m_input,
|
self.m_input,
|
||||||
version='aes128gcm',
|
version='aes128gcm',
|
||||||
key=self.m_key,
|
key=self.m_key,
|
||||||
keyid=b64e(os.urandom(192)), # 256 bytes
|
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):
|
def test_overlong_padding(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
self.m_header + b'\xbb\xc7\xb9ev\x0b\xf0f+\x93\xf4'
|
self.m_header + b'\xbb\xc7\xb9ev\x0b\xf0f+\x93\xf4'
|
||||||
b'\xe5\xd6\x94\xb7e\xf0\xcd\x15\x9b(\x01\xa5',
|
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',
|
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
|
||||||
keyid=b64e(os.urandom(192)), # 256 bytes
|
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):
|
def test_bad_early_delimiter(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
self.m_header + b'\xb9\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08C8u'
|
self.m_header + b'\xb9\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08C8u'
|
||||||
b'\xa3\x06\xc9x\x06\n\xfc|}\xe9R\x85\x91'
|
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',
|
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
|
||||||
keyid=b64e(os.urandom(192)), # 256 bytes
|
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):
|
def test_bad_final_delimiter(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
self.m_header + b'\xba\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08Ji'
|
self.m_header + b'\xba\xc7\xb9ev\x0b\xf0\x9eB\xb1\x08Ji'
|
||||||
b'\xe4P\x1b\x8dI\xdb\xc6y#MG\xc2W\x16',
|
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',
|
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
|
||||||
keyid=b64e(os.urandom(192)), # 256 bytes
|
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):
|
def test_damage(self):
|
||||||
with assert_raises(ECEException) as ex:
|
with self.assertRaises(ECEException) as ex:
|
||||||
ece.decrypt(
|
ece.decrypt(
|
||||||
self.m_header + b'\xbb\xc6\xb1\x1dF:~\x0f\x07+\xbe\xaaD'
|
self.m_header + b'\xbb\xc6\xb1\x1dF:~\x0f\x07+\xbe\xaaD'
|
||||||
b'\xe0\xd6.K\xe5\xf9]%\xe3\x86q\xe0}',
|
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',
|
key=b'd\xc7\x0ed\xa7%U\x14Q\xf2\x08\xdf\xba\xa0\xb9r',
|
||||||
keyid=b64e(os.urandom(192)), # 256 bytes
|
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):
|
class TestEceIntegration(unittest.TestCase):
|
||||||
@ -315,7 +313,7 @@ class TestEceIntegration(unittest.TestCase):
|
|||||||
decrypt_rs_default),
|
decrypt_rs_default),
|
||||||
version=version)
|
version=version)
|
||||||
logbuf("Decrypted", decrypted)
|
logbuf("Decrypted", decrypted)
|
||||||
eq_(input, decrypted)
|
self.assertEqual(input, decrypted)
|
||||||
|
|
||||||
def use_explicit_key(self, version=None):
|
def use_explicit_key(self, version=None):
|
||||||
params = {
|
params = {
|
||||||
@ -353,9 +351,9 @@ class TestEceIntegration(unittest.TestCase):
|
|||||||
chunk = encrypted[0:21+rs]
|
chunk = encrypted[0:21+rs]
|
||||||
else:
|
else:
|
||||||
chunk = encrypted[0:rs+16]
|
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)
|
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 use_dh(self, version):
|
||||||
def pubbytes(k):
|
def pubbytes(k):
|
||||||
@ -493,7 +491,7 @@ class TestNode(unittest.TestCase):
|
|||||||
rs=p.get('rs', 4096),
|
rs=p.get('rs', 4096),
|
||||||
version=p['version'],
|
version=p['version'],
|
||||||
)
|
)
|
||||||
eq_(b64d(data[outp]), result)
|
self.assertEqual(b64d(data[outp]), result)
|
||||||
|
|
||||||
def test_decrypt(self):
|
def test_decrypt(self):
|
||||||
self._run('decrypt')
|
self._run('decrypt')
|
||||||
|
Loading…
Reference in New Issue
Block a user