• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.
2# All rights reserved.
3#
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the
6# "Software"), to deal in the Software without restriction, including
7# without limitation the rights to use, copy, modify, merge, publish, dis-
8# tribute, sublicense, and/or sell copies of the Software, and to permit
9# persons to whom the Software is furnished to do so, subject to the fol-
10# lowing conditions:
11#
12# The above copyright notice and this permission notice shall be included
13# in all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21# IN THE SOFTWARE.
22
23"""
24Base class to make checking the certs easier.
25"""
26
27
28# We subclass from ``object`` instead of ``TestCase`` here so that this doesn't
29# add noise to the test suite (otherwise these no-ops would run on every
30# import).
31class ServiceCertVerificationTest(object):
32    ssl = True
33
34    # SUBCLASSES MUST OVERRIDE THIS!
35    # Something like ``boto.sqs.regions()``...
36    regions = []
37
38    def test_certs(self):
39        self.assertTrue(len(self.regions) > 0)
40
41        for region in self.regions:
42            special_access_required = False
43
44            for snippet in ('gov', 'cn-'):
45                if snippet in region.name:
46                    special_access_required = True
47                    break
48
49            try:
50                c = region.connect()
51                self.sample_service_call(c)
52            except:
53                # This is bad (because the SSL cert failed). Re-raise the
54                # exception.
55                if not special_access_required:
56                    raise
57
58    def sample_service_call(self, conn):
59        """
60        Subclasses should override this method to do a service call that will
61        always succeed (like fetch a list, even if it's empty).
62        """
63        pass
64