@@ -22,15 +22,24 @@ func TestSetDNSNameserversValidation(t *testing.T) {
2222 name : "accepts doh nameserver" ,
2323 args : []string {"set" , "dns" , "nameservers" , "--nameserver" , "https://dns.google/dns-query" },
2424 },
25+ {
26+ name : "accepts empty nameserver to clear list" ,
27+ args : []string {"set" , "dns" , "nameservers" , "--nameserver" , "" },
28+ },
2529 {
2630 name : "rejects malformed nameserver" ,
2731 args : []string {"set" , "dns" , "nameservers" , "--nameserver" , "dns.google" },
28- errContains : " invalid nameserver" ,
32+ errContains : ` invalid nameserver "dns.google"` ,
2933 },
3034 {
3135 name : "rejects non-https doh nameserver" ,
3236 args : []string {"set" , "dns" , "nameservers" , "--nameserver" , "http://dns.google/dns-query" },
33- errContains : "invalid nameserver" ,
37+ errContains : `invalid nameserver "http://dns.google/dns-query"` ,
38+ },
39+ {
40+ name : "rejects out of range doh port" ,
41+ args : []string {"set" , "dns" , "nameservers" , "--nameserver" , "https://dns.google:65536/dns-query" },
42+ errContains : `invalid nameserver "https://dns.google:65536/dns-query"` ,
3443 },
3544 }
3645
@@ -71,7 +80,12 @@ func TestSetDNSSplitValidation(t *testing.T) {
7180 {
7281 name : "rejects invalid nameserver entry" ,
7382 args : []string {"set" , "dns" , "split-dns" , "--entry" , "corp.example.com=dns.google" },
74- errContains : "invalid nameserver" ,
83+ errContains : `invalid nameserver "dns.google"` ,
84+ },
85+ {
86+ name : "rejects malformed entry shape" ,
87+ args : []string {"set" , "dns" , "split-dns" , "--entry" , "corp.example.com" },
88+ errContains : `expect domain=nameserver` ,
7589 },
7690 }
7791
@@ -120,6 +134,24 @@ func TestSetDNSNameserverDoHValuesReachAPI(t *testing.T) {
120134 }
121135 })
122136
137+ t .Run ("nameservers clear list" , func (t * testing.T ) {
138+ mock := apimock .New (t )
139+ mock .AddJSON (http .MethodPost , "/dns/nameservers" , http .StatusOK , map [string ]any {"dns" : []string {}})
140+
141+ res := executeCLI (t , []string {"set" , "dns" , "nameservers" , "--nameserver" , "" }, map [string ]string {"TSCLI_BASE_URL" : mock .URL ()})
142+ if res .err != nil {
143+ t .Fatalf ("unexpected error: %v\n stderr:\n %s" , res .err , res .stderr )
144+ }
145+
146+ reqs := mock .Requests ()
147+ if len (reqs ) == 0 {
148+ t .Fatalf ("expected request to mock API, got none" )
149+ }
150+ if ! strings .Contains (reqs [0 ].Body , `"dns":[]` ) {
151+ t .Fatalf ("expected request body to send an empty list, got %s" , reqs [0 ].Body )
152+ }
153+ })
154+
123155 t .Run ("split dns" , func (t * testing.T ) {
124156 mock := apimock .New (t )
125157 mock .AddJSON (http .MethodPatch , "/dns/split-dns" , http .StatusOK , apimock .DNSSplitConfig ())
0 commit comments