diff options
Diffstat (limited to 'tests/packager/test_utils.py')
-rw-r--r-- | tests/packager/test_utils.py | 116 |
1 files changed, 55 insertions, 61 deletions
diff --git a/tests/packager/test_utils.py b/tests/packager/test_utils.py index 450a526..8c504e4 100644 --- a/tests/packager/test_utils.py +++ b/tests/packager/test_utils.py @@ -22,22 +22,24 @@ from vnfsdk_pkgtools.packager import utils from vnfsdk_pkgtools import util ROOT_DIR = util.get_project_root() -RESOURCES_DIR= os.path.join(ROOT_DIR, 'tests', 'resources', 'signature') +RESOURCES_DIR = os.path.join(ROOT_DIR, 'tests', 'resources', 'signature') -MSG_FILE = os.path.join(RESOURCES_DIR, 'manifest.mf') +MSG_FILE = os.path.join(RESOURCES_DIR, 'manifest.mf') CERT_FILE = os.path.join(RESOURCES_DIR, 'test.crt') -KEY_FILE = os.path.join(RESOURCES_DIR, 'test.key') +KEY_FILE = os.path.join(RESOURCES_DIR, 'test.key') CONTENT = b"needToBeHashed" SHA256 = "20a480339aa4371099f9503511dcc5a8051ce3884846678ced5611ec64bbfc9c" SHA512 = "dbed8672e752d51d0c7ca42050f67faf1534e58470bba96e787df5c4cf6a4f8ecf7ad45fb9307adbc5b9dec8432627d86b3eb1d3d43ee9c5e93f754ff2825320" + def test_cal_file_hash(tmpdir): p = tmpdir.join("file_to_hash.txt") p.write(CONTENT) assert SHA512 == utils.cal_file_hash("", str(p), 'SHA512') assert SHA256 == utils.cal_file_hash(p.dirname, p.basename, 'sha256') + def test_cal_file_hash_remote(mocker): class FakeRequest(object): def __init__(self, *args): @@ -46,6 +48,7 @@ def test_cal_file_hash_remote(mocker): mocker.patch('requests.get', new=FakeRequest) assert SHA256 == utils.cal_file_hash("", "http://fake", 'sha256') + def test_sign_verify_pairwise(): cms = utils.sign(MSG_FILE, CERT_FILE, KEY_FILE) # We can't examine the exact content of cms because it contains timestamp @@ -56,70 +59,61 @@ def test_sign_verify_pairwise(): def test_verify_bad(tmpdir): cms = utils.sign(MSG_FILE, CERT_FILE, KEY_FILE) - p = tmpdir.join("file_msg.txt") p.write("BAD") - with pytest.raises(subprocess.CalledProcessError): utils.verify(str(p), CERT_FILE, cms, no_verify_cert=True) -CHECK_FILE_CASES = [ - { - 'negative': False, - 'params': {'root': RESOURCES_DIR, - 'entry': 'test.key', - 'msg': '', - 'check_for_non': False, - 'check_dir': False, - } - }, - { - 'negative': False, - 'params': {'root': RESOURCES_DIR, - 'entry': 'non-existing-file', - 'msg': '', - 'check_for_non': True, - 'check_dir': False, - } - }, - { - 'negative': True, - 'params': {'root': RESOURCES_DIR, - 'entry': 'non-existing-file', - 'msg': '', - 'check_for_non': False, - 'check_dir': False, - } - }, - { - 'negative': False, - 'params': {'root': ROOT_DIR, - 'entry': 'tests', - 'msg': '', - 'check_for_non': False, - 'check_dir': True, - } - }, - { - 'negative': False, - 'params': {'root': ROOT_DIR, - 'entry': 'non-existing-dir', - 'msg': '', - 'check_for_non': True, - 'check_dir': True, - } - }, - { - 'negative': True, - 'params': {'root': ROOT_DIR, - 'entry': 'non-existing-dir', - 'msg': '', - 'check_for_non': False, - 'check_dir': True, - } - }, - ] +CHECK_FILE_CASES = [{'negative': False, + 'params': {'root': RESOURCES_DIR, + 'entry': 'test.key', + 'msg': '', + 'check_for_non': False, + 'check_dir': False, + }, + }, + {'negative': False, + 'params': {'root': RESOURCES_DIR, + 'entry': 'non-existing-file', + 'msg': '', + 'check_for_non': True, + 'check_dir': False, + } + }, + {'negative': True, + 'params': {'root': RESOURCES_DIR, + 'entry': 'non-existing-file', + 'msg': '', + 'check_for_non': False, + 'check_dir': False, + } + }, + {'negative': False, + 'params': {'root': ROOT_DIR, + 'entry': 'tests', + 'msg': '', + 'check_for_non': False, + 'check_dir': True, + } + }, + {'negative': False, + 'params': {'root': ROOT_DIR, + 'entry': 'non-existing-dir', + 'msg': '', + 'check_for_non': True, + 'check_dir': True, + } + }, + {'negative': True, + 'params': {'root': ROOT_DIR, + 'entry': 'non-existing-dir', + 'msg': '', + 'check_for_non': False, + 'check_dir': True, + } + }, + ] def test_check_file_dir(): |