@@ -4,8 +4,10 @@ package caddy_remote_host_test
4
4
// methods see package caddy_remote_host.
5
5
6
6
import (
7
+ "fmt"
7
8
"testing"
8
9
10
+ "github.com/caddyserver/caddy/v2"
9
11
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
10
12
plugin "github.com/muety/caddy-remote-host"
11
13
"github.com/stretchr/testify/assert"
@@ -114,3 +116,51 @@ func TestMatchRemoteHost_UnmarshalCaddyfile_invalid(t *testing.T) {
114
116
})
115
117
}
116
118
}
119
+
120
+ func TestMatchRemoteHost_Validate (t * testing.T ) {
121
+ for name , hosts := range map [string ][]string {
122
+ "single" : {"example" },
123
+ "simple" : {"example.com" },
124
+ "multiple" : {"example.com" , "example.org" },
125
+ "subdomain" : {"sub.example.com" },
126
+ "hyphens" : {"ex-am-ple.com" },
127
+ "digits" : {"example24.com" },
128
+ "leading digits" : {"42example.org" },
129
+ "only digits" : {"42.example" },
130
+ } {
131
+ hosts := hosts
132
+ t .Run (name , func (t * testing.T ) {
133
+ t .Parallel ()
134
+
135
+ subject := plugin.MatchRemoteHost {Hosts : hosts }
136
+ require .NoError (t , subject .Provision (caddy.Context {}))
137
+ assert .NoError (t , subject .Validate ())
138
+ })
139
+ }
140
+ }
141
+
142
+ func TestMatchRemoteHost_Validate_invalid (t * testing.T ) {
143
+ require := require .New (t )
144
+ assert := assert .New (t )
145
+
146
+ for name , host := range map [string ]string {
147
+ "dot" : "." ,
148
+ "double dot" : "example..com" ,
149
+ "leading dot" : ".example.org" ,
150
+ "leading dash" : "-example.org" ,
151
+ "trailing dash" : "example-.org" ,
152
+ "underscore" : "_http.example" ,
153
+ "non-acsii" : "ëxample.com" ,
154
+ "wildcard" : "*.example.com" ,
155
+ } {
156
+ host := host
157
+ t .Run (name , func (t * testing.T ) {
158
+ t .Parallel ()
159
+
160
+ subject := plugin.MatchRemoteHost {Hosts : []string {host }}
161
+ require .NoError (subject .Provision (caddy.Context {}))
162
+ assert .EqualError (subject .Validate (),
163
+ fmt .Sprintf ("'%s' is not a valid host name" , host ))
164
+ })
165
+ }
166
+ }
0 commit comments