File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,12 @@ def __check_secret(self, secret):
3636 raise TypeError ('You must set an ascii str variable as secret!' )
3737 secret_without_spaces = self .remove_spaces (secret )
3838 self ._secret = self .to_upper_case (secret_without_spaces )
39- if len (self ._secret ) % 8 != 0 :
40- raise ValueError ('You must set a string multiple of 8!' )
39+ secret_length = len (self ._secret )
40+ if secret_length < 8 :
41+ raise ValueError ('You must set a secret of minimum 8 characters!' )
42+ if secret_length > 8 :
43+ index = secret_length % 8
44+ self ._secret = self ._secret [:- index ]
4145 if self .__is_alpha (self ._secret ) == False :
4246 raise TypeError ('All characters in the secret must be alphabetic!' )
4347
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def test_wrong_initiation(self):
2121 with self .assertRaises (Exception ) as context :
2222 Authenticator ('abcd' )
2323
24- self .assertTrue ('You must set a string multiple of 8 !' in str (context .exception ))
24+ self .assertTrue ('You must set a secret of minimum 8 characters !' in str (context .exception ))
2525
2626 with self .assertRaises (Exception ) as context :
2727 Authenticator (lambda : None )
@@ -81,9 +81,12 @@ def test_create_hmac(self):
8181 def test_one_time_password (self ):
8282 password = self ._authenticator .one_time_password ()
8383 self .assertIsNotNone (password )
84+ self .assertIsNotNone (Authenticator ('abcd xyzw a' ).one_time_password ())
85+ self .assertIsNotNone (Authenticator ('abcd xyzw ab' ).one_time_password ())
86+ self .assertIsNotNone (Authenticator ('abcd xyzw abcd' ).one_time_password ())
8487
8588 def test_one_time_password_with_empty_spaces (self ):
86- password = Authenticator ('\t \t \t \t \t \t \t \t ' ).one_time_password ()
89+ password = Authenticator ('\t a \b t \t c \t d \t e \t f \t g \t h ' ).one_time_password ()
8790 self .assertIsNotNone (password )
88- password = Authenticator ('\r \r \r \r \r \r \r \r ' ).one_time_password ()
91+ password = Authenticator ('\r a \r b \r c \r d \r e \r f \r g \r h ' ).one_time_password ()
8992 self .assertIsNotNone (password )
You can’t perform that action at this time.
0 commit comments