Commit bc328ce0 authored by Łukasz Nowak's avatar Łukasz Nowak

Check behaviour in case of exists key or certificate.

parent ab16cfcc
...@@ -776,12 +776,14 @@ class GenerateSignatureScriptTest(unittest.TestCase): ...@@ -776,12 +776,14 @@ class GenerateSignatureScriptTest(unittest.TestCase):
self.certificate = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() self.certificate = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix()
+ str(random.random())) + str(random.random()))
self.common_name = str(random.random()) self.common_name = str(random.random())
self.key_exist = tempfile.NamedTemporaryFile(delete=False).name
self.certificate_exist = tempfile.NamedTemporaryFile(delete=False).name
def tearDown(self): def tearDown(self):
if os.path.exists(self.key): for f in [self.key, self.certificate, self.key_exist,
os.unlink(self.key) self.certificate_exist]:
if os.path.exists(self.certificate): if os.path.lexists(f):
os.unlink(self.certificate) os.unlink(f)
def test_generate_certificate(self): def test_generate_certificate(self):
slapos.signature.generateCertificate(self.certificate, self.key, slapos.signature.generateCertificate(self.certificate, self.key,
...@@ -789,3 +791,12 @@ class GenerateSignatureScriptTest(unittest.TestCase): ...@@ -789,3 +791,12 @@ class GenerateSignatureScriptTest(unittest.TestCase):
result = subprocess.check_output(['openssl', 'x509', '-noout', '-subject', result = subprocess.check_output(['openssl', 'x509', '-noout', '-subject',
'-in', self.certificate]) '-in', self.certificate])
self.assertEqual('subject= /CN=%s' % self.common_name, result.strip()) self.assertEqual('subject= /CN=%s' % self.common_name, result.strip())
def test_generate_key_exists(self):
self.assertRaises(ValueError, slapos.signature.generateCertificate,
self.certificate, self.key_exist, self.common_name)
def test_generate_cert_exists(self):
self.assertRaises(ValueError, slapos.signature.generateCertificate,
self.certificate_exist, self.key, self.common_name)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment