~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_https_urllib.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-06 23:38:33 UTC
  • mfrom: (6463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6464.
  • Revision ID: jelmer@samba.org-20120206233833-w0nbclw7d1xj4twj
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011 Canonical Ltd
 
1
# Copyright (C) 2011,2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
41
41
    def get_stack(self, content):
42
42
        return config.MemoryStack(content.encode('utf-8'))
43
43
 
44
 
    def test_default_raises_value_error(self):
45
 
        stack = self.get_stack("")
46
 
        self.overrideAttr(_urllib2_wrappers, "DEFAULT_CA_PATH",
47
 
                "/i-do-not-exist")
48
 
        self.assertRaises(ValueError, stack.get, 'ssl.ca_certs')
49
 
 
50
44
    def test_default_exists(self):
51
 
        self.build_tree(['cacerts.pem'])
 
45
        """Check that the default we provide exists for the tested platform."""
52
46
        stack = self.get_stack("")
53
 
        path = os.path.join(self.test_dir, "cacerts.pem")
54
 
        self.overrideAttr(_urllib2_wrappers, "DEFAULT_CA_PATH", path)
55
 
        self.assertEquals(path, stack.get('ssl.ca_certs'))
 
47
        self.assertPathExists(stack.get('ssl.ca_certs'))
56
48
 
57
49
    def test_specified(self):
58
50
        self.build_tree(['cacerts.pem'])
61
53
        self.assertEquals(path, stack.get('ssl.ca_certs'))
62
54
 
63
55
    def test_specified_doesnt_exist(self):
64
 
        path = os.path.join(self.test_dir, "nonexisting.pem")
65
 
        stack = self.get_stack("ssl.ca_certs = %s\n" % path)
 
56
        stack = self.get_stack('')
 
57
        # Disable the default value mechanism to force the behavior we want
 
58
        self.overrideAttr(_urllib2_wrappers.opt_ssl_ca_certs, 'default',
 
59
                          os.path.join(self.test_dir, u"nonexisting.pem"))
66
60
        self.warnings = []
67
61
        def warning(*args):
68
62
            self.warnings.append(args[0] % args[1:])
69
63
        self.overrideAttr(trace, 'warning', warning)
70
 
        self.assertEquals(_urllib2_wrappers.DEFAULT_CA_PATH,
71
 
                          stack.get('ssl.ca_certs'))
 
64
        self.assertEquals(None, stack.get('ssl.ca_certs'))
72
65
        self.assertLength(1, self.warnings)
73
66
        self.assertContainsRe(self.warnings[0],
74
67
                              "is not valid for \"ssl.ca_certs\"")
83
76
    def test_from_string(self):
84
77
        stack = config.MemoryStack("ssl.cert_reqs = none\n")
85
78
        self.assertEquals(ssl.CERT_NONE, stack.get("ssl.cert_reqs"))
86
 
        stack = config.MemoryStack("ssl.cert_reqs = optional\n")
87
 
        self.assertEquals(ssl.CERT_OPTIONAL, stack.get("ssl.cert_reqs"))
88
79
        stack = config.MemoryStack("ssl.cert_reqs = required\n")
89
80
        self.assertEquals(ssl.CERT_REQUIRED, stack.get("ssl.cert_reqs"))
90
81
        stack = config.MemoryStack("ssl.cert_reqs = invalid\n")