1
# Copyright 2012 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
19
from glanceclient import exc
20
from glanceclient.common import http
22
TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
26
class TestVerifiedHTTPSConnection(unittest.TestCase):
27
def test_ssl_init_ok(self):
29
Test VerifiedHTTPSConnection class init
31
key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
32
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
33
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
35
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
39
except exc.SSLConfigurationError:
40
self.fail('Failed to init VerifiedHTTPSConnection.')
42
def test_ssl_init_cert_no_key(self):
44
Test VerifiedHTTPSConnection: absense of SSL key file.
46
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
47
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
49
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
52
self.fail('Failed to raise assertion.')
53
except exc.SSLConfigurationError:
56
def test_ssl_init_key_no_cert(self):
58
Test VerifiedHTTPSConnection: absense of SSL cert file.
60
key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
61
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
63
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
67
self.fail('Failed to init VerifiedHTTPSConnection.')
69
def test_ssl_init_bad_key(self):
71
Test VerifiedHTTPSConnection: bad key.
73
key_file = os.path.join(TEST_VAR_DIR, 'badkey.key')
74
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
75
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
77
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
80
self.fail('Failed to raise assertion.')
81
except exc.SSLConfigurationError:
84
def test_ssl_init_bad_cert(self):
86
Test VerifiedHTTPSConnection: bad cert.
88
key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
89
cert_file = os.path.join(TEST_VAR_DIR, 'badcert.crt')
90
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
92
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
95
self.fail('Failed to raise assertion.')
96
except exc.SSLConfigurationError:
99
def test_ssl_init_bad_ca(self):
101
Test VerifiedHTTPSConnection: bad CA.
103
key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
104
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
105
ca_file = os.path.join(TEST_VAR_DIR, 'badca.crt')
107
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
110
self.fail('Failed to raise assertion.')
111
except exc.SSLConfigurationError: