Skip to content

Commit 5518bd6

Browse files
author
Roland Hedberg
committed
Use explicit exception classes.
1 parent 6744f80 commit 5518bd6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/saml2/validate.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import calendar
22
from six.moves.urllib.parse import urlparse
33
import re
4-
from saml2 import time_util
4+
from saml2 import time_util, Error
55
import struct
66
import base64
77

@@ -26,6 +26,14 @@ class MustValueError(ValueError):
2626
class ShouldValueError(ValueError):
2727
pass
2828

29+
30+
class ResponseLifetimeExceed(Error):
31+
pass
32+
33+
34+
class ToEarly(Error):
35+
pass
36+
2937
# --------------------- validators -------------------------------------
3038
#
3139

@@ -82,8 +90,8 @@ def validate_on_or_after(not_on_or_after, slack):
8290
now = time_util.utc_now()
8391
nooa = calendar.timegm(time_util.str_to_time(not_on_or_after))
8492
if now > nooa + slack:
85-
raise Exception("Can't use it, it's too old %d > %d" %
86-
(nooa, now))
93+
raise ResponseLifetimeExceed(
94+
"Can't use it, it's too old %d > %d".format(nooa, now))
8795
return nooa
8896
else:
8997
return False
@@ -94,7 +102,8 @@ def validate_before(not_before, slack):
94102
now = time_util.utc_now()
95103
nbefore = calendar.timegm(time_util.str_to_time(not_before))
96104
if nbefore > now + slack:
97-
raise Exception("Can't use it yet %d <= %d" % (nbefore, now))
105+
raise ToEarly("Can't use it yet %d <= %d" % (nbefore,
106+
now))
98107

99108
return True
100109

@@ -447,6 +456,6 @@ def valid_instance(instance):
447456
def valid_domain_name(dns_name):
448457
m = re.match(
449458
"^[a-z0-9]+([-.]{ 1 }[a-z0-9]+).[a-z]{2,5}(:[0-9]{1,5})?(\/.)?$",
450-
dns_name, "ix")
459+
dns_name, re.I)
451460
if not m:
452461
raise ValueError("Not a proper domain name")

0 commit comments

Comments
 (0)