Skip to content

Commit

Permalink
python3: fix cookie handler in test
Browse files Browse the repository at this point in the history
* tries both cases for the set-cookie header to make sure we catch cookie transitions.
* tampers with basic_connection fixture to demonstrate

closes: #93
  • Loading branch information
hartsock committed Jul 29, 2014
1 parent abbb274 commit 124a8ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pyVmomi/SoapAdapter.py
Expand Up @@ -1241,7 +1241,10 @@ def InvokeMethod(self, mo, info, args, outerStub=None):
# The server is probably sick, drop all of the cached connections.
self.DropConnections()
raise
cookie = resp.getheader('set-cookie')
cookie = resp.getheader('Set-Cookie')
if cookie is None:
# try lower-case header for backwards compat. with old vSphere
cookie = resp.getheader('set-cookie')
status = resp.status

if cookie:
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/basic_connection.yaml
Expand Up @@ -52,7 +52,7 @@ interactions:
content-length: ['3332']
content-type: [text/xml; charset=utf-8]
date: ['Mon, 21 Jul 2014 22:31:05 GMT']
set-cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/;
set-cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/;
HttpOnly; Secure;]
status: {code: 200, message: OK}
- request:
Expand All @@ -68,7 +68,7 @@ interactions:
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/;
Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
Expand Down Expand Up @@ -99,7 +99,7 @@ interactions:
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/;
Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
Expand Down Expand Up @@ -155,7 +155,7 @@ interactions:
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/;
Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
Expand Down Expand Up @@ -212,7 +212,7 @@ interactions:
headers:
Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8]
Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/;
Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/;
HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"']
method: POST
Expand Down
5 changes: 5 additions & 0 deletions tests/test_connect.py
Expand Up @@ -36,10 +36,15 @@ def test_basic_connection(self):
si = connect.Connect(host='vcsa',
user='my_user',
pwd='my_password')
cookie = si._stub.cookie
session_id = si.content.sessionManager.currentSession.key
# NOTE (hartsock): The cookie value should never change during
# a connected session. That should be verifiable in these tests.
self.assertEqual(cookie, si._stub.cookie)
# NOTE (hartsock): assertIsNotNone does not work in Python 2.6
self.assertTrue(session_id is not None)
self.assertEqual('52773cd3-35c6-b40a-17f1-fe664a9f08f3', session_id)
self.assertTrue(session_id in cookie)

@vcr.use_cassette('basic_connection_bad_password.yaml',
cassette_library_dir=fixtures_path, record_mode='none')
Expand Down

0 comments on commit 124a8ac

Please sign in to comment.