1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Testing of bzrlib.transport.http.ca_bundle module"""
23
from bzrlib import osutils
24
from bzrlib.tests import (
28
from bzrlib.transport.http import ca_bundle
31
class TestGetCAPath(TestCaseInTempDir):
34
TestCaseInTempDir.setUp(self)
36
'CURL_CA_BUNDLE': None,
40
self.addCleanup(self._restore)
41
for name, value in new_env.iteritems():
42
self._old_env[name] = osutils.set_or_unset_env(name, None)
45
for name, value in self._old_env.iteritems():
46
osutils.set_or_unset_env(name, value)
48
def _make_file(self, in_dir='.'):
49
fname = os.path.join(in_dir, 'curl-ca-bundle.crt')
54
def test_found_nothing(self):
55
self.assertEqual('', ca_bundle.get_ca_path(use_cache=False))
57
def test_env_var(self):
58
osutils.set_or_unset_env('CURL_CA_BUNDLE', 'foo.bar')
60
self.assertEqual('foo.bar', ca_bundle.get_ca_path(use_cache=False))
62
def test_in_path(self):
63
if sys.platform != 'win32':
64
raise TestSkipped('Searching in PATH implemented only for win32')
66
in_dir = os.path.join(os.getcwd(), 'foo')
67
self._make_file(in_dir=in_dir)
68
osutils.set_or_unset_env('PATH', in_dir)
69
shouldbe = os.path.join(in_dir, 'curl-ca-bundle.crt')
70
self.assertEqual(shouldbe, ca_bundle.get_ca_path(use_cache=False))