GH-3798: A couple more PR updates

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
This commit is contained in:
Matt Keeler 2018-04-12 10:10:37 -04:00
parent 3a0f7789ec
commit aa9151738a
3 changed files with 50 additions and 2 deletions

View File

@ -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

View File

@ -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{}
@ -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)
@ -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) {

View File

@ -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