aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-03-13 20:24:37 +0000
committerGravatar GitHub <noreply@github.com> 2017-03-13 20:24:37 +0000
commitbfaf9e0aecc74d4e6897cdb9c6ef51b4b21ffd4e (patch)
tree1eb571726beee206742fa69d6d97ef80d6dcd48f /test
parent4985d698e2d1e7c8335bff3b39c1d593cf1f02e6 (diff)
downloadcoredns-bfaf9e0aecc74d4e6897cdb9c6ef51b4b21ffd4e.tar.gz
coredns-bfaf9e0aecc74d4e6897cdb9c6ef51b4b21ffd4e.tar.zst
coredns-bfaf9e0aecc74d4e6897cdb9c6ef51b4b21ffd4e.zip
core: add more transports (#574)
* core: add listening for other protocols Allow CoreDNS to listen for TLS request coming over port 853. This can be enabled with `tls://` in the config file. Implement listening for grps:// as well. a Corefile like: ~~~ . tls://.:1853 { whoami tls } ~~~ Means we listen on 1853 for tls requests, the `tls` config item allows configuration for TLS parameters. We *might* be tempted to use Caddy's Let's Encrypt implementation here. * Refactor coredns/grpc into CoreDNS This makes gRPC a first class citizen in CoreDNS. Add defines as being just another server. * some cleanups * unexport the servers * Move protobuf dir * Hook up TLS properly * Fix test * listen for TLS as well. README updates * disable test, fix package * fix test * Fix tests * Fix remaining test * Some tests * Make the test work * Add grpc test from #580 * fix crash * Fix tests * Close conn * README cleanups * README * link RFC
Diffstat (limited to 'test')
-rw-r--r--test/grpc_test.go62
-rw-r--r--test/proxy_test.go2
2 files changed, 63 insertions, 1 deletions
diff --git a/test/grpc_test.go b/test/grpc_test.go
new file mode 100644
index 000000000..f7c47b57c
--- /dev/null
+++ b/test/grpc_test.go
@@ -0,0 +1,62 @@
+package test
+
+import (
+ "io/ioutil"
+ "log"
+ "testing"
+ "time"
+
+ "github.com/miekg/dns"
+ "golang.org/x/net/context"
+ "google.golang.org/grpc"
+
+ "github.com/coredns/coredns/pb"
+)
+
+func TestGrpc(t *testing.T) {
+ log.SetOutput(ioutil.Discard)
+
+ corefile := `grpc://.:0 {
+ whoami
+}
+`
+ g, err := CoreDNSServer(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+
+ _, tcp := CoreDNSServerPorts(g, 0)
+ defer g.Stop()
+
+ conn, err := grpc.Dial(tcp, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(5*time.Second))
+ if err != nil {
+ t.Fatalf("Expected no error but got: %s", err)
+ }
+ defer conn.Close()
+
+ client := pb.NewDnsServiceClient(conn)
+
+ m := new(dns.Msg)
+ m.SetQuestion("whoami.example.org.", dns.TypeA)
+ msg, _ := m.Pack()
+
+ reply, err := client.Query(context.TODO(), &pb.DnsPacket{Msg: msg})
+ if err != nil {
+ t.Errorf("Expected no error but got: %s", err)
+ }
+
+ d := new(dns.Msg)
+ err = d.Unpack(reply.Msg)
+ if err != nil {
+ t.Errorf("Expected no error but got: %s", err)
+ }
+
+ if d.Rcode != dns.RcodeSuccess {
+ t.Errorf("Expected success but got %s", d.Rcode)
+ }
+
+ if len(d.Extra) != 2 {
+ t.Errorf("Expected 2 RRs in additional section, but got %s", len(d.Extra))
+ }
+ t.Logf("Message %v\n", d)
+}
diff --git a/test/proxy_test.go b/test/proxy_test.go
index 7b96582c5..cb9f1b298 100644
--- a/test/proxy_test.go
+++ b/test/proxy_test.go
@@ -46,7 +46,7 @@ func TestLookupProxy(t *testing.T) {
}
// expect answer section with A record in it
if len(resp.Answer) == 0 {
- t.Error("Expected to at least one RR in the answer section, got none")
+ t.Fatalf("Expected to at least one RR in the answer section, got none: %s", resp)
}
if resp.Answer[0].Header().Rrtype != dns.TypeA {
t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)