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>
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 @@
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)
+