-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdomain_test.go
137 lines (129 loc) · 2.7 KB
/
domain_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package thirdparty
import (
"context"
"fmt"
"strings"
"testing"
"github.com/code-payments/code-server/pkg/code/common"
"github.com/code-payments/code-server/pkg/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetAsciiBaseDomain(t *testing.T) {
for _, tc := range []struct {
input string
expected string
isError bool
}{
{
input: "app.getcode.com",
expected: "getcode.com",
},
{
input: "app.getcode.com",
expected: "getcode.com",
},
{
input: "subdomain.bücher.com",
expected: "xn--bcher-kva.com",
},
{
input: "bücher.com",
expected: "xn--bcher-kva.com",
},
{
input: "💩.domain.com",
expected: "domain.com",
},
{
input: "google-énçøded.com",
expected: "xn--google-nded-t9ay6s.com",
},
{
input: "subdomain.💩.io",
expected: "xn--ls8h.io",
},
{
input: "localhost",
isError: true,
},
{
input: fmt.Sprintf("%s.com", strings.Repeat("1", 64)),
isError: true,
},
{
input: fmt.Sprintf("%s.com", strings.Repeat("1", 250)),
isError: true,
},
} {
actual, err := GetAsciiBaseDomain(tc.input)
if tc.isError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.expected, actual)
}
}
}
func TestGetDomainDisplayValue(t *testing.T) {
for _, tc := range []struct {
input string
expected string
isError bool
}{
{
input: "app.getcode.com",
expected: "App.getcode.com",
},
{
input: "getcode.com",
expected: "Getcode.com",
},
{
input: "UPPERCASE.com",
expected: "Uppercase.com",
},
{
input: "xn--bcher-kva.com",
expected: "Bücher.com",
},
{
input: "xn--cher-zra.com",
expected: "Ücher.com",
},
{
input: "xn--google-nded-t9ay6s.com",
expected: "Google-Énçøded.com",
},
{
input: "xn--ls8h.io",
expected: "💩.io",
},
{
input: "localhost",
isError: true,
},
} {
actual, err := GetDomainDisplayName(tc.input)
if tc.isError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tc.expected, actual)
}
}
}
func TestVerifyDomainNameOwnership(t *testing.T) {
ctx := context.Background()
validAuthority, err := common.NewAccountFromPublicKeyString("McS32C1q6Rv1odkEoR5g1xtFBN7TdbkLFvGeyvQtzLF")
require.NoError(t, err)
maliciousAuthority := testutil.NewRandomAccount(t)
for _, authority := range []*common.Account{
validAuthority,
maliciousAuthority,
} {
isVerified, err := VerifyDomainNameOwnership(ctx, authority, "app.getcode.com")
require.NoError(t, err)
assert.Equal(t, authority.PublicKey().ToBase58() == validAuthority.PublicKey().ToBase58(), isVerified)
}
}