~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_https_ca_bundle.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Testing of bzrlib.transport.http.ca_bundle module"""
 
18
 
 
19
import os
 
20
import sys
 
21
 
 
22
import bzrlib
 
23
from bzrlib import osutils
 
24
from bzrlib.tests import (
 
25
    TestCaseInTempDir,
 
26
    TestSkipped,
 
27
    )
 
28
from bzrlib.transport.http import ca_bundle
 
29
 
 
30
 
 
31
class TestGetCAPath(TestCaseInTempDir):
 
32
 
 
33
    def setUp(self):
 
34
        TestCaseInTempDir.setUp(self)
 
35
        new_env = {
 
36
            'CURL_CA_BUNDLE': None,
 
37
            'PATH': None,
 
38
            }
 
39
        self._old_env = {}
 
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)
 
43
 
 
44
    def _restore(self):
 
45
        for name, value in self._old_env.iteritems():
 
46
            osutils.set_or_unset_env(name, value)
 
47
 
 
48
    def _make_file(self, in_dir='.'):
 
49
        fname = os.path.join(in_dir, 'curl-ca-bundle.crt')
 
50
        f = file(fname,'w')
 
51
        f.write('spam')
 
52
        f.close()
 
53
 
 
54
    def test_found_nothing(self):
 
55
        self.assertEqual('', ca_bundle.get_ca_path(use_cache=False))
 
56
 
 
57
    def test_env_var(self):
 
58
        osutils.set_or_unset_env('CURL_CA_BUNDLE', 'foo.bar')
 
59
        self._make_file()
 
60
        self.assertEqual('foo.bar', ca_bundle.get_ca_path(use_cache=False))
 
61
 
 
62
    def test_in_path(self):
 
63
        if sys.platform != 'win32':
 
64
            raise TestSkipped('Searching in PATH implemented only for win32')
 
65
        os.mkdir('foo')
 
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))