44 "context"
55 "fmt"
66 "net"
7+ "net/http"
78 "reflect"
89 "testing"
910
@@ -27,8 +28,8 @@ func assertCritical(t *testing.T, val, expected interface{}) {
2728// and expected certificate name.
2829// If one of them doesn't match, or the resolution function returned with an
2930// error, it aborts the current test.
30- func testResolve (t * testing.T , serverName spec.ServerName , destination , host , certName string ) {
31- res , err := ResolveServer (context .Background (), serverName )
31+ func testResolve (t * testing.T , client * http. Client , serverName spec.ServerName , destination , host , certName string ) {
32+ res , err := ResolveServer (context .Background (), client , serverName )
3233 assertCritical (t , err , nil )
3334 assertCritical (t , len (res ), 1 )
3435 assertCritical (t , res [0 ].Destination , destination )
@@ -40,6 +41,7 @@ func testResolve(t *testing.T, serverName spec.ServerName, destination, host, ce
4041func TestResolutionIPLiteral (t * testing.T ) {
4142 testResolve (
4243 t ,
44+ http .DefaultClient ,
4345 spec .ServerName ("42.42.42.42" ), // The server name is an IP literal without a port
4446 "42.42.42.42:8448" , // Destination must be the IP address + port 8448
4547 "42.42.42.42" , // Host must be the IP address
@@ -51,6 +53,7 @@ func TestResolutionIPLiteral(t *testing.T) {
5153func TestResolutionIPv6Literal (t * testing.T ) {
5254 testResolve (
5355 t ,
56+ http .DefaultClient ,
5457 spec .ServerName ("[42:42::42]" ), // The server name is an IP literal without a port
5558 "[42:42::42]:8448" , // Destination must be the IP address + port 8448
5659 "[42:42::42]" , // Host must be the IP address
@@ -62,6 +65,7 @@ func TestResolutionIPv6Literal(t *testing.T) {
6265func TestResolutionIPLiteralWithPort (t * testing.T ) {
6366 testResolve (
6467 t ,
68+ http .DefaultClient ,
6569 spec .ServerName ("42.42.42.42:443" ), // The server name is an IP literal with a port
6670 "42.42.42.42:443" , // Destination must be the IP address + port
6771 "42.42.42.42:443" , // Host must be the IP address + port
@@ -73,6 +77,7 @@ func TestResolutionIPLiteralWithPort(t *testing.T) {
7377func TestResolutionIPv6LiteralWithPort (t * testing.T ) {
7478 testResolve (
7579 t ,
80+ http .DefaultClient ,
7681 spec .ServerName ("[42:42::42]:443" ), // The server name is an IP literal with a port
7782 "[42:42::42]:443" , // Destination must be the IP address + port
7883 "[42:42::42]:443" , // Host must be the IP address + port
@@ -84,6 +89,7 @@ func TestResolutionIPv6LiteralWithPort(t *testing.T) {
8489func TestResolutionHostnameAndPort (t * testing.T ) {
8590 testResolve (
8691 t ,
92+ http .DefaultClient ,
8793 spec .ServerName ("example.com:4242" ), // The server name is not an IP literal and includes an explicit port
8894 "example.com:4242" , // Destination must be the hostname + port
8995 "example.com:4242" , // Host must be the hostname + port
@@ -102,6 +108,7 @@ func TestResolutionHostnameWellKnownWithIPLiteral(t *testing.T) {
102108
103109 testResolve (
104110 t ,
111+ http .DefaultClient ,
105112 spec .ServerName ("example.com" ), // The server name is a domain hosting a .well-known file which specifies an IP literal without a port
106113 "42.42.42.42:8448" , // Destination must be the IP literal + port 8448
107114 "42.42.42.42" , // Host must be the IP literal
@@ -120,6 +127,7 @@ func TestResolutionHostnameWellKnownWithIPLiteralAndPort(t *testing.T) {
120127
121128 testResolve (
122129 t ,
130+ http .DefaultClient ,
123131 spec .ServerName ("example.com" ), // The server name is a domain hosting a .well-known file which specifies an IP literal with a port
124132 "42.42.42.42:443" , // Destination must be the IP literal + port
125133 "42.42.42.42:443" , // Host must be the IP literal + port
@@ -138,6 +146,7 @@ func TestResolutionHostnameWellKnownWithHostnameAndPort(t *testing.T) {
138146
139147 testResolve (
140148 t ,
149+ http .DefaultClient ,
141150 spec .ServerName ("example.com" ), // The server name is a domain hosting a .well-known file which specifies a hostname that's not an IP literal and has a port
142151 "matrix.example.com:4242" , // Destination must be the hostname + port
143152 "matrix.example.com:4242" , // Host must be the hostname + port
@@ -159,6 +168,7 @@ func TestResolutionHostnameWellKnownWithHostnameSRV(t *testing.T) {
159168
160169 testResolve (
161170 t ,
171+ http .DefaultClient ,
162172 spec .ServerName ("example.com" ), // The server name is a domain hosting a .well-known file which specifies a hostname that's not an IP literal, has no port and for which a SRV record with a non-0 exists
163173 "matrix.otherexample.com:4242" , // Destination must be the hostname + port from the SRV record
164174 "matrix.example.com" , // Host must be the delegated hostname
@@ -180,6 +190,7 @@ func TestResolutionHostnameWellKnownWithHostnameNoSRV(t *testing.T) {
180190
181191 testResolve (
182192 t ,
193+ http .DefaultClient ,
183194 spec .ServerName ("example.com" ), // The server name is a domain hosting a .well-known file which specifies a hostname that's not an IP literal, has no port and for which no SRV record exists
184195 "matrix.example.com:8448" , // Destination must be the delegated hostname + port 8448
185196 "matrix.example.com" , // Host must be the delegated hostname
@@ -194,6 +205,7 @@ func TestResolutionHostnameWithSRV(t *testing.T) {
194205
195206 testResolve (
196207 t ,
208+ http .DefaultClient ,
197209 spec .ServerName ("example.com" ), // The server name is a domain for which a SRV record exists with a non-0 port
198210 "matrix.otherexample.com:4242" , // Destination must be the hostname + port
199211 "example.com" , // Host must be the server name
@@ -214,6 +226,7 @@ func TestResolutionHostnameWithNoWellKnownNorSRV(t *testing.T) {
214226
215227 testResolve (
216228 t ,
229+ http .DefaultClient ,
217230 spec .ServerName ("example.com" ), // The server name is a domain for no .well-known file nor SRV record exist
218231 "example.com:8448" , // Destination must be the hostname + 8448
219232 "example.com" , // Host must be the server name
0 commit comments