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

Follow changes in test.

parent 6e0205fc
...@@ -9,6 +9,7 @@ import random ...@@ -9,6 +9,7 @@ import random
import shutil import shutil
import socket import socket
import ssl import ssl
import subprocess
import tempfile import tempfile
import threading import threading
import time import time
...@@ -767,71 +768,22 @@ class OnlineTestWrongChecksum(OnlineMixin, unittest.TestCase): ...@@ -767,71 +768,22 @@ class OnlineTestWrongChecksum(OnlineMixin, unittest.TestCase):
self.test_data) self.test_data)
class LibNetworkCacheMixin(unittest.TestCase): class GenerateSignatureScriptTest(unittest.TestCase):
def setUp(self):
''' Setup the test. '''
self.pub_file_descriptor = tempfile.NamedTemporaryFile()
self.priv_file_descritor = tempfile.NamedTemporaryFile()
self.signature_certificate_file = self.pub_file_descriptor.name
self.signature_private_key_file = self.priv_file_descritor.name
self.signature_creation_argument_list = \
('--signature-certificate-file', self.signature_certificate_file,
'--signature-private-key-file', self.signature_private_key_file,
'--country', 'BR',
'--state-name', 'Campos',
'--locality-name', 'Rio de Janeiro',
'--organization-name', 'Nexedi',
'--organization-unit-name', 'Dev',
'--common-name', 'R500.com',
'--email', 'test@example.com')
self.option_dict = slapos.signature.parseArgument(
*self.signature_creation_argument_list)
self.cert_as_text = slapos.signature.createPrivateKeyAndCertificateFile(
**self.option_dict)
def tearDown(self):
''' Remove the files which have been created during the test. '''
self.priv_file_descritor.close()
self.pub_file_descriptor.close()
class GenerateSignatureScriptTest(LibNetworkCacheMixin):
''' Class which must test the signature.py script. ''' ''' Class which must test the signature.py script. '''
def test_generate_certificate(self):
key = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() +
str(random.random()))
certificate = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix()
+ str(random.random()))
common_name = str(random.random())
def test_parse_argument_with_empty_list(self): try:
''' slapos.signature.generateCertificate(certificate, key, common_name)
If the argument list is empty, then the parseArgument method should result = subprocess.check_output(['openssl', 'x509', '-noout', '-subject', '-in',
return a dictionary with default argument values. certificate])
''' self.assertEqual('subject= /CN=%s' % common_name, result.strip())
default_dict = {'organization_name': 'Default Company Ltd', finally:
'state_name': 'Default Province', if os.path.exists(key):
'organization_unit_name': '', os.unlink(key)
'common_name': '', if os.path.exists(certificate):
'country': 'XX', os.unlink(certificate)
'locality_name': 'Default City',
'signature_private_key_file': 'private.pem',
'signature_certificate_file': 'public.pem',
'email': ''}
self.assertEquals(default_dict, slapos.signature.parseArgument())
def test_parse_argument(self):
'''
Check if the argument is properly set.
'''
size_argument_list = len(self.signature_creation_argument_list) / 2
size_option_dict = len(self.option_dict)
self.assertEquals(size_argument_list, size_option_dict,
"Argument list should have the same size of option dict.")
# Assert if the values are equals.
for value in self.option_dict.values():
self.assertTrue(value in self.signature_creation_argument_list,\
'%s is not in %s.' % (value, self.signature_creation_argument_list))
def test_key_and_certificate_file_creation(self):
'''
Check if key file and the certificate file are being created correctly.
'''
self.assertTrue(os.path.exists(self.signature_certificate_file))
self.assertTrue(os.path.exists(self.signature_private_key_file))
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