aboutsummaryrefslogtreecommitdiffstats
path: root/tests/packager/test_utils.py
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2018-08-24 18:48:49 +0800
committerLianhao Lu <lianhao.lu@intel.com>2018-08-24 18:48:49 +0800
commita570b0bbe05295b469c975916faf19919c656cd2 (patch)
tree692c16ce232ffb3cbddfb518e2fe56d77672e00b /tests/packager/test_utils.py
parenta15a4bc165307623ca0870983cee746e5f761db8 (diff)
Added supporting functions for certificate
Added the supporting functions for sign and verify using certificate. Change-Id: Ic84e773d60c248963e63909cbdae3edd99bd5293 Issue-ID: VNFSDK-144 Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Diffstat (limited to 'tests/packager/test_utils.py')
-rw-r--r--tests/packager/test_utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/packager/test_utils.py b/tests/packager/test_utils.py
index 91fc72b..3124ea5 100644
--- a/tests/packager/test_utils.py
+++ b/tests/packager/test_utils.py
@@ -14,6 +14,9 @@
#
import os
+import subprocess
+
+import pytest
from vnfsdk_pkgtools.packager import utils
@@ -34,3 +37,26 @@ def test_cal_file_hash_remote(mocker):
self.content = CONTENT
mocker.patch('requests.get', new=FakeRequest)
assert SHA256 == utils.cal_file_hash("", "http://fake", 'sha256')
+
+
+MSG_FILE = "tests/resources/signature/manifest.mf"
+CERT_FILE = "tests/resources/signature/test.crt"
+KEY_FILE = "tests/resources/signature/test.key"
+
+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
+ assert "---BEGIN CMS---" in cms
+ assert "---END CMS---" in cms
+ utils.verify(MSG_FILE, CERT_FILE, cms, no_verify_cert=True)
+
+
+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)
+