ソースを参照

libnetwork: assert DNS replies are well-formed

The well-formedness of a DNS message is only checked when it is
serialized, through the (*dns.Msg).Pack() method. Add a call to Pack()
to our tstwriter mock to mirror the behaviour of the real
dns.ResponseWriter implementation. And fix tests which generated
ill-formed DNS query messages.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 1 年間 前
コミット
1da85f7bdc
2 ファイル変更7 行追加3 行削除
  1. 4 0
      libnetwork/resolver_test.go
  2. 3 3
      libnetwork/resolver_unix_test.go

+ 4 - 0
libnetwork/resolver_test.go

@@ -38,6 +38,10 @@ type tstwriter struct {
 }
 
 func (w *tstwriter) WriteMsg(m *dns.Msg) (err error) {
+	// Assert that the message is serializable.
+	if _, err := m.Pack(); err != nil {
+		return err
+	}
 	w.msg = m
 	return nil
 }

+ 3 - 3
libnetwork/resolver_unix_test.go

@@ -61,7 +61,7 @@ func TestDNSIPQuery(t *testing.T) {
 
 	// test name1's IP is resolved correctly with the default A type query
 	// Also make sure DNS lookups are case insensitive
-	names := []string{"name1", "NaMe1"}
+	names := []string{"name1.", "NaMe1."}
 	for _, name := range names {
 		q := new(dns.Msg)
 		q.SetQuestion(name, dns.TypeA)
@@ -84,7 +84,7 @@ func TestDNSIPQuery(t *testing.T) {
 
 	// test MX query with name1 results in Success response with 0 answer records
 	q := new(dns.Msg)
-	q.SetQuestion("name1", dns.TypeMX)
+	q.SetQuestion("name1.", dns.TypeMX)
 	r.serveDNS(w, q)
 	resp := w.GetResponse()
 	checkNonNullResponse(t, resp)
@@ -96,7 +96,7 @@ func TestDNSIPQuery(t *testing.T) {
 	// test MX query with non existent name results in ServFail response with 0 answer records
 	// since this is a unit test env, we disable proxying DNS above which results in ServFail rather than NXDOMAIN
 	q = new(dns.Msg)
-	q.SetQuestion("nonexistent", dns.TypeMX)
+	q.SetQuestion("nonexistent.", dns.TypeMX)
 	r.serveDNS(w, q)
 	resp = w.GetResponse()
 	checkNonNullResponse(t, resp)