Skip to content

Commit 85c3c22

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reduce mocking in test_reject_open_redirect for compat" into stable/victoria
2 parents 66ccea7 + 94e265f commit 85c3c22

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

nova/tests/unit/console/test_websocketproxy.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Tests for nova websocketproxy."""
1616

1717
import copy
18+
import io
1819
import socket
1920

2021
import mock
@@ -635,30 +636,28 @@ def test_reject_open_redirect(self):
635636
b''
636637
]
637638

638-
# Collect the response data to verify at the end. The
639-
# SimpleHTTPRequestHandler writes the response data by calling the
640-
# request socket sendall() method.
641-
self.data = b''
642-
643-
def fake_sendall(data):
644-
self.data += data
645-
646-
mock_req.sendall.side_effect = fake_sendall
647-
648639
client_addr = ('8.8.8.8', 54321)
649640
mock_server = mock.MagicMock()
650641
# This specifies that the server will be able to handle requests other
651642
# than only websockets.
652643
mock_server.only_upgrade = False
653644

654645
# Constructing a handler will process the mock_req request passed in.
655-
websocketproxy.NovaProxyRequestHandler(
646+
handler = websocketproxy.NovaProxyRequestHandler(
656647
mock_req, client_addr, mock_server)
657648

649+
# Collect the response data to verify at the end. The
650+
# SimpleHTTPRequestHandler writes the response data to a 'wfile'
651+
# attribute.
652+
output = io.BytesIO()
653+
handler.wfile = output
654+
# Process the mock_req again to do the capture.
655+
handler.do_GET()
656+
output.seek(0)
657+
result = output.readlines()
658+
658659
# Verify no redirect happens and instead a 400 Bad Request is returned.
659-
self.data = self.data.decode()
660-
self.assertIn('Error code: 400', self.data)
661-
self.assertIn('Message: URI must not start with //', self.data)
660+
self.assertIn('400 URI must not start with //', result[0].decode())
662661

663662
@mock.patch('websockify.websocketproxy.select_ssl_version')
664663
def test_ssl_min_version_is_not_set(self, mock_select_ssl):

0 commit comments

Comments
 (0)