Skip to content

Commit

Permalink
test(RFC3339): add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed Jun 22, 2022
1 parent 41f1797 commit cd80945
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cert_issuer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def validate_issuer (certificate_issuer):
pass

def validate_date_RFC3339_string_format (date, property_name):
error_message = '`{}` property must be a valid RFC3339 string'.format(property_name)
error_message = '`{}` property must be a valid RFC3339 string.'.format(property_name)
if not isinstance(date, str):
error_message += ' `{}` value is not a string'.format(date)
raise ValueError(error_message)

if not validate_RFC3339_date(date):
error_message += ' Value received: `{}`'.format(date)
raise ValueError(error_message)
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_verify_expiration_date (self):
try:
handler.prepare_batch()
except Exception as e:
self.assertEqual(str(e), '`expirationDate` property must be a valid RFC3339 string')
self.assertEqual(str(e), '`expirationDate` property must be a valid RFC3339 string. Value received: `20200909`')
return

assert False
Expand Down
39 changes: 39 additions & 0 deletions tests/v3_certificate_validation/test_unit_issuance_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def test_validate_issuance_date_invalid_RFC3339 (self):
return

assert False
def test_validate_issuance_date_invalid_RFC3339_timezone_offset_zulu (self):
candidate = '2020-02-02T00:00:00+03:00Z'
try:
validate_issuance_date(candidate)
except:
assert True
return

assert False

def test_validate_issuance_date_valid_RFC3339 (self):
candidate = '2020-02-02T00:00:00Z'
Expand All @@ -23,5 +32,35 @@ def test_validate_issuance_date_valid_RFC3339 (self):

assert True

def test_validate_issuance_date_valid_RFC3339_no_T (self):
candidate = '2020-02-02 00:00:00Z'
try:
validate_issuance_date(candidate)
except:
assert False
return

assert True

def test_validate_issuance_date_valid_RFC3339_timezone_offset (self):
candidate = '2020-02-02T00:00:00+03:00'
try:
validate_issuance_date(candidate)
except:
assert False
return

assert True

def test_validate_issuance_date_valid_RFC3339_millisec (self):
candidate = '2020-02-02T00:00:00.916Z'
try:
validate_issuance_date(candidate)
except:
assert False
return

assert True

if __name__ == '__main__':
unittest.main()

0 comments on commit cd80945

Please sign in to comment.