1
1
import calendar
2
2
from six .moves .urllib .parse import urlparse
3
3
import re
4
- from saml2 import time_util
4
+ from saml2 import time_util , Error
5
5
import struct
6
6
import base64
7
7
@@ -26,6 +26,14 @@ class MustValueError(ValueError):
26
26
class ShouldValueError (ValueError ):
27
27
pass
28
28
29
+
30
+ class ResponseLifetimeExceed (Error ):
31
+ pass
32
+
33
+
34
+ class ToEarly (Error ):
35
+ pass
36
+
29
37
# --------------------- validators -------------------------------------
30
38
#
31
39
@@ -82,8 +90,8 @@ def validate_on_or_after(not_on_or_after, slack):
82
90
now = time_util .utc_now ()
83
91
nooa = calendar .timegm (time_util .str_to_time (not_on_or_after ))
84
92
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 ))
87
95
return nooa
88
96
else :
89
97
return False
@@ -94,7 +102,8 @@ def validate_before(not_before, slack):
94
102
now = time_util .utc_now ()
95
103
nbefore = calendar .timegm (time_util .str_to_time (not_before ))
96
104
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 ))
98
107
99
108
return True
100
109
@@ -447,6 +456,6 @@ def valid_instance(instance):
447
456
def valid_domain_name (dns_name ):
448
457
m = re .match (
449
458
"^[a-z0-9]+([-.]{ 1 }[a-z0-9]+).[a-z]{2,5}(:[0-9]{1,5})?(\/.)?$" ,
450
- dns_name , "ix" )
459
+ dns_name , re . I )
451
460
if not m :
452
461
raise ValueError ("Not a proper domain name" )
0 commit comments