aboutsummaryrefslogtreecommitdiffstats
path: root/certs/tests/test_fetch.py
blob: 1a84a7a6908f82a9c608e783a7cc079b10069afc (plain) (blame)
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from library.python import resource

import pytest
import ssl
# import urllib2


class TestRequest(object):
    @pytest.fixture
    def ctx(self):
        r = resource.find("/builtin/cacert")
        # ssl.create_default_context expects unicode string for pem-coded certificates
        r = r.decode('ascii', errors='ignore')
        return ssl.create_default_context(cadata=r)

    def test_certs(self, ctx):
        assert any(
            any(item[0] == ("commonName", "YandexInternalRootCA") for item in cert["subject"])
            for cert in ctx.get_ca_certs()
        )
        assert any(
            any(item[0] == ("commonName", "Certum Trusted Network CA") for item in cert["subject"])
            for cert in ctx.get_ca_certs()
        )

    # def test_internal(self, ctx):
    #     connection = urllib2.urlopen("https://nanny.yandex-team.ru/", context=ctx)
    #     assert connection.read()

    # def test_external(self, ctx):
    #     connection = urllib2.urlopen("https://docs.python.org/", context=ctx)
    #     assert connection.read()