diff options
author | Vlastimil Zíma <vlastimil.zima@nic.cz> | 2018-05-09 10:31:09 +0200 |
---|---|---|
committer | Vlastimil Zíma <vlastimil.zima@nic.cz> | 2018-05-11 13:40:03 +0200 |
commit | 8345d651bc80fa48961f2d4282a03ce605c216de (patch) | |
tree | 22c805c839bbec27489802237a5810f12ce38d99 /openid | |
parent | c987505065718ae400d51eea7143c25646480e6a (diff) | |
download | openid-8345d651bc80fa48961f2d4282a03ce605c216de.tar.gz |
Fix test data loading
Diffstat (limited to 'openid')
-rw-r--r-- | openid/test/discoverdata.py | 2 | ||||
-rw-r--r-- | openid/test/test_accept.py | 2 | ||||
-rw-r--r-- | openid/test/test_discover.py | 4 | ||||
-rw-r--r-- | openid/test/test_etxrd.py | 25 | ||||
-rw-r--r-- | openid/test/test_trustroot.py | 2 | ||||
-rw-r--r-- | openid/test/test_yadis_discover.py | 2 |
6 files changed, 19 insertions, 18 deletions
diff --git a/openid/test/discoverdata.py b/openid/test/discoverdata.py index 1540c34..1cc1484 100644 --- a/openid/test/discoverdata.py +++ b/openid/test/discoverdata.py @@ -132,5 +132,5 @@ def generateResult(base_url, input_name, id_name, result_name, success): if success: result.xrds_uri = urljoin(base_url, result_name) result.content_type = ctype - result.response_text = content + result.response_text = content.encode('utf-8') return input_url, result diff --git a/openid/test/test_accept.py b/openid/test/test_accept.py index 8ca25fa..7f645d8 100644 --- a/openid/test/test_accept.py +++ b/openid/test/test_accept.py @@ -15,7 +15,7 @@ def getTestData(): filename = os.path.join(os.path.dirname(__file__), 'data', 'accept.txt') i = 1 lines = [] - for line in open(filename): + for line in open(filename, 'rb'): lines.append((i, line.decode('utf-8'))) i += 1 return lines diff --git a/openid/test/test_discover.py b/openid/test/test_discover.py index c99fc49..5e56a77 100644 --- a/openid/test/test_discover.py +++ b/openid/test/test_discover.py @@ -206,7 +206,7 @@ def readDataFile(filename): module_directory = os.path.dirname(os.path.abspath(__file__)) filename = os.path.join( module_directory, 'data', 'test_discover', filename) - return open(filename).read() + return open(filename, 'rb').read() class TestDiscovery(BaseTestDiscovery): @@ -258,7 +258,7 @@ class TestDiscovery(BaseTestDiscovery): def test_noOpenID(self): services = self._discover(content_type='text/plain', - data="junk", + data=b"junk", expected_services=0) services = self._discover( diff --git a/openid/test/test_etxrd.py b/openid/test/test_etxrd.py index 6932584..f07dbb9 100644 --- a/openid/test/test_etxrd.py +++ b/openid/test/test_etxrd.py @@ -67,19 +67,20 @@ class TestParseXRDS(unittest.TestCase): etxrd.parseXRDS(xml) def test_xxe(self): - xxe_content = 'XXE CONTENT' + xxe_content = b'XXE CONTENT' _, tmp_file = tempfile.mkstemp() try: - with open(tmp_file, 'w') as xxe_file: + with open(tmp_file, 'wb') as xxe_file: xxe_file.write(xxe_content) # XXE example from Testing for XML Injection (OTG-INPVAL-008) # https://www.owasp.org/index.php/Testing_for_XML_Injection_(OTG-INPVAL-008) - xml = (b'<?xml version="1.0" encoding="ISO-8859-1"?>' - b'<!DOCTYPE foo [' - b'<!ELEMENT foo ANY >' - b'<!ENTITY xxe SYSTEM "file://%s" >]>' - b'<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">&xxe;</xrds:XRDS>') - tree = etxrd.parseXRDS(xml % tmp_file) + xml = ('<?xml version="1.0" encoding="ISO-8859-1"?>' + '<!DOCTYPE foo [' + '<!ELEMENT foo ANY >' + '<!ENTITY xxe SYSTEM "file://%s" >]>' + '<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">&xxe;</xrds:XRDS>') + xml = xml % tmp_file + tree = etxrd.parseXRDS(xml.encode('utf-8')) self.assertNotIn(xxe_content, etree.tostring(tree)) finally: os.remove(tmp_file) @@ -87,7 +88,7 @@ class TestParseXRDS(unittest.TestCase): class TestServiceParser(unittest.TestCase): def setUp(self): - self.xmldoc = open(XRD_FILE).read() + self.xmldoc = open(XRD_FILE, 'rb').read() self.yadis_url = 'http://unittest.url/' def _getServices(self, flt=None): @@ -155,7 +156,7 @@ class TestServiceParser(unittest.TestCase): def testNoXRDS(self): """Make sure that we get an exception when an XRDS element is not present""" - self.xmldoc = open(NOXRDS_FILE).read() + self.xmldoc = open(NOXRDS_FILE, 'rb').read() self.assertRaises(etxrd.XRDSError, services.applyFilter, self.yadis_url, self.xmldoc, None) def testEmpty(self): @@ -167,7 +168,7 @@ class TestServiceParser(unittest.TestCase): def testNoXRD(self): """Make sure that we get an exception when there is no XRD element present.""" - self.xmldoc = open(NOXRD_FILE).read() + self.xmldoc = open(NOXRD_FILE, 'rb').read() self.assertRaises(etxrd.XRDSError, services.applyFilter, self.yadis_url, self.xmldoc, None) @@ -180,7 +181,7 @@ class TestCanonicalID(unittest.TestCase): filename = datapath(filename) def test(self): - xrds = etxrd.parseXRDS(open(filename).read()) + xrds = etxrd.parseXRDS(open(filename, 'rb').read()) self._getCanonicalID(iname, xrds, expectedID) return test diff --git a/openid/test/test_trustroot.py b/openid/test/test_trustroot.py index 9d3e3f3..f90dd90 100644 --- a/openid/test/test_trustroot.py +++ b/openid/test/test_trustroot.py @@ -5,7 +5,7 @@ import unittest from openid.server.trustroot import TrustRoot -with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'trustroot.txt')) as test_data_file: +with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'trustroot.txt'), 'rb') as test_data_file: trustroot_test_data = test_data_file.read().decode('utf-8') diff --git a/openid/test/test_yadis_discover.py b/openid/test/test_yadis_discover.py index eec94c8..52baa14 100644 --- a/openid/test/test_yadis_discover.py +++ b/openid/test/test_yadis_discover.py @@ -41,7 +41,7 @@ def mkResponse(data): status = int(status_mo.group(1)) return fetchers.HTTPResponse(status=status, headers=headers, - body=body) + body=body.encode('utf-8')) class TestFetcher(object): |