Skip to content

Commit 9ec7705

Browse files
committed
Fix basic python3 issues in test_02_saml
- Strings/bytes encoding/decoding where necessary. - Random hash seed producing test fails sometimes on keys(), sorting lists fixes this.
1 parent efa12f0 commit 9ec7705

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/saml2/saml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _verify_value_type(typ, val):
119119
if typ == XSD + "base64Binary":
120120
import base64
121121

122-
return base64.decodestring(val)
122+
return base64.decodestring(val.encode('utf-8'))
123123

124124

125125
class AttributeValueBase(SamlBase):

tests/test_02_saml.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_add_extension_attribute(self):
183183
ec = saml2.ExtensionContainer()
184184
ec.add_extension_attribute("foo", "bar")
185185
assert len(ec.extension_attributes) == 1
186-
assert ec.extension_attributes.keys()[0] == "foo"
186+
assert list(ec.extension_attributes.keys())[0] == "foo"
187187

188188

189189
class TestSAMLBase:
@@ -216,13 +216,14 @@ def test_make_vals_multi_dict(self):
216216

217217
attr = Attribute()
218218
saml2.make_vals(ava, AttributeValue, attr, prop="attribute_value")
219-
assert attr.keyswv() == ["name_format", "attribute_value"]
219+
assert sorted(attr.keyswv()) == sorted(["name_format",
220+
"attribute_value"])
220221
assert len(attr.attribute_value) == 4
221222

222223
def test_to_string_nspair(self):
223224
foo = saml2.make_vals("lions", AttributeValue, part=True)
224-
txt = foo.to_string()
225-
nsstr = foo.to_string({"saml": saml.NAMESPACE})
225+
txt = foo.to_string().decode('utf-8')
226+
nsstr = foo.to_string({"saml": saml.NAMESPACE}).decode('utf-8')
226227
assert nsstr != txt
227228
print(txt)
228229
print(nsstr)
@@ -1215,4 +1216,4 @@ def testUsingTestData(self):
12151216

12161217
if __name__ == "__main__":
12171218
t = TestSAMLBase()
1218-
t.test_make_vals_multi_dict()
1219+
t.test_make_vals_multi_dict()

0 commit comments

Comments
 (0)