}{
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
}, true,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
}, false,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAnswer: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*7200.*"},
FailIfNotMatchesRegexp: []string{".*3600.*"},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAuthority: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*7200.*"},
},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAdditional: config.DNSRRValidator{
FailIfNotMatchesRegexp: []string{".*3600.*"},
},
}{
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
}, true,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- QueryType: "SOA",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ QueryType: "SOA",
}, true,
}, {
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
}, false,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAnswer: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*3600.*"},
FailIfNotMatchesRegexp: []string{".*3600.*"},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAnswer: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*7200.*"},
FailIfNotMatchesRegexp: []string{".*7200.*"},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAuthority: config.DNSRRValidator{
FailIfNotMatchesRegexp: []string{"ns.*.isp.net"},
},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAdditional: config.DNSRRValidator{
FailIfNotMatchesRegexp: []string{"^ns.*.isp"},
},
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
ValidateAdditional: config.DNSRRValidator{
FailIfMatchesRegexp: []string{"^ns.*.isp"},
},
}{
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
}, false,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
}, true,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- QueryType: "NOT_A_VALID_QUERY_TYPE",
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ QueryType: "NOT_A_VALID_QUERY_TYPE",
}, false,
},
{
config.DNSProbe{
- IPProtocol: "ipv4",
- QueryName: "example.com",
- ValidRcodes: []string{"NOT_A_VALID_RCODE"},
+ IPProtocol: "ip4",
+ IPProtocolFallback: true,
+ QueryName: "example.com",
+ ValidRcodes: []string{"NOT_A_VALID_RCODE"},
}, false,
},
}
package prober
import (
+ "context"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"fmt"
"math/big"
"net"
+ "os"
"testing"
"time"
+ "github.com/go-kit/kit/log"
+
+ "github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
pemKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privatekey)})
return pemCert, pemKey
}
+
+func TestChooseProtocol(t *testing.T) {
+ ctx := context.Background()
+ registry := prometheus.NewPedanticRegistry()
+ w := log.NewSyncWriter(os.Stderr)
+ logger := log.NewLogfmtLogger(w)
+
+ ip, _, err := chooseProtocol(ctx, "ip4", true, "ipv6.google.com", registry, logger)
+ if err != nil {
+ t.Error(err)
+ }
+ if ip == nil || ip.IP.To4() != nil {
+ t.Error("with fallback it should answer")
+ }
+
+ registry = prometheus.NewPedanticRegistry()
+
+ ip, _, err = chooseProtocol(ctx, "ip4", false, "ipv6.google.com", registry, logger)
+ if err != nil && err.Error() != "unable to find ip; no fallback" {
+ t.Error(err)
+ } else if err == nil {
+ t.Error("should set error")
+ }
+ if ip != nil {
+ t.Error("without fallback it should not answer")
+ }
+}