44
55"""
66
7- import sys
8- import unittest
9-
10- from sshpubkeys import AuthorizedKeysFile , InvalidOptionsError , SSHKey
11-
127from .authorized_keys import items as list_of_authorized_keys
138from .invalid_authorized_keys import items as list_of_invalid_authorized_keys
149from .invalid_keys import keys as list_of_invalid_keys
1510from .invalid_options import options as list_of_invalid_options
1611from .valid_keys import keys as list_of_valid_keys
1712from .valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
1813from .valid_options import options as list_of_valid_options
14+ from sshpubkeys import AuthorizedKeysFile , InvalidOptionsError , SSHKey
15+
16+ import sys
17+ import unittest
1918
2019if sys .version_info .major == 2 :
2120 from io import BytesIO as StringIO
2221else :
2322 from io import StringIO
2423
25-
2624DEFAULT_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEGODBKRjsFB/1v3pDRGpA6xR+QpOJg9vat0brlbUNDD"
2725
2826
2927class TestMisc (unittest .TestCase ):
30-
3128 def test_none_to_constructor (self ):
3229 ssh = SSHKey (None )
3330 self .assertEqual (None , ssh .keydata ) # Python2.6 does not have assertIsNone
3431 self .assertRaises (ValueError , ssh .parse )
3532
3633
3734class TestKeys (unittest .TestCase ):
38-
3935 def check_key (self , pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment , ** kwargs ): # pylint:disable=too-many-arguments
4036 """ Checks valid key """
4137 ssh = SSHKey (pubkey , ** kwargs )
@@ -55,7 +51,6 @@ def check_fail(self, pubkey, expected_error, **kwargs):
5551
5652
5753class TestOptions (unittest .TestCase ):
58-
5954 def check_valid_option (self , option , parsed_option ):
6055 ssh = SSHKey ()
6156 parsed = ssh .parse_options (option )
@@ -72,7 +67,6 @@ def test_disallow_options(self):
7267
7368
7469class TestAuthorizedKeys (unittest .TestCase ):
75-
7670 def check_valid_file (self , file_str , valid_keys_count ):
7771 file_obj = StringIO (file_str )
7872 key_file = AuthorizedKeysFile (file_obj )
@@ -94,8 +88,10 @@ def test_disallow_options(self):
9488
9589def loop_options (options ):
9690 """ Loop over list of options and dynamically create tests """
91+
9792 def ch (option , parsed_option ):
9893 return lambda self : self .check_valid_option (option , parsed_option )
94+
9995 for i , items in enumerate (options ):
10096 prefix_tmp = "%s_%s" % (items [0 ], i )
10197 setattr (TestOptions , "test_%s" % prefix_tmp , ch (items [1 ], items [2 ]))
@@ -104,15 +100,18 @@ def ch(option, parsed_option):
104100def loop_invalid_options (options ):
105101 def ch (option , expected_error ):
106102 return lambda self : self .check_invalid_option (option , expected_error )
103+
107104 for i , items in enumerate (options ):
108105 prefix_tmp = "%s_%s" % (items [0 ], i )
109106 setattr (TestOptions , "test_%s" % prefix_tmp , ch (items [1 ], items [2 ]))
110107
111108
112109def loop_valid (keyset , prefix ):
113110 """ Loop over list of valid keys and dynamically create tests """
111+
114112 def ch (pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment , ** kwargs ): # pylint:disable=too-many-arguments
115113 return lambda self : self .check_key (pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment , ** kwargs )
114+
116115 for items in keyset :
117116 modes = items .pop ()
118117 prefix_tmp = "%s_%s" % (prefix , items .pop ())
@@ -126,13 +125,18 @@ def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kw
126125 options = comment = None
127126 else :
128127 pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment = items
129- setattr (TestKeys , "test_%s_mode_%s" % (prefix_tmp , mode ), ch (pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment , ** kwargs ))
128+ setattr (
129+ TestKeys , "test_%s_mode_%s" % (prefix_tmp , mode ),
130+ ch (pubkey , bits , fingerprint_md5 , fingerprint_sha256 , options , comment , ** kwargs )
131+ )
130132
131133
132134def loop_invalid (keyset , prefix ):
133135 """ Loop over list of invalid keys and dynamically create tests """
136+
134137 def ch (pubkey , expected_error , ** kwargs ):
135138 return lambda self : self .check_fail (pubkey , expected_error , ** kwargs )
139+
136140 for items in keyset :
137141 modes = items .pop ()
138142 prefix_tmp = "%s_%s" % (prefix , items .pop ())
@@ -148,6 +152,7 @@ def ch(pubkey, expected_error, **kwargs):
148152def loop_authorized_keys (keyset ):
149153 def ch (file_str , valid_keys_count ):
150154 return lambda self : self .check_valid_file (file_str , valid_keys_count )
155+
151156 for i , items in enumerate (keyset ):
152157 prefix_tmp = "%s_%s" % (items [0 ], i )
153158 setattr (TestAuthorizedKeys , "test_%s" % prefix_tmp , ch (items [1 ], items [2 ]))
@@ -156,6 +161,7 @@ def ch(file_str, valid_keys_count):
156161def loop_invalid_authorized_keys (keyset ):
157162 def ch (file_str , expected_error , ** kwargs ):
158163 return lambda self : self .check_invalid_file (file_str , expected_error , ** kwargs )
164+
159165 for i , items in enumerate (keyset ):
160166 prefix_tmp = "%s_%s" % (items [0 ], i )
161167 setattr (TestAuthorizedKeys , "test_invalid_%s" % prefix_tmp , ch (items [1 ], items [2 ]))
0 commit comments