@@ -2,8 +2,11 @@ package hinting
2
2
3
3
import (
4
4
"crypto/rand"
5
+ "fmt"
5
6
"net"
6
7
"net/netip"
8
+ "os"
9
+ "strings"
7
10
"testing"
8
11
9
12
"github.com/stretchr/testify/assert"
@@ -160,13 +163,46 @@ func TestReverseLookupWHOIS(t *testing.T) {
160
163
t .Log (tc .name )
161
164
for _ , v := range tc .values {
162
165
t .Log (v .ip )
163
- res := reverseLookupWhois (v .ip )
166
+ res := reverseLookupWHOIS (v .ip )
164
167
t .Log (res )
165
- assert .Subset (t , res , []string {v .domain }, "" )
168
+ assert .Subset (t , res , []string {v .domain },
169
+ "WHOIS record for IP `%s` does not contain contact information with the domain `%s`.\n " +
170
+ "Run `go test -v -run TestWHOISInfo ./hinting/dns_search_domain_fallbacks_test.go -args IP domain`" +
171
+ " to debug WHOIS information for `IP` and expected `domain`." ,
172
+ v .ip , v .domain )
166
173
}
167
174
}
168
175
}
169
176
177
+ func TestWHOISInfo (t * testing.T ) {
178
+ if ! strings .Contains (fmt .Sprintln (os .Args ), "-test.run=" ) {
179
+ return
180
+ }
181
+ // Manual test for debugging with -run
182
+ args := strings .Fields (strings .Split (fmt .Sprintln (os .Args ), "-test.run=" )[1 ])
183
+ if len (args ) == 1 {
184
+ // Do not run when not explicitly called with test arguments.
185
+ return
186
+ }
187
+ if len (args ) != 3 {
188
+ assert .FailNow (t , "Call TestWHOISInfo with" +
189
+ "`go test -v -run TestWHOISInfo ./hinting/dns_search_domain_fallbacks_test.go -args IP domain`" ,
190
+ "args: %s" , os .Args )
191
+ }
192
+ arg1 := netip .MustParseAddr (args [1 ])
193
+ arg2 := args [2 ]
194
+ addr := arg1
195
+ response , err := resolveWHOISRedirects (addr , ianaWHOIS )
196
+ if err != nil {
197
+ assert .FailNow (t , "WHOIS lookup failed" , "err: %s" , err )
198
+ }
199
+ domains := extractEmailDomains (response )
200
+ assert .Subset (t , domains , []string {arg2 },
201
+ "WHOIS record for IP `%s` does not contain contact information with the domain `%s`.\n " +
202
+ "Full WHOIS: %s" ,
203
+ arg1 , arg2 , response )
204
+ }
205
+
170
206
func TestDomainsFromHostnamesDerivation (t * testing.T ) {
171
207
testCases := []struct {
172
208
name string
@@ -183,13 +219,14 @@ func TestDomainsFromHostnamesDerivation(t *testing.T) {
183
219
}{
184
220
{hostnames : []string {"82-130-64-0.net4.ethz.ch." }, domains : []string {"net4.ethz.ch" , "ethz.ch" }},
185
221
{hostnames : []string {"service-id-api-cd-dcz1-server-4-b.ethz.ch." }, domains : []string {"ethz.ch" }},
222
+ {hostnames : []string {"cms-publish." }, domains : []string {"local" }},
186
223
},
187
224
},
188
225
{
189
- name : "ETHZ " ,
226
+ name : "KU " ,
190
227
values : []struct {
191
228
hostnames []string
192
- domains []string
229
+ domains []string
193
230
}{
194
231
{hostnames : []string {"60.korea.ac.kr." , "sub.korea.ac.kr." }, domains : []string {"korea.ac.kr" }},
195
232
},
0 commit comments