Ejemplo n.º 1
0
class TestVerificationError(object):
    def test_repr_str(self):
        """
        The __str__ and __repr__ methods return something helpful.
        """
        try:
            raise VerificationError(errors=["foo"])
        except VerificationError as e:
            assert repr(e) == str(e)
            assert str(e) != ""

    @pytest.mark.parametrize("proto", range(0, pickle.HIGHEST_PROTOCOL + 1))
    @pytest.mark.parametrize(
        "exc",
        [
            VerificationError(errors=[]),
            VerificationError(errors=[DNSMismatch("example.com")]),
            VerificationError([]),
            VerificationError([DNSMismatch("example.com")]),
        ],
    )
    def test_pickle(self, exc, proto):
        """
        Exceptions can be pickled and unpickled.
        """
        new_exc = pickle.loads(pickle.dumps(exc, proto))

        # Exceptions can't be compared.
        assert exc.__class__ == new_exc.__class__
        assert exc.__dict__ == new_exc.__dict__
Ejemplo n.º 2
0
    def test_certificate_verify_hostname_fail(self):
        """
        verify_certificate_hostname fails if the hostnames don't match and
        provides the user with helpful information.
        """
        with pytest.raises(VerificationError) as ei:
            verify_certificate_hostname(X509_DNS_ONLY, u"google.com")

        assert [DNSMismatch(mismatched_id=DNS_ID(u"google.com"))
                ] == ei.value.errors
Ejemplo n.º 3
0
 def test_integration_dns_id_fail(self):
     """
     Raise VerificationError if no certificate id matches the supplied
     service ids.
     """
     i = DNS_ID(u"wrong.host")
     with pytest.raises(VerificationError) as e:
         verify_service_identity(DNS_IDS,
                                 obligatory_ids=[i],
                                 optional_ids=[])
     assert [DNSMismatch(mismatched_id=i)] == e.value.errors
Ejemplo n.º 4
0
 def test_obligatory_mismatch(self):
     """
     Raise if one of the obligatory IDs doesn't match.
     """
     i = DNS_ID(u"example.net")
     with pytest.raises(VerificationError) as e:
         verify_service_identity(
             [SRVPattern(b"_mail.example.net"), DNSPattern(b"example.com")],
             obligatory_ids=[SRV_ID(u"_mail.example.net"), i],
             optional_ids=[],
         )
     assert [DNSMismatch(mismatched_id=i)] == e.value.errors
    def test_verify_hostname_fail(self):
        """
        verify_hostname fails if the hostnames don't match and provides the
        user with helpful information.
        """
        class FakeConnection(object):
            def get_peer_certificate(self):
                return CERT_DNS_ONLY

        with pytest.raises(VerificationError) as ei:
            verify_hostname(FakeConnection(), u"google.com")

        assert [DNSMismatch(mismatched_id=DNS_ID(u"google.com"))
                ] == ei.value.errors