py3: port crossdomain
Change-Id: I83a35f066d69edf39c74fd22c7fb248b5320d21f
This commit is contained in:
parent
50ea4e1e08
commit
081ff36e6e
@ -71,7 +71,7 @@ class CrossDomainMiddleware(object):
|
||||
'<cross-domain-policy>\n' \
|
||||
'%s\n' \
|
||||
'</cross-domain-policy>' % self.cross_domain_policy
|
||||
return Response(request=req, body=body,
|
||||
return Response(request=req, body=body.encode('utf-8'),
|
||||
content_type="application/xml")
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
|
@ -23,7 +23,7 @@ from swift.common.middleware import crossdomain
|
||||
class FakeApp(object):
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
return "FAKE APP"
|
||||
return b"FAKE APP"
|
||||
|
||||
|
||||
def start_response(*args):
|
||||
@ -37,12 +37,12 @@ class TestCrossDomain(unittest.TestCase):
|
||||
|
||||
# GET of /crossdomain.xml (default)
|
||||
def test_crossdomain_default(self):
|
||||
expectedResponse = '<?xml version="1.0"?>\n' \
|
||||
'<!DOCTYPE cross-domain-policy SYSTEM ' \
|
||||
'"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >\n' \
|
||||
'<cross-domain-policy>\n' \
|
||||
'<allow-access-from domain="*" secure="false" />\n' \
|
||||
'</cross-domain-policy>'
|
||||
expectedResponse = b'<?xml version="1.0"?>\n' \
|
||||
b'<!DOCTYPE cross-domain-policy SYSTEM ' \
|
||||
b'"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >\n' \
|
||||
b'<cross-domain-policy>\n' \
|
||||
b'<allow-access-from domain="*" secure="false" />\n' \
|
||||
b'</cross-domain-policy>'
|
||||
|
||||
req = Request.blank('/crossdomain.xml',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
@ -53,13 +53,13 @@ class TestCrossDomain(unittest.TestCase):
|
||||
def test_crossdomain_custom(self):
|
||||
conf = {'cross_domain_policy': '<dummy 1>\n<dummy 2>'}
|
||||
self.app = crossdomain.CrossDomainMiddleware(FakeApp(), conf)
|
||||
expectedResponse = '<?xml version="1.0"?>\n' \
|
||||
'<!DOCTYPE cross-domain-policy SYSTEM ' \
|
||||
'"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >\n' \
|
||||
'<cross-domain-policy>\n' \
|
||||
'<dummy 1>\n' \
|
||||
'<dummy 2>\n' \
|
||||
'</cross-domain-policy>'
|
||||
expectedResponse = b'<?xml version="1.0"?>\n' \
|
||||
b'<!DOCTYPE cross-domain-policy SYSTEM ' \
|
||||
b'"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >\n' \
|
||||
b'<cross-domain-policy>\n' \
|
||||
b'<dummy 1>\n' \
|
||||
b'<dummy 2>\n' \
|
||||
b'</cross-domain-policy>'
|
||||
|
||||
req = Request.blank('/crossdomain.xml',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
@ -70,7 +70,7 @@ class TestCrossDomain(unittest.TestCase):
|
||||
def test_crossdomain_pass(self):
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEqual(resp, 'FAKE APP')
|
||||
self.assertEqual(resp, b'FAKE APP')
|
||||
|
||||
# Only GET is allowed on the /crossdomain.xml resource
|
||||
def test_crossdomain_get_only(self):
|
||||
@ -78,7 +78,7 @@ class TestCrossDomain(unittest.TestCase):
|
||||
req = Request.blank('/crossdomain.xml',
|
||||
environ={'REQUEST_METHOD': method})
|
||||
resp = self.app(req.environ, start_response)
|
||||
self.assertEqual(resp, 'FAKE APP')
|
||||
self.assertEqual(resp, b'FAKE APP')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
1
tox.ini
1
tox.ini
@ -37,6 +37,7 @@ commands =
|
||||
test/unit/cli/test_ring_builder_analyzer.py \
|
||||
test/unit/cli/test_ringbuilder.py \
|
||||
test/unit/common/middleware/test_catch_errors.py \
|
||||
test/unit/common/middleware/test_crossdomain.py \
|
||||
test/unit/common/middleware/test_gatekeeper.py \
|
||||
test/unit/common/middleware/test_healthcheck.py \
|
||||
test/unit/common/middleware/test_proxy_logging.py \
|
||||
|
Loading…
Reference in New Issue
Block a user