Skip to content

Commit

Permalink
GH-3798: A couple more PR updates
Browse files Browse the repository at this point in the history
Test HTTP/DNS source IP without header/extra EDNS data.
Add WARN log for when prepared query with near=_ip is executed without specifying the source ip
  • Loading branch information
mkeeler committed Apr 12, 2018
1 parent cec8d51 commit 136efeb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions agent/consul/prepared_query_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ func (p *PreparedQuery) Execute(args *structs.PreparedQueryExecuteRequest,
break
}
}
} else {
p.srv.logger.Printf("[WARN] Prepared Query using near=_ip requires "+
"the source IP to be set but none was provided. No distance "+
"sorting will be done.")

}

// Either a source IP was given but we couldnt find the associated node
Expand Down
29 changes: 27 additions & 2 deletions agent/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
args := &structs.RegisterRequest{
Datacenter: "dc1",
Node: "bar",
Address: "198.18.0.9",
Address: "127.0.0.1",
}

var out struct{}
Expand Down Expand Up @@ -1937,7 +1937,7 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
e.Family = 1
e.SourceNetmask = 32
e.SourceScope = 0
e.Address = net.ParseIP("198.18.0.9").To4()
e.Address = net.ParseIP("127.0.0.1").To4()
o.Option = append(o.Option, e)
m.Extra = append(m.Extra, o)

Expand All @@ -1961,6 +1961,31 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
}
}
})

retry.Run(t, func(r *retry.R) {
m := new(dns.Msg)
m.SetQuestion("some.query.we.like.query.consul.", dns.TypeA)

c := new(dns.Client)
in, _, err := c.Exchange(m, a.DNSAddr())
if err != nil {
r.Fatalf("Error with call to dns.Client.Exchange: %s", err)
}

if len(serviceNodes) != len(in.Answer) {
r.Fatalf("Expecting %d A RRs in response, Actual found was %d", len(serviceNodes), len(in.Answer))
}

for i, rr := range in.Answer {
if aRec, ok := rr.(*dns.A); ok {
if actual := aRec.A.String(); serviceNodes[i].address != actual {
r.Fatalf("Expecting A RR #%d = %s, Actual RR was %s", i, serviceNodes[i].address, actual)
}
} else {
r.Fatalf("DNS Answer contained a non-A RR")
}
}
})
}

func TestDNS_ServiceLookup_PreparedQueryNamePeriod(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions agent/prepared_query_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,24 @@ func TestPreparedQuery_Execute(t *testing.T) {
if r.Failovers != 99 {
t.Fatalf("bad: %v", r)
}

req, _ = http.NewRequest("GET", "/v1/query/my-id/execute?token=my-token&consistent=true&near=_ip&limit=5", body)
req.RemoteAddr = "127.0.0.1:12345"
resp = httptest.NewRecorder()
obj, err = a.srv.PreparedQuerySpecific(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != 200 {
t.Fatalf("bad code: %d", resp.Code)
}
r, ok = obj.(structs.PreparedQueryExecuteResponse)
if !ok {
t.Fatalf("unexpected: %T", obj)
}
if r.Failovers != 99 {
t.Fatalf("bad: %v", r)
}
})

// Ensure the proper params are set when no special args are passed
Expand Down

0 comments on commit 136efeb

Please sign in to comment.