3
3
4
4
import base64
5
5
6
+ import six
7
+
6
8
from saml2 import s_utils as utils
7
9
from saml2 import saml
8
10
from saml2 import samlp
15
17
16
18
from pathutils import full_path
17
19
18
- SUCCESS_STATUS = ('<?xml version=\' 1.0\' encoding=\' UTF-8\' ?>\n '
20
+ XML_HEADER = '<?xml version=\' 1.0\' encoding=\' UTF-8\' ?>\n '
21
+
22
+ SUCCESS_STATUS_NO_HEADER = (
19
23
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
20
24
'Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></ns0:Status>' )
25
+ SUCCESS_STATUS = '%s%s' % (XML_HEADER , SUCCESS_STATUS_NO_HEADER )
21
26
22
- ERROR_STATUS = ('<?xml version= \' 1.0 \' encoding= \' UTF-8 \' ?> \n '
27
+ ERROR_STATUS_NO_HEADER = (
23
28
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
24
29
'Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode '
25
30
'Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal" '
26
31
'/></ns0:StatusCode><ns0:StatusMessage>Error resolving '
27
32
'principal</ns0:StatusMessage></ns0:Status>' )
33
+ ERROR_STATUS = '%s%s' % (XML_HEADER , ERROR_STATUS_NO_HEADER )
28
34
29
35
30
36
def _eq (l1 , l2 ):
@@ -48,16 +54,20 @@ def test_inflate_then_deflate():
48
54
txt = """Selma Lagerlöf (1858-1940) was born in Östra Emterwik, Värmland,
49
55
Sweden. She was brought up on Mårbacka, the family estate, which she did
50
56
not leave until 1881, when she went to a teachers' college at Stockholm"""
57
+ if not isinstance (txt , six .binary_type ):
58
+ txt = txt .encode ('utf-8' )
51
59
52
60
interm = utils .deflate_and_base64_encode (txt )
53
61
bis = utils .decode_base64_and_inflate (interm )
62
+ if not isinstance (bis , six .binary_type ):
63
+ bis = bis .encode ('utf-8' )
54
64
assert bis == txt
55
65
56
66
57
67
def test_status_success ():
58
68
status = utils .success_status_factory ()
59
69
status_text = "%s" % status
60
- assert status_text == SUCCESS_STATUS
70
+ assert status_text in ( SUCCESS_STATUS_NO_HEADER , SUCCESS_STATUS )
61
71
assert status .status_code .value == samlp .STATUS_SUCCESS
62
72
63
73
@@ -68,15 +78,15 @@ def test_error_status():
68
78
69
79
status_text = "%s" % status
70
80
print (status_text )
71
- assert status_text == ERROR_STATUS
81
+ assert status_text in ( ERROR_STATUS_NO_HEADER , ERROR_STATUS )
72
82
73
83
74
84
def test_status_from_exception ():
75
85
e = utils .UnknownPrincipal ("Error resolving principal" )
76
86
stat = utils .error_status_factory (e )
77
87
status_text = "%s" % stat
78
88
print (status_text )
79
- assert status_text == ERROR_STATUS
89
+ assert status_text in ( ERROR_STATUS_NO_HEADER , ERROR_STATUS )
80
90
81
91
82
92
def test_attribute_sn ():
@@ -117,7 +127,10 @@ def test_attribute_onoff():
117
127
118
128
119
129
def test_attribute_base64 ():
120
- b64sl = base64 .b64encode ("Selma Lagerlöf" )
130
+ txt = "Selma Lagerlöf"
131
+ if not isinstance (txt , six .binary_type ):
132
+ txt = txt .encode ("utf-8" )
133
+ b64sl = base64 .b64encode (txt ).decode ('ascii' )
121
134
attr = utils .do_attributes ({"name" : (b64sl , "xs:base64Binary" )})
122
135
123
136
assert len (attr ) == 1
0 commit comments