summaryrefslogtreecommitdiff
path: root/service/test/unit/bitmask_libraries/test_certs.py
blob: 4a06649ddca13507325e756754905c1eeafad295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest

from pixelated.bitmask_libraries.certs import which_bootstrap_CA_bundle, which_api_CA_bundle
from pixelated.bitmask_libraries.config import AUTO_DETECT_CA_BUNDLE
from mock import MagicMock, patch


class CertsTest(unittest.TestCase):

    @patch('pixelated.bitmask_libraries.certs.os.path.isfile')
    @patch('pixelated.bitmask_libraries.certs.os.path.isdir')
    def test_that_which_bootstrap_cert_bundle_returns_byte_string(self, mock_isdir, mock_isfile):
        mock_isfile.return_value = True
        mock_isdir.return_value = True
        config = MagicMock(bootstrap_ca_cert_bundle=AUTO_DETECT_CA_BUNDLE, leap_home='/leap/home')
        provider = MagicMock(server_name=u'test.leap.net', config=config)

        bundle = which_bootstrap_CA_bundle(provider)

        self.assertEqual('/leap/home/providers/test.leap.net/test.leap.net.ca.crt', bundle)
        self.assertEqual(str, type(bundle))

    @patch('pixelated.bitmask_libraries.certs.os.path.isfile')
    @patch('pixelated.bitmask_libraries.certs.os.path.isdir')
    def test_that_which_bundle_returns_byte_string(self, mock_isdir, mock_isfile):
        mock_isfile.return_value = True
        mock_isdir.return_value = True

        config = MagicMock(bootstrap_ca_cert_bundle=AUTO_DETECT_CA_BUNDLE, ca_cert_bundle=None, leap_home='/some/leap/home')
        provider = MagicMock(server_name=u'test.leap.net', config=config)

        bundle = which_api_CA_bundle(provider)

        self.assertEqual('/some/leap/home/providers/test.leap.net/keys/client/api.pem', bundle)
        self.assertEqual(str, type(bundle))