Commit c6f62c94 authored by Lucas Carvalho's avatar Lucas Carvalho

Added tests to signature.py.

parent a4eed283
import unittest import unittest
from slapos.libnetworkcache import NetworkcacheClient
import tempfile import tempfile
import os
from slapos.libnetworkcache import NetworkcacheClient
from slapos.signature import parseArgument, \
createPrivateKeyAndCertificateFile
class OfflineTest(unittest.TestCase): class OfflineTest(unittest.TestCase):
def test_download_offline(self): def test_download_offline(self):
...@@ -11,3 +14,65 @@ class OfflineTest(unittest.TestCase): ...@@ -11,3 +14,65 @@ class OfflineTest(unittest.TestCase):
content = tempfile.TemporaryFile() content = tempfile.TemporaryFile()
nc = NetworkcacheClient('http://127.0.0.1:0', 'http://127.0.0.1:0') nc = NetworkcacheClient('http://127.0.0.1:0', 'http://127.0.0.1:0')
self.assertRaises(IOError, nc.upload, content) self.assertRaises(IOError, nc.upload, content)
class GenerateSignatureScriptTest(unittest.TestCase):
''' Class which must test the signature.py script. '''
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.arg_list = ('--signature-public-file', self.signature_certificate_file,
'--signature-private-file', self.signature_private_key_file,
'--country', 'BR, aze, AEAZE, ZEAZE',
'--state-name', 'Campos',
'--locality-name', 'Rio de Janeiro',
'--organization-name', 'Nexedi',
'--organization-unit-name', 'Dev',
'--common-name', 'R500.com',
'--email', 'test@example.com')
def tearDown(self):
''' Remove the files which have been created during the test. '''
self.priv_file_descritor.close()
self.pub_file_descriptor.close()
def test_parse_argument_with_empty_list(self):
'''
If the argument list is empty, then the parseArgument method should
return a dictionary with default argument values.
'''
default_dict = {'organization_name': 'Default Company Ltd',
'state_name': 'Default Province',
'organization_unit_name': '',
'common_name': '',
'country': 'XX',
'locality_name': 'Default City',
'signature_private_key_file': 'private.pem',
'signature_certificate_file': 'public.pem',
'email': ''}
self.assertEquals(default_dict, parseArgument())
def test_parse_argument(self):
'''
Check if the argument is properly set.
'''
option_dict = parseArgument(*self.arg_list)
self.assertEquals(len(self.arg_list)/2, len(option_dict))
for value in option_dict.values():
self.assertTrue(value in self.arg_list, '%s is not in %s.' %
(value, self.arg_list))
def test_key_and_certificate_file_creation(self):
'''
Check if key file and the certificate file are being created correctly.
'''
option_dict = parseArgument(*self.arg_list)
cert_as_text = createPrivateKeyAndCertificateFile(**option_dict)
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