|
| 1 | +package hinting |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/assert" |
| 5 | + "net/netip" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestReverseLookupDomains(t *testing.T) { |
| 10 | + |
| 11 | + testCases := []struct { |
| 12 | + name string |
| 13 | + values []struct { |
| 14 | + ip netip.Addr |
| 15 | + domain string |
| 16 | + } |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "ETHZ", |
| 20 | + values: []struct { |
| 21 | + ip netip.Addr |
| 22 | + domain string |
| 23 | + }{ |
| 24 | + {ip: netip.MustParseAddr("129.132.19.216"), domain: "ethz.ch"}, |
| 25 | + {ip: netip.MustParseAddr("82.130.64.0"), domain: "ethz.ch"}, |
| 26 | + {ip: netip.MustParseAddr("148.187.192.0"), domain: "ethz.ch"}, |
| 27 | + }, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "PU", |
| 31 | + values: []struct { |
| 32 | + ip netip.Addr |
| 33 | + domain string |
| 34 | + }{ |
| 35 | + {ip: netip.MustParseAddr("66.180.178.131"), domain: "princeton.edu"}, |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "VU", |
| 40 | + values: []struct { |
| 41 | + ip netip.Addr |
| 42 | + domain string |
| 43 | + }{ |
| 44 | + {ip: netip.MustParseAddr("128.143.33.137"), domain: "virginia.edu"}, |
| 45 | + {ip: netip.MustParseAddr("128.143.33.144"), domain: "virginia.edu"}, |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "SWITCH", |
| 50 | + values: []struct { |
| 51 | + ip netip.Addr |
| 52 | + domain string |
| 53 | + }{ |
| 54 | + {ip: netip.MustParseAddr("130.59.31.80"), domain: "switch.ch"}, |
| 55 | + }, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "KREONET", |
| 59 | + values: []struct { |
| 60 | + ip netip.Addr |
| 61 | + domain string |
| 62 | + }{ |
| 63 | + {ip: netip.MustParseAddr("134.75.254.11"), domain: "kreonet.net"}, |
| 64 | + {ip: netip.MustParseAddr("134.75.254.12"), domain: "kreonet.net"}, |
| 65 | + }, |
| 66 | + }, |
| 67 | + { |
| 68 | + name: "KU", |
| 69 | + values: []struct { |
| 70 | + ip netip.Addr |
| 71 | + domain string |
| 72 | + }{ |
| 73 | + {ip: netip.MustParseAddr("163.152.6.10"), domain: "korea.ac.kr"}, |
| 74 | + }, |
| 75 | + }, |
| 76 | + } |
| 77 | + for _, tc := range testCases { |
| 78 | + t.Log(tc.name) |
| 79 | + for _, v := range tc.values { |
| 80 | + t.Log(v.ip) |
| 81 | + res := reverseLookupDomains(v.ip) |
| 82 | + t.Log(res) |
| 83 | + assert.Subset(t, res, []string{v.domain}, "") |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +func TestDomainsFromHostnamesDerivation(t *testing.T) { |
| 89 | + |
| 90 | + testCases := []struct { |
| 91 | + name string |
| 92 | + values []struct { |
| 93 | + hostnames []string |
| 94 | + domains []string |
| 95 | + } |
| 96 | + }{ |
| 97 | + { |
| 98 | + name: "ETHZ", |
| 99 | + values: []struct { |
| 100 | + hostnames []string |
| 101 | + domains []string |
| 102 | + }{ |
| 103 | + {hostnames: []string{"82-130-64-0.net4.ethz.ch."}, domains: []string{"net4.ethz.ch", "ethz.ch"}}, |
| 104 | + {hostnames: []string{"service-id-api-cd-dcz1-server-4-b.ethz.ch."}, domains: []string{"ethz.ch"}}, |
| 105 | + }, |
| 106 | + }, |
| 107 | + { |
| 108 | + name: "ETHZ", |
| 109 | + values: []struct { |
| 110 | + hostnames []string |
| 111 | + domains []string |
| 112 | + }{ |
| 113 | + {hostnames: []string{"60.korea.ac.kr.", "sub.korea.ac.kr."}, domains: []string{"korea.ac.kr"}}, |
| 114 | + }, |
| 115 | + }, |
| 116 | + } |
| 117 | + |
| 118 | + for _, tc := range testCases { |
| 119 | + t.Log(tc.name) |
| 120 | + for _, v := range tc.values { |
| 121 | + t.Log(v.hostnames) |
| 122 | + res := domainsFromHostnames(v.hostnames) |
| 123 | + t.Log(res) |
| 124 | + assert.EqualValues(t, v.domains, res, "") |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments