@@ -9,11 +9,13 @@ class TestEdgeSSL(base_edge.BaseEdgeTest):
99
1010 def setUp (self ):
1111 super ().setUp ()
12- self ._private_key = './certs/private.key'
12+ self ._key_filepath = './certs/private.key'
1313 self ._domain_cert = './certs/certificate.crt'
14- self ._intermediate = './certs/intermediate.crt'
15- self ._ca = './certs/ca.crt'
16- self ._certificate = ssl .SSL .BEGIN_PEM
14+ self ._intermediate_cert = './certs/intermediate.crt'
15+ self ._root_cert = './certs/ca.crt'
16+
17+ self ._private_key_contents = 'private_key'
18+ self ._certificate_contents = 'certificate'
1719
1820 def test_is_http_disabled_true (self ):
1921 get_response = True
@@ -53,14 +55,30 @@ def test_disable_http(self):
5355 ssl .SSL (self ._filer ).disable_http ()
5456 self ._filer .put .assert_called_once_with ('/config/fileservices/webdav/forceHttps' , True )
5557
56- def test_set_certificate (self ):
57- data = 'data\n '
58- self ._init_filer ()
59- self .patch_call ("cterasdk.edge.ssl.FileSystem.get_local_file_info" )
60- mock_open = mock .mock_open (read_data = data )
61- with mock .patch ("builtins.open" , mock_open ):
62- ssl .SSL (self ._filer ).set_certificate (self ._private_key , self ._domain_cert , self ._intermediate , self ._ca )
63- self ._filer .put .assert_called_once_with ('/config/certificate' , '\n ' + data * 4 )
58+ def test_import_certificate (self ):
59+ put_response = 'Success'
60+ self ._init_filer (put_response = put_response )
61+ mock_load_private_key = self .patch_call ("cterasdk.lib.crypto.PrivateKey.load_private_key" )
62+ mock_load_private_key .return_value = TestEdgeSSL ._get_secret (self ._private_key_contents )
63+ mock_load_certificate = self .patch_call ("cterasdk.lib.crypto.X509Certificate.load_certificate" )
64+ mock_load_certificate .return_value = TestEdgeSSL ._get_secret (self ._certificate_contents )
65+ ret = ssl .SSL (self ._filer ).import_certificate (self ._key_filepath , self ._domain_cert , self ._intermediate_cert , self ._root_cert )
66+ mock_load_private_key .assert_called_once_with (self ._key_filepath )
67+ mock_load_certificate .assert_has_calls (
68+ [
69+ mock .call (self ._domain_cert ),
70+ mock .call (self ._intermediate_cert ),
71+ mock .call (self ._root_cert ),
72+ ]
73+ )
74+ expected_param = '' .join ([
75+ self ._private_key_contents ,
76+ self ._certificate_contents ,
77+ self ._certificate_contents ,
78+ self ._certificate_contents
79+ ])
80+ self ._filer .put .assert_called_once_with ('/config/certificate' , '\n {}' .format (expected_param ))
81+ self .assertEqual (ret , put_response )
6482
6583 def test_get_storage_ca (self ):
6684 get_response = 'Success'
@@ -69,13 +87,16 @@ def test_get_storage_ca(self):
6987 self ._filer .get .assert_called_once_with ('/status/extStorageTrustedCA' )
7088 self .assertEqual (ret , get_response )
7189
72- def test_set_storage_ca (self ):
90+ def test_import_storage_ca (self ):
7391 put_response = 'Success'
7492 self ._init_filer (put_response = put_response )
75- ret = ssl .SSL (self ._filer ).set_storage_ca (self ._certificate )
93+ mock_load_certificate = self .patch_call ("cterasdk.lib.crypto.X509Certificate.load_certificate" )
94+ mock_load_certificate .return_value = TestEdgeSSL ._get_secret (self ._certificate_contents )
95+ ret = ssl .SSL (self ._filer ).import_storage_ca (self ._domain_cert )
7696 expected_param = Object ()
7797 expected_param ._classname = 'ExtTrustedCA' # pylint: disable=protected-access
78- expected_param .certificate = self ._certificate
98+ expected_param .certificate = self ._certificate_contents
99+ mock_load_certificate .assert_called_once_with (self ._domain_cert )
79100 self ._filer .put .assert_called_once_with ('/config/extStorageTrustedCA' , mock .ANY )
80101 actual_param = self ._filer .put .call_args [0 ][1 ]
81102 self ._assert_equal_objects (actual_param , expected_param )
@@ -86,3 +107,11 @@ def test_remove_storage_ca(self):
86107 self ._init_filer (put_response = put_response )
87108 ssl .SSL (self ._filer ).remove_storage_ca ()
88109 self ._filer .put .assert_called_once_with ('/config/extStorageTrustedCA' , None )
110+
111+ @staticmethod
112+ def _get_secret (secret ):
113+ param = Object ()
114+ param .pem_data = secret .encode ('utf-8' )
115+ param .subject = 'subject'
116+ param .issuer = 'issuer'
117+ return param
0 commit comments