unit tests fail if _proxy env vars are set #3739

Open
dpb1 opened this Issue Jun 15, 2017 · 0 comments

Comments

Projects
None yet
1 participant

dpb1 commented Jun 15, 2017

python-boto 2.44.0

When running the unit tests in the develop branch as of 0a9b114, I get test errors if I have https_proxy variables set in my environment before starting the test. Errors are of the form:

http_proxy=http://10.73.33.104:3128 https_proxy=http://10.73.33.104:3128 python tests/test.py unit.beanstalk
...

======================================================================
ERROR: test_list_available_solution_stacks (tests.unit.beanstalk.test_layer1.TestListAvailableSolutionStacks)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dpb/src/ubuntu/python-boto/tests/unit/beanstalk/test_layer1.py", line 32, in test_list_available_solution_stacks
    api_response = self.service_connection.list_available_solution_stacks()
  File "/home/dpb/src/ubuntu/python-boto/boto/beanstalk/layer1.py", line 756, in list_available_solution_stacks
    return self._get_response('ListAvailableSolutionStacks', params={})
  File "/home/dpb/src/ubuntu/python-boto/boto/beanstalk/layer1.py", line 71, in _get_response
    raise self.ResponseError(response.status, response.reason, body)
BotoServerError: BotoServerError: 403 Forbidden
{"Error":{"Code":"InvalidClientTokenId","Message":"The security token included in the request is invalid.","Type":"Sender"},"RequestId":"ee5326d9-51fa-11e7-a456-a5060a063dde"}
-------------------- >> begin captured logging << --------------------
boto: DEBUG: Using access key provided by client.
boto: DEBUG: Using secret key provided by client.
boto: DEBUG: Method: GET
boto: DEBUG: Path: https://elasticbeanstalk.us-east-1.amazonaws.com/
boto: DEBUG: Data:
boto: DEBUG: Headers: {}
boto: DEBUG: Host: elasticbeanstalk.us-east-1.amazonaws.com
boto: DEBUG: Port: 443
boto: DEBUG: Params: {'Action': 'ListAvailableSolutionStacks', 'Version': '2010-12-01', 'ContentType': 'JSON'}
boto: DEBUG: establishing HTTPS connection: host=elasticbeanstalk.us-east-1.amazonaws.com, kwargs={'port': 443, 'timeout': 70}
boto: DEBUG: Proxy connection: CONNECT elasticbeanstalk.us-east-1.amazonaws.com:443 HTTP/1.0

boto: DEBUG: wrapping ssl socket for proxied connection; CA certificate file=/home/dpb/src/ubuntu/python-boto/boto/cacerts/cacerts.txt
boto: DEBUG: validating server certificate: hostname=elasticbeanstalk.us-east-1.amazonaws.com, certificate hosts=['elasticbeanstalk.us-east-1.amazonaws.com']
boto: DEBUG: Token: None
boto: DEBUG: CanonicalRequest:
GET
/
Action=ListAvailableSolutionStacks&ContentType=JSON&Version=2010-12-01
host:elasticbeanstalk.us-east-1.amazonaws.com
x-amz-date:20170615T184623Z

host;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
boto: DEBUG: StringToSign:
AWS4-HMAC-SHA256
20170615T184623Z
20170615/us-east-1/elasticbeanstalk/aws4_request
0639ecced695d1f1b2de74fc1b13f69c472757799dfcf081ac08a208ea236cad
boto: DEBUG: Signature:
ba75ad3b1153b515ae8c6278b4d95cf7b580e5aa3f79f8be42e5f9fcd88c8f45
boto: DEBUG: Final headers: {'Content-Length': '0', 'Host': 'elasticbeanstalk.us-east-1.amazonaws.com', 'Authorization': 'AWS4-HMAC-SHA256 Credential=aws_access_key_id/20170615/us-east-1/elasticbeanstalk/aws4_request,SignedHeaders=host;x-amz-date,Signature=ba75ad3b1153b515ae8c6278b4d95cf7b580e5aa3f79f8be42e5f9fcd88c8f45', 'X-Amz-Date': '20170615T184623Z', 'User-Agent': 'Boto/2.47.0 Python/2.7.12 Linux/4.4.0-79-generic'}
boto: DEBUG: Response headers: [('date', 'Thu, 15 Jun 2017 18:46:23 GMT'), ('x-amzn-requestid', 'ee5326d9-51fa-11e7-a456-a5060a063dde'), ('content-length', '175'), ('content-type', 'application/json'), ('connection', 'keep-alive')]
boto: DEBUG: {"Error":{"Code":"InvalidClientTokenId","Message":"The security token included in the request is invalid.","Type":"Sender"},"RequestId":"ee5326d9-51fa-11e7-a456-a5060a063dde"}

Upon more careful inspection, it seems the connection code is overriding mocks that the unit tests set up if it detects https_proxy is set.

The workaround is simple, A command line like the following works fine:

http_proxy= https_proxy= python tests/test.py unit.beanstalk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment