예제 #1
0
 def test_mismatch_dns(self):
     """
     If the dns_id doesn't match, verify returns False.
     """
     assert not (
         SRV_ID(u"_mail.foo.com").verify(SRVPattern(b"_mail.bar.com"))
     )
예제 #2
0
 def test_match_idna(self):
     """
     IDNAs are handled properly.
     """
     assert SRV_ID(u"_mail.f\xf8\xf8.com").verify(
         SRVPattern(b'_mail.xn--f-5gaa.com')
     )
예제 #3
0
 def test_mismatch_service_name(self):
     """
     If the service name doesn't match, verify returns False.
     """
     assert not (
         SRV_ID(u"_mail.foo.com").verify(SRVPattern(b"_xmpp.foo.com"))
     )
예제 #4
0
 def test_lowercases(self):
     """
     The service name is lowercased so it can be compared
     case-insensitively.
     """
     srv_id = SRV_ID(u"_MaIl.foo.com")
     assert b"mail" == srv_id.name
예제 #5
0
 def test_optional_missing(self):
     """
     Optional IDs may miss as long as they don't conflict with an existing
     pattern.
     """
     p = DNSPattern(b"mail.foo.com")
     i = DNS_ID(u"mail.foo.com")
     rv = verify_service_identity([p],
                                  obligatory_ids=[i],
                                  optional_ids=[SRV_ID(u"_mail.foo.com")])
     assert [ServiceMatch(cert_pattern=p, service_id=i)] == rv
예제 #6
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
예제 #7
0
 def test_optional_mismatch(self):
     """
     Raise VerificationError if an ID from optional_ids does not match
     a pattern of respective type even if obligatory IDs match.
     """
     i = SRV_ID(u"_xmpp.example.com")
     with pytest.raises(VerificationError) as e:
         verify_service_identity(
             [DNSPattern(b"example.net"), SRVPattern(b"_mail.example.com")],
             obligatory_ids=[DNS_ID(u"example.net")],
             optional_ids=[i],
         )
     assert [SRVMismatch(mismatched_id=i)] == e.value.errors
예제 #8
0
 def test_contains_optional_and_matches(self):
     """
     If an optional ID is found, return the match within the returned
     list and don't raise an error.
     """
     p = SRVPattern(b"_mail.example.net")
     i = SRV_ID(u"_mail.example.net")
     rv = verify_service_identity(
         [DNSPattern(b"example.net"), p],
         obligatory_ids=[DNS_ID(u"example.net")],
         optional_ids=[i],
     )
     assert ServiceMatch(cert_pattern=p, service_id=i) == rv[1]
예제 #9
0
 def test_match(self):
     """
     Accept legal matches.
     """
     assert SRV_ID(u"_mail.foo.com").verify(SRVPattern(b"_mail.foo.com"))
예제 #10
0
 def test_is_only_valid_for_SRV(self):
     """
     If anything else than an SRVPattern is passed to verify, return False.
     """
     assert not SRV_ID(u"_mail.foo.com").verify(object())
예제 #11
0
 def test_catches_missing_underscore(self):
     """
     Raise ValueError if the service is doesn't start with an underscore.
     """
     with pytest.raises(ValueError):
         SRV_ID(u"imaps.foo.com")
예제 #12
0
 def test_catches_missing_dot(self):
     """
     Raise ValueError if there's no dot within a SRV-ID.
     """
     with pytest.raises(ValueError):
         SRV_ID(u"_imapsfoocom")
예제 #13
0
 def test_create_DNS_ID(self):
     """
     The hostname is converted into a DNS_ID object.
     """
     srv_id = SRV_ID(u"_mail.example.com")
     assert DNS_ID(u"example.com") == srv_id.dns_id
예제 #14
0
 def test_enforces_unicode(self):
     """
     Raise TypeError if pass srv-ID is not unicode.
     """
     with pytest.raises(TypeError):
         SRV_ID(b"_mail.example.com")