11package main
22
33import (
4+ "fmt"
45 "net/http"
56 "reflect"
67 "testing"
@@ -21,6 +22,7 @@ func TestDNSProxy_getResponse(t *testing.T) {
2122 Cache := InitCache (60 * 1000000000 )
2223 rrDnsGoogle , _ := dns .NewRR ("dns.google. IN A 8.8.8.8" )
2324 rrDnsTest , _ := dns .NewRR ("test.com. IN A 67.225.146.248" )
25+ rrDnsNotAllowed , _ := dns .NewRR (fmt .Sprintf ("notallowed.com. IN A %s" , StepSecuritySinkHoleIPAddress ))
2426 rrDnsAllowed , _ := dns .NewRR ("allowed.com. IN A 67.225.146.248" )
2527
2628 apiclient := & ApiClient {Client : & http.Client {}, APIURL : agentApiBaseUrl }
@@ -33,6 +35,9 @@ func TestDNSProxy_getResponse(t *testing.T) {
3335 httpmock .RegisterResponder ("GET" , "https://dns.google/resolve?name=allowed.com.&type=a" ,
3436 httpmock .NewStringResponder (200 , `{"Status":0,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,"Question":[{"name":"allowed.com.","type":1}],"Answer":[{"name":"allowed.com.","type":1,"TTL":3080,"data":"67.225.146.248"}]}` ))
3537
38+ httpmock .RegisterResponder ("GET" , "https://dns.google/resolve?name=notfound.com.&type=a" ,
39+ httpmock .NewStringResponder (200 , `{"Status":3,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,"Question":[{"name":"notfound.com.","type":1}],"Authority":[{"name":"com.","type":6,"TTL":900,"data":"a.gtld-servers.net. nstld.verisign-grs.com. 1640040308 1800 900 604800 86400"}],"Comment":"Response from 2001:503:231d::2:30."}` ))
40+
3641 tests := []struct {
3742 name string
3843 fields fields
@@ -61,8 +66,8 @@ func TestDNSProxy_getResponse(t *testing.T) {
6166 {name : "type A notallowed.com" ,
6267 fields : fields {Cache : & Cache , EgressPolicy : EgressPolicyBlock , AllowedEndpoints : []Endpoint {{domainName : "allowed.com" }}},
6368 args : args {requestMsg : & dns.Msg {Question : []dns.Question {{Name : "notallowed.com." , Qtype : dns .TypeA }}}},
64- want : & dns.Msg {},
65- wantErr : true ,
69+ want : & dns.Msg {Answer : []dns. RR { rrDnsNotAllowed } },
70+ wantErr : false ,
6671 },
6772 {name : "type A test.com egress policy cached" ,
6873 fields : fields {Cache : & Cache , EgressPolicy : EgressPolicyBlock , AllowedEndpoints : []Endpoint {{domainName : "test.com" }}},
@@ -76,6 +81,12 @@ func TestDNSProxy_getResponse(t *testing.T) {
7681 want : & dns.Msg {Answer : []dns.RR {rrDnsAllowed }},
7782 wantErr : false ,
7883 },
84+ {name : "type A notfound.com" ,
85+ fields : fields {Cache : & Cache , EgressPolicy : EgressPolicyAudit },
86+ args : args {requestMsg : & dns.Msg {Question : []dns.Question {{Name : "notfound.com." , Qtype : dns .TypeA }}}},
87+ want : & dns.Msg {},
88+ wantErr : true ,
89+ },
7990 }
8091 for _ , tt := range tests {
8192 t .Run (tt .name , func (t * testing.T ) {
0 commit comments