~ubuntu-branches/ubuntu/saucy/python-glanceclient/saucy

« back to all changes in this revision

Viewing changes to tests/test_ssl.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 10:22:06 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20121123102206-0dlq52aydhudnrrc
Tags: 1:0.6.0-0ubuntu1
[ Adam Gandelman ]
* Ensure python-prettytable >= 0.6. (LP: #1073275)
* debian/control, pydist-overrides: Add python-openssl override.

[ Chuck Short ]
* New usptream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
16
import os
 
17
import unittest
 
18
 
 
19
from glanceclient import exc
 
20
from glanceclient.common import http
 
21
 
 
22
TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
 
23
                                            'var'))
 
24
 
 
25
 
 
26
class TestVerifiedHTTPSConnection(unittest.TestCase):
 
27
    def test_ssl_init_ok(self):
 
28
        """
 
29
        Test VerifiedHTTPSConnection class init
 
30
        """
 
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')
 
34
        try:
 
35
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
36
                                                key_file=key_file,
 
37
                                                cert_file=cert_file,
 
38
                                                ca_file=ca_file)
 
39
        except exc.SSLConfigurationError:
 
40
            self.fail('Failed to init VerifiedHTTPSConnection.')
 
41
 
 
42
    def test_ssl_init_cert_no_key(self):
 
43
        """
 
44
        Test VerifiedHTTPSConnection: absense of SSL key file.
 
45
        """
 
46
        cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
 
47
        ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
 
48
        try:
 
49
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
50
                                                cert_file=cert_file,
 
51
                                                ca_file=ca_file)
 
52
            self.fail('Failed to raise assertion.')
 
53
        except exc.SSLConfigurationError:
 
54
            pass
 
55
 
 
56
    def test_ssl_init_key_no_cert(self):
 
57
        """
 
58
        Test VerifiedHTTPSConnection: absense of SSL cert file.
 
59
        """
 
60
        key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
 
61
        ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
 
62
        try:
 
63
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
64
                                                key_file=key_file,
 
65
                                                ca_file=ca_file)
 
66
        except:
 
67
            self.fail('Failed to init VerifiedHTTPSConnection.')
 
68
 
 
69
    def test_ssl_init_bad_key(self):
 
70
        """
 
71
        Test VerifiedHTTPSConnection: bad key.
 
72
        """
 
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')
 
76
        try:
 
77
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
78
                                                cert_file=cert_file,
 
79
                                                ca_file=ca_file)
 
80
            self.fail('Failed to raise assertion.')
 
81
        except exc.SSLConfigurationError:
 
82
            pass
 
83
 
 
84
    def test_ssl_init_bad_cert(self):
 
85
        """
 
86
        Test VerifiedHTTPSConnection: bad cert.
 
87
        """
 
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')
 
91
        try:
 
92
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
93
                                                cert_file=cert_file,
 
94
                                                ca_file=ca_file)
 
95
            self.fail('Failed to raise assertion.')
 
96
        except exc.SSLConfigurationError:
 
97
            pass
 
98
 
 
99
    def test_ssl_init_bad_ca(self):
 
100
        """
 
101
        Test VerifiedHTTPSConnection: bad CA.
 
102
        """
 
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')
 
106
        try:
 
107
            conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
 
108
                                                cert_file=cert_file,
 
109
                                                ca_file=ca_file)
 
110
            self.fail('Failed to raise assertion.')
 
111
        except exc.SSLConfigurationError:
 
112
            pass