Skip to content

Commit

Permalink
imvalid timezones are checked in generalized time format validator
Browse files Browse the repository at this point in the history
  • Loading branch information
cannatag committed Mar 17, 2017
1 parent d528ad5 commit d401a97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions _changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- updated tests for OpenLDAP
- fixed error when in add/remove extend operation for case mismatch in user or group dn
- integer validator now automatically convert valid string numbers to int
- invalid timezone are checked when validating Generalized Time Format
- added test cases for validators

- 2.2.1 2017.02.12
Expand Down
3 changes: 3 additions & 0 deletions ldap3/protocol/formatters/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def format_time(raw_value):
raise ValueError
except ValueError:
return raw_value
if timezone_hour > 23 or timezone_minute > 59: # invalid timezone
return raw_value

if str is not bytes: # Python 3
timezone = OffsetTzInfo((timezone_hour * 60 + timezone_minute) * (1 if sep == b'+' else -1), 'UTC' + str(sep + offset, encoding='utf-8'))
else: # Python 2
Expand Down
12 changes: 10 additions & 2 deletions test/testValidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def test_validate_time_valid_str_with_timezone(self):
validated = validate_time('20170317094232+0100')
self.assertTrue(validated)

def test_validate_time_invalid_str(self):
def test_validate_time_invalid_str_1(self):
validated = validate_time('abc')
self.assertFalse(validated)
self.assertFalse(validated)

def test_validate_time_invalid_str_2(self):
validated = validate_time('20170317254201Z')
self.assertFalse(validated)

def test_validate_time_invalid_str_with_timezone(self):
validated = validate_time('20170317094232+24')
self.assertFalse(validated)

0 comments on commit d401a97

Please sign in to comment.