-
Notifications
You must be signed in to change notification settings - Fork 43
/
dnsmorph_test.go
82 lines (72 loc) · 2.12 KB
/
dnsmorph_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
package main
import (
"testing"
)
/*
Helper functions tests
*/
func TestCountChar(t *testing.T) {
count := countChar("test")
if len(count) != 3 {
t.Error("expected map keys lenght of 4, got", len(count))
}
if count['t'] != 2 {
t.Error("expected count['t'] to be 2, got", count['t'])
}
if count['e'] != 1 {
t.Error("expected count['t'] to be 1, got", count['t'])
}
}
func TestProcessInput(t *testing.T) {
sanitizedInput, tld := processInput("subdomain.test.co.uk")
if sanitizedInput != "test" && tld != "co.uk" {
t.Error("expected 'test' and 'co.uk', got", sanitizedInput, tld)
}
}
func TestDomainValidation(t *testing.T) {
if !validateDomainName("yahoo.co.uk") {
t.Error("expected 'yahoo.co.uk' to be a valid domain")
}
if validateDomainName("test") != false {
t.Error("expected 'test' to be an invalid domain")
}
}
type testcase struct {
testString string
function func(string) []string
expectedResultLen int
firstResult string
}
var tests = []testcase{
{"test", transpositionAttack, 3, "etst"},
{"test", additionAttack, 26, "testa"},
{"test", vowelswapAttack, 5, "tast"},
{"test", subdomainAttack, 3, "t.est"},
{"test", replacementAttack, 31, "6est"},
{"test", repetitionAttack, 4, "ttest"},
{"test", omissionAttack, 4, "est"},
{"test", hyphenationAttack, 3, "t-est"},
{"test", bitsquattingAttack, 31, "test"},
{"test", homographAttack, 27, "τest"},
{"test.test", doppelgangerAttack, 1, "testtest"},
}
func TestAttackResults(t *testing.T) {
for _, test := range tests {
results := test.function(test.testString)
if len(results) != test.expectedResultLen {
t.Errorf("expected array of lenght %d, got %d", test.expectedResultLen, len(results))
}
if results[0] != test.firstResult {
t.Errorf("expected first element of array to be '%s', got %s", test.firstResult, results[0])
}
}
}
func TestWhoisLookup(t *testing.T) {
result := whoisLookup("google.com")
if result[0] != "1997-09-15T04:00:00Z" {
t.Errorf("expected 1997-09-15T04:00:00Z, got %s", result[0])
}
if result[1] != "2019-09-09T15:39:04Z" {
t.Errorf("expected 2019-09-09T15:39:04Z, got %s", result[1])
}
}