fix(netxlite): map servfail error (#728)

This error occurred for example when querying kazemjalali.com
in websteps measurements run from Iran.

This error is relatively uncommon, but it still makes sense to
create a specific mapping rule for it.

Originally: 4269e82fbd

See https://github.com/ooni/probe/issues/2096
This commit is contained in:
Simone Basso 2022-05-13 19:25:22 +02:00 committed by GitHub
parent b872dd0e1e
commit 5904e6988d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 3 deletions

View File

@ -248,11 +248,17 @@ const (
// unexported errors used by the Go standard library.
var (
ErrOODNSNoSuchHost = fmt.Errorf("ooniresolver: %s", DNSNoSuchHostSuffix)
ErrOODNSRefused = errors.New("ooniresolver: refused")
ErrOODNSMisbehaving = fmt.Errorf("ooniresolver: %s", DNSServerMisbehavingSuffix)
ErrOODNSNoAnswer = fmt.Errorf("ooniresolver: %s", DNSNoAnswerSuffix)
)
// These errors are not part of the Go standard library but we can
// return them in our custom resolvers.
var (
ErrOODNSRefused = errors.New("ooniresolver: refused")
ErrOODNSServfail = errors.New("ooniresolver: servfail")
)
// classifyResolverError maps DNS resolution errors to
// OONI failure strings.
//
@ -278,6 +284,9 @@ func classifyResolverError(err error) string {
if errors.Is(err, ErrOODNSRefused) {
return FailureDNSRefusedError // not in MK
}
if errors.Is(err, ErrOODNSServfail) {
return FailureDNSServfailError
}
return classifyGenericError(err)
}

View File

@ -269,6 +269,12 @@ func TestClassifyResolverError(t *testing.T) {
}
})
t.Run("for servfail", func(t *testing.T) {
if classifyResolverError(ErrOODNSServfail) != FailureDNSServfailError {
t.Fatal("unexpected result")
}
})
t.Run("for another kind of error", func(t *testing.T) {
if classifyResolverError(io.EOF) != FailureEOFError {
t.Fatal("unexpected result")

View File

@ -22,6 +22,8 @@ func (d *DNSDecoderMiekg) parseReply(data []byte) (*dns.Msg, error) {
return nil, ErrOODNSNoSuchHost
case dns.RcodeRefused:
return nil, ErrOODNSRefused
case dns.RcodeServerFailure:
return nil, ErrOODNSServfail
default:
return nil, ErrOODNSMisbehaving
}

View File

@ -47,6 +47,18 @@ func TestDNSDecoder(t *testing.T) {
}
})
t.Run("Servfail", func(t *testing.T) {
d := &DNSDecoderMiekg{}
data, err := d.DecodeLookupHost(
dns.TypeA, dnsGenReplyWithError(t, dns.TypeA, dns.RcodeServerFailure))
if !errors.Is(err, ErrOODNSServfail) {
t.Fatal("not the error we expected", err)
}
if data != nil {
t.Fatal("expected nil data here")
}
})
t.Run("no address", func(t *testing.T) {
d := &DNSDecoderMiekg{}
data, err := d.DecodeLookupHost(dns.TypeA, dnsGenLookupHostReplySuccess(t, dns.TypeA))

View File

@ -8,7 +8,6 @@ import (
)
func TestDNSEncoder(t *testing.T) {
t.Run("encode A", func(t *testing.T) {
e := &DNSEncoderMiekg{}
data, err := e.Encode("x.org", dns.TypeA, false)

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// Generated: 2022-04-12 11:15:59.316541 +0200 CEST m=+0.537932501
// Generated: 2022-05-13 19:09:07.343096 +0200 CEST m=+0.512294417
package netxlite
@ -26,6 +26,7 @@ const (
FailureDNSNonRecoverableFailure = "dns_non_recoverable_failure"
FailureDNSRefusedError = "dns_refused_error"
FailureDNSServerMisbehaving = "dns_server_misbehaving"
FailureDNSServfailError = "dns_servfail_error"
FailureDNSTemporaryFailure = "dns_temporary_failure"
FailureDestinationAddressRequired = "destination_address_required"
FailureEOFError = "eof_error"
@ -75,6 +76,7 @@ var failuresMap = map[string]string{
"dns_nxdomain_error": "dns_nxdomain_error",
"dns_refused_error": "dns_refused_error",
"dns_server_misbehaving": "dns_server_misbehaving",
"dns_servfail_error": "dns_servfail_error",
"dns_temporary_failure": "dns_temporary_failure",
"eof_error": "eof_error",
"generic_timeout_error": "generic_timeout_error",

View File

@ -158,6 +158,7 @@ var Specs = []*ErrorSpec{
NewLibraryError("DNS_refused_error"),
NewLibraryError("DNS_server_misbehaving"),
NewLibraryError("DNS_no_answer"),
NewLibraryError("DNS_servfail_error"),
NewLibraryError("EOF_error"),
NewLibraryError("generic_timeout_error"),
NewLibraryError("QUIC_incompatible_version"),