Esempio n. 1
0
 def test_match_hostname_mismatch(self):
     cert = {'subjectAltName': [('DNS', 'foo')]}
     asserted_hostname = 'bar'
     try:
         with mock.patch('urllib3.util.ssl_.log.error') as mock_log:
             match_hostname(cert, asserted_hostname)
     except CertificateError as e:
         assert str(e) == "hostname 'bar' doesn't match 'foo'"
         mock_log.assert_called_once_with(
             'Certificate did not match expected hostname: %s. '
             'Certificate: %s', 'bar', {'subjectAltName': [('DNS', 'foo')]})
         assert e._peer_cert == cert
Esempio n. 2
0
 def test_match_hostname_mismatch(self):
     cert = {"subjectAltName": [("DNS", "foo")]}
     asserted_hostname = "bar"
     try:
         with mock.patch("urllib3.util.ssl_.log.warning") as mock_log:
             match_hostname(cert, asserted_hostname)
     except CertificateError as e:
         assert "hostname 'bar' doesn't match 'foo'" in str(e)
         mock_log.assert_called_once_with(
             "Certificate did not match expected hostname: %s. Certificate: %s",
             "bar",
             {"subjectAltName": [("DNS", "foo")]},
         )
         assert e._peer_cert == cert
Esempio n. 3
0
 def test_match_hostname_match(self):
     cert = {"subjectAltName": [("DNS", "foo")]}
     asserted_hostname = "foo"
     match_hostname(cert, asserted_hostname)
Esempio n. 4
0
 def test_match_hostname_empty_cert(self):
     cert = {}
     asserted_hostname = "foo"
     with pytest.raises(ValueError):
         match_hostname(cert, asserted_hostname)
Esempio n. 5
0
 def test_match_hostname_match(self):
     cert = {'subjectAltName': [('DNS', 'foo')]}
     asserted_hostname = 'foo'
     match_hostname(cert, asserted_hostname)
Esempio n. 6
0
 def test_match_hostname_no_cert(self):
     cert = None
     asserted_hostname = 'foo'
     with pytest.raises(ValueError):
         match_hostname(cert, asserted_hostname)