Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <[email protected]>
  • Loading branch information
roidelapluie committed Jul 8, 2020
1 parent d7a68ec commit f1c5fa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
8 changes: 2 additions & 6 deletions prober/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,13 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
}
}

idnTarget, err := internationalizeDNSTarget(logger, module.DNS.QueryName)
if err != nil {
level.Error(logger).Log("msg", "IDN conversion failed", "err", err)
return false
}
queryName := internationalizeDNSDomain(logger, module.DNS.QueryName)

msg := new(dns.Msg)
msg.Id = dns.Id()
msg.RecursionDesired = true
msg.Question = make([]dns.Question, 1)
msg.Question[0] = dns.Question{dns.Fqdn(idnTarget), qt, qc}
msg.Question[0] = dns.Question{dns.Fqdn(queryName), qt, qc}
level.Info(logger).Log("msg", "Making DNS query", "target", target, "dial_protocol", dialProtocol, "query", module.DNS.QueryName, "type", qt, "class", qc)
timeoutDeadline, _ := ctx.Deadline()
client.Timeout = time.Until(timeoutDeadline)
Expand Down
18 changes: 7 additions & 11 deletions prober/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
fallbackProtocol = "ip6"
}

target, err = internationalizeDNSTarget(logger, target)
if err != nil {
level.Error(logger).Log("msg", "IDN conversion failed", "err", err)
return nil, 0.0, err
}
target = internationalizeDNSDomain(logger, target)

level.Info(logger).Log("msg", "Resolving target address", "ip_protocol", IPProtocol)
resolveStart := time.Now()
Expand Down Expand Up @@ -127,13 +123,13 @@ func ipHash(ip net.IP) float64 {
return float64(h.Sum32())
}

func internationalizeDNSTarget(logger log.Logger, target string) (string, error) {
idnaTarget, err := idna.Lookup.ToASCII(target)
func internationalizeDNSDomain(logger log.Logger, domain string) string {
idnaDomain, err := idna.Lookup.ToASCII(domain)
if err != nil {
return target, fmt.Errorf("error while internationalizing target: %w", err)
return domain
}
if idnaTarget != target {
level.Info(logger).Log("msg", "Target address internationalized", "ascii", idnaTarget)
if idnaDomain != domain {
level.Info(logger).Log("msg", "Domain internationalized", "unicode", domain, "ascii", idnaDomain)
}
return idnaTarget, nil
return idnaDomain
}

0 comments on commit f1c5fa9

Please sign in to comment.