Skip to content

Commit

Permalink
Merge pull request #26 from twisted/24.certificate.verification
Browse files Browse the repository at this point in the history
Default to enabling hostname verification.
  • Loading branch information
mithrandi committed Jan 9, 2017
2 parents f2bfc74 + 97bb4a8 commit 46b66c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion txaws/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
# Licenced under the txaws licence available at /LICENSE in the txaws source.

import warnings

from txaws.credentials import AWSCredentials
from txaws import regions
from txaws.util import parse
Expand Down Expand Up @@ -42,12 +44,16 @@ class AWSServiceEndpoint(object):
will be done when connecting to the endpoint.
"""

def __init__(self, uri="", method="GET", ssl_hostname_verification=False):
def __init__(self, uri="", method="GET", ssl_hostname_verification=True):
self.host = ""
self.port = None
self.path = "/"
self.method = method
self.ssl_hostname_verification = ssl_hostname_verification
if not self.ssl_hostname_verification:
warnings.warn(
"Operating with certificate verification disabled!", stacklevel=2,
)
self._parse_uri(uri)
if not self.scheme:
self.scheme = "http"
Expand Down
12 changes: 12 additions & 0 deletions txaws/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class AWSServiceEndpointTestCase(TXAWSTestCase):
def setUp(self):
self.endpoint = AWSServiceEndpoint(uri="http://my.service/da_endpoint")

def test_warning_when_verification_disabled(self):
"""
L{AWSServiceEndpoint} emits a warning when told not to perform
certificate verification.
"""
self.assertWarns(
UserWarning,
"Operating with certificate verification disabled!",
__file__,
lambda: AWSServiceEndpoint(ssl_hostname_verification=False),
)

def test_simple_creation(self):
endpoint = AWSServiceEndpoint()
self.assertEquals(endpoint.scheme, "http")
Expand Down

0 comments on commit 46b66c3

Please sign in to comment.