-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtraversal_test.go
108 lines (100 loc) · 2.6 KB
/
traversal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0
package resolve
import (
"reflect"
"testing"
)
func TestFQDNToRegistered(t *testing.T) {
var got []string
tests := []struct {
name string
fqdn string
registered string
expected []string
callback func(domain string) bool
}{
{
name: "Full traversal",
fqdn: "www.accessphysiotherapy.com.ezproxy.utica.edu",
registered: "utica.edu",
expected: []string{
"www.accessphysiotherapy.com.ezproxy.utica.edu",
"accessphysiotherapy.com.ezproxy.utica.edu",
"com.ezproxy.utica.edu",
"ezproxy.utica.edu",
"utica.edu",
},
callback: func(domain string) bool {
got = append(got, domain)
return false
},
},
{
name: "Only one domain name",
fqdn: "www.accessphysiotherapy.com.ezproxy.utica.edu",
registered: "utica.edu",
expected: []string{"www.accessphysiotherapy.com.ezproxy.utica.edu"},
callback: func(domain string) bool {
got = append(got, domain)
return true
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got = []string{}
FQDNToRegistered(tt.fqdn, tt.registered, tt.callback)
if !reflect.DeepEqual(got, tt.expected) {
t.Errorf("Unexpected Result, expected %v, got %v", tt.expected, got)
}
})
}
}
func TestRegisteredToFQDN(t *testing.T) {
var got []string
tests := []struct {
name string
fqdn string
registered string
expected []string
callback func(domain string) bool
}{
{
name: "Full traversal",
fqdn: "www.accessphysiotherapy.com.ezproxy.utica.edu",
registered: "utica.edu",
expected: []string{
"utica.edu",
"ezproxy.utica.edu",
"com.ezproxy.utica.edu",
"accessphysiotherapy.com.ezproxy.utica.edu",
"www.accessphysiotherapy.com.ezproxy.utica.edu",
},
callback: func(domain string) bool {
got = append(got, domain)
return false
},
},
{
name: "Only one domain name",
fqdn: "www.accessphysiotherapy.com.ezproxy.utica.edu",
registered: "utica.edu",
expected: []string{"utica.edu"},
callback: func(domain string) bool {
got = append(got, domain)
return true
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got = []string{}
RegisteredToFQDN(tt.registered, tt.fqdn, tt.callback)
if !reflect.DeepEqual(got, tt.expected) {
t.Errorf("Unexpected Result, expected %v, got %v", tt.expected, got)
}
})
}
}