1
1
"""
2
- SoftLayer.tests.CLI.modules.sshkey_tests
2
+ SoftLayer.tests.CLI.modules.security_tests
3
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
5
5
:license: MIT, see LICENSE for more details.
15
15
from SoftLayer import testing
16
16
17
17
18
- class SshKeyTests (testing .TestCase ):
19
- def test_add_without_key_errors (self ):
20
- result = self .run_command (['sshkey ' , 'add' , 'key1' ])
18
+ class SecurityTests (testing .TestCase ):
19
+ def test_add_sshkey_without_key_errors (self ):
20
+ result = self .run_command (['security ' , 'sshkey- add' , 'key1' ])
21
21
22
22
self .assertEqual (result .exit_code , 2 )
23
23
self .assertIsInstance (result .exception , exceptions .ArgumentError )
24
24
25
- def test_add_with_key_file_and_key_argument_errors (self ):
25
+ def test_add_sshkey_with_key_file_and_key_argument_errors (self ):
26
26
path = os .path .join (testing .FIXTURE_PATH , 'id_rsa.pub' )
27
- result = self .run_command (['sshkey ' , 'add' , 'key1' ,
27
+ result = self .run_command (['security ' , 'sshkey- add' , 'key1' ,
28
28
'--key=some_key' ,
29
29
'--in-file=%s' % path ])
30
30
31
31
self .assertEqual (result .exit_code , 2 )
32
32
self .assertIsInstance (result .exception , exceptions .ArgumentError )
33
33
34
- def test_add_by_option (self ):
34
+ def test_add_sshkey_by_option (self ):
35
35
service = self .client ['Security_Ssh_Key' ]
36
36
mock_key = service .getObject ()['key' ]
37
37
38
- result = self .run_command (['sshkey ' , 'add' , 'key1' ,
38
+ result = self .run_command (['security ' , 'sshkey- add' , 'key1' ,
39
39
'--key=%s' % mock_key ,
40
40
'--note=my key' ])
41
41
@@ -47,10 +47,10 @@ def test_add_by_option(self):
47
47
'key' : mock_key ,
48
48
'label' : 'key1' },))
49
49
50
- def test_add_by_file (self ):
50
+ def test_add_sshkey_by_file (self ):
51
51
path = os .path .join (testing .FIXTURE_PATH , 'id_rsa.pub' )
52
52
53
- result = self .run_command (['sshkey ' , 'add' , 'key1' ,
53
+ result = self .run_command (['security ' , 'sshkey- add' , 'key1' ,
54
54
'--in-file=%s' % path ])
55
55
56
56
self .assert_no_fail (result )
@@ -63,22 +63,22 @@ def test_add_by_file(self):
63
63
'key' : mock_key ,
64
64
'label' : 'key1' },))
65
65
66
- def test_remove_key (self ):
67
- result = self .run_command (['--really' , 'sshkey ' , 'remove' , '1234' ])
66
+ def test_remove_sshkey_key (self ):
67
+ result = self .run_command (['--really' , 'security ' , 'sshkey- remove' , '1234' ])
68
68
69
69
self .assert_no_fail (result )
70
70
self .assert_called_with ('SoftLayer_Security_Ssh_Key' , 'deleteObject' ,
71
71
identifier = 1234 )
72
72
73
73
@mock .patch ('SoftLayer.CLI.formatting.no_going_back' )
74
- def test_remove_key_fail (self , ngb_mock ):
74
+ def test_remove_sshkey_fail (self , ngb_mock ):
75
75
ngb_mock .return_value = False
76
- result = self .run_command (['sshkey ' , 'remove' , '1234' ])
76
+ result = self .run_command (['security ' , 'sshkey- remove' , '1234' ])
77
77
78
78
self .assertEqual (result .exit_code , 2 )
79
79
80
- def test_edit_key (self ):
81
- result = self .run_command (['sshkey ' , 'edit' , '1234' ,
80
+ def test_edit_sshkey (self ):
81
+ result = self .run_command (['security ' , 'sshkey- edit' , '1234' ,
82
82
'--label=key1' , '--note=my key' ])
83
83
84
84
self .assert_no_fail (result )
@@ -87,17 +87,17 @@ def test_edit_key(self):
87
87
'label' : 'key1' },),
88
88
identifier = 1234 )
89
89
90
- def test_edit_key_fail (self ):
90
+ def test_edit_sshkey_fail (self ):
91
91
fixture = self .set_mock ('SoftLayer_Security_Ssh_Key' , 'editObject' )
92
92
fixture .return_value = False
93
93
94
- result = self .run_command (['sshkey ' , 'edit' , '1234' ,
94
+ result = self .run_command (['security ' , 'sshkey- edit' , '1234' ,
95
95
'--label=key1' , '--note=my key' ])
96
96
97
97
self .assertEqual (result .exit_code , 2 )
98
98
99
- def test_list_keys (self ):
100
- result = self .run_command (['sshkey ' , 'list' ])
99
+ def test_list_sshkeys (self ):
100
+ result = self .run_command (['security ' , 'sshkey- list' ])
101
101
102
102
self .assert_no_fail (result )
103
103
self .assertEqual (json .loads (result .output ),
@@ -110,21 +110,45 @@ def test_list_keys(self):
110
110
'id' : '101' ,
111
111
'label' : 'Test 2' }])
112
112
113
- def test_print_key (self ):
114
- result = self .run_command (['sshkey ' , 'print' , '1234' ])
113
+ def test_print_sshkey (self ):
114
+ result = self .run_command (['security ' , 'sshkey- print' , '1234' ])
115
115
116
116
self .assert_no_fail (result )
117
117
self .assertEqual (json .loads (result .output ),
118
118
{'id' : 1234 , 'label' : 'label' , 'notes' : 'notes' })
119
119
120
- def test_print_key_file (self ):
120
+ def test_print_sshkey_file (self ):
121
121
if sys .platform .startswith ("win" ):
122
122
self .skipTest ("Test doesn't work in Windows" )
123
123
with tempfile .NamedTemporaryFile () as sshkey_file :
124
124
service = self .client ['Security_Ssh_Key' ]
125
125
mock_key = service .getObject ()['key' ]
126
- result = self .run_command (['sshkey ' , 'print' , '1234' ,
126
+ result = self .run_command (['security ' , 'sshkey- print' , '1234' ,
127
127
'--out-file=%s' % sshkey_file .name ])
128
128
129
129
self .assert_no_fail (result )
130
130
self .assertEqual (mock_key , sshkey_file .read ().decode ("utf-8" ))
131
+
132
+ def test_list_certficates (self ):
133
+ result = self .run_command (['security' , 'cert-list' , '--status' , 'all' ])
134
+ self .assert_no_fail (result )
135
+ self .assertEqual (json .loads (result .output ), [
136
+ {
137
+ "id" : 1234 ,
138
+ "common_name" : "cert" ,
139
+ "days_until_expire" : 0 ,
140
+ "notes" : None
141
+ }
142
+ ])
143
+
144
+ @mock .patch ('SoftLayer.CLI.formatting.no_going_back' )
145
+ def test_remove_certficate (self , confirm_mock ):
146
+ confirm_mock .return_value = True
147
+ result = self .run_command (['security' , 'cert-remove' , '123456' ])
148
+ self .assert_no_fail (result )
149
+ self .assertEqual (result .exit_code , 0 )
150
+
151
+ def test_download_certficate (self ):
152
+ result = self .run_command (['security' , 'cert-download' , '123456' ])
153
+ self .assert_no_fail (result )
154
+ self .assertEqual (result .exit_code , 0 )
0 commit comments