@@ -18,6 +18,7 @@ package db
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"testing"
22
23
"time"
23
24
@@ -40,17 +41,21 @@ func TestProxyProtocolPostgres(t *testing.T) {
40
41
41
42
testCtx .createUserAndRole (ctx , t , "alice" , "admin" , []string {"postgres" }, []string {"postgres" })
42
43
43
- // Point our proxy to the Teleport's db listener on the multiplexer.
44
- proxy , err := multiplexer .NewTestProxy (testCtx .mux .DB ().Addr ().String ())
45
- require .NoError (t , err )
46
- t .Cleanup (func () { proxy .Close () })
47
- go proxy .Serve ()
48
-
49
- // Connect to the proxy instead of directly to Postgres listener and make
50
- // sure the connection succeeds.
51
- psql , err := testCtx .postgresClientWithAddr (ctx , proxy .Address (), "alice" , "postgres" , "postgres" , "postgres" )
52
- require .NoError (t , err )
53
- require .NoError (t , psql .Close (ctx ))
44
+ for _ , v2 := range []bool {false , true } {
45
+ t .Run (fmt .Sprintf ("v2=%v" , v2 ), func (t * testing.T ) {
46
+ // Point our proxy to the Teleport's db listener on the multiplexer.
47
+ proxy , err := multiplexer .NewTestProxy (testCtx .mux .DB ().Addr ().String (), v2 )
48
+ require .NoError (t , err )
49
+ t .Cleanup (func () { proxy .Close () })
50
+ go proxy .Serve ()
51
+
52
+ // Connect to the proxy instead of directly to Postgres listener and make
53
+ // sure the connection succeeds.
54
+ psql , err := testCtx .postgresClientWithAddr (ctx , proxy .Address (), "alice" , "postgres" , "postgres" , "postgres" )
55
+ require .NoError (t , err )
56
+ require .NoError (t , psql .Close (ctx ))
57
+ })
58
+ }
54
59
}
55
60
56
61
// TestProxyProtocolMySQL ensures that clients can successfully connect to a
@@ -63,17 +68,21 @@ func TestProxyProtocolMySQL(t *testing.T) {
63
68
64
69
testCtx .createUserAndRole (ctx , t , "alice" , "admin" , []string {"root" }, []string {types .Wildcard })
65
70
66
- // Point our proxy to the Teleport's MySQL listener.
67
- proxy , err := multiplexer .NewTestProxy (testCtx .mysqlListener .Addr ().String ())
68
- require .NoError (t , err )
69
- t .Cleanup (func () { proxy .Close () })
70
- go proxy .Serve ()
71
-
72
- // Connect to the proxy instead of directly to MySQL listener and make
73
- // sure the connection succeeds.
74
- mysql , err := testCtx .mysqlClientWithAddr (proxy .Address (), "alice" , "mysql" , "root" )
75
- require .NoError (t , err )
76
- require .NoError (t , mysql .Close ())
71
+ for _ , v2 := range []bool {false , true } {
72
+ t .Run (fmt .Sprintf ("v2=%v" , v2 ), func (t * testing.T ) {
73
+ // Point our proxy to the Teleport's MySQL listener.
74
+ proxy , err := multiplexer .NewTestProxy (testCtx .mysqlListener .Addr ().String (), v2 )
75
+ require .NoError (t , err )
76
+ t .Cleanup (func () { proxy .Close () })
77
+ go proxy .Serve ()
78
+
79
+ // Connect to the proxy instead of directly to MySQL listener and make
80
+ // sure the connection succeeds.
81
+ mysql , err := testCtx .mysqlClientWithAddr (proxy .Address (), "alice" , "mysql" , "root" )
82
+ require .NoError (t , err )
83
+ require .NoError (t , mysql .Close ())
84
+ })
85
+ }
77
86
}
78
87
79
88
// TestProxyProtocolMongo ensures that clients can successfully connect to a
@@ -86,17 +95,21 @@ func TestProxyProtocolMongo(t *testing.T) {
86
95
87
96
testCtx .createUserAndRole (ctx , t , "alice" , "admin" , []string {"admin" }, []string {types .Wildcard })
88
97
89
- // Point our proxy to the Teleport's TLS listener.
90
- proxy , err := multiplexer .NewTestProxy (testCtx .webListener .Addr ().String ())
91
- require .NoError (t , err )
92
- t .Cleanup (func () { proxy .Close () })
93
- go proxy .Serve ()
94
-
95
- // Connect to the proxy instead of directly to Teleport listener and make
96
- // sure the connection succeeds.
97
- mongo , err := testCtx .mongoClientWithAddr (ctx , proxy .Address (), "alice" , "mongo" , "admin" )
98
- require .NoError (t , err )
99
- require .NoError (t , mongo .Disconnect (ctx ))
98
+ for _ , v2 := range []bool {false , true } {
99
+ t .Run (fmt .Sprintf ("v2=%v" , v2 ), func (t * testing.T ) {
100
+ // Point our proxy to the Teleport's TLS listener.
101
+ proxy , err := multiplexer .NewTestProxy (testCtx .webListener .Addr ().String (), v2 )
102
+ require .NoError (t , err )
103
+ t .Cleanup (func () { proxy .Close () })
104
+ go proxy .Serve ()
105
+
106
+ // Connect to the proxy instead of directly to Teleport listener and make
107
+ // sure the connection succeeds.
108
+ mongo , err := testCtx .mongoClientWithAddr (ctx , proxy .Address (), "alice" , "mongo" , "admin" )
109
+ require .NoError (t , err )
110
+ require .NoError (t , mongo .Disconnect (ctx ))
111
+ })
112
+ }
100
113
}
101
114
102
115
func TestProxyProtocolRedis (t * testing.T ) {
@@ -106,23 +119,27 @@ func TestProxyProtocolRedis(t *testing.T) {
106
119
107
120
testCtx .createUserAndRole (ctx , t , "alice" , "admin" , []string {"admin" }, []string {types .Wildcard })
108
121
109
- // Point our proxy to the Teleport's TLS listener.
110
- proxy , err := multiplexer .NewTestProxy (testCtx .webListener .Addr ().String ())
111
- require .NoError (t , err )
112
- t .Cleanup (func () { proxy .Close () })
113
- go proxy .Serve ()
114
-
115
- // Connect to the proxy instead of directly to Teleport listener and make
116
- // sure the connection succeeds.
117
- redisClient , err := testCtx .redisClientWithAddr (ctx , proxy .Address (), "alice" , "redis" , "admin" )
118
- require .NoError (t , err )
119
-
120
- // Send ECHO to Redis server and check if we get it back.
121
- resp := redisClient .Echo (ctx , "hello" )
122
- require .NoError (t , resp .Err ())
123
- require .Equal (t , "hello" , resp .Val ())
124
-
125
- require .NoError (t , redisClient .Close ())
122
+ for _ , v2 := range []bool {false , true } {
123
+ t .Run (fmt .Sprintf ("v2=%v" , v2 ), func (t * testing.T ) {
124
+ // Point our proxy to the Teleport's TLS listener.
125
+ proxy , err := multiplexer .NewTestProxy (testCtx .webListener .Addr ().String (), v2 )
126
+ require .NoError (t , err )
127
+ t .Cleanup (func () { proxy .Close () })
128
+ go proxy .Serve ()
129
+
130
+ // Connect to the proxy instead of directly to Teleport listener and make
131
+ // sure the connection succeeds.
132
+ redisClient , err := testCtx .redisClientWithAddr (ctx , proxy .Address (), "alice" , "redis" , "admin" )
133
+ require .NoError (t , err )
134
+
135
+ // Send ECHO to Redis server and check if we get it back.
136
+ resp := redisClient .Echo (ctx , "hello" )
137
+ require .NoError (t , resp .Err ())
138
+ require .Equal (t , "hello" , resp .Val ())
139
+
140
+ require .NoError (t , redisClient .Close ())
141
+ })
142
+ }
126
143
}
127
144
128
145
// TestProxyClientDisconnectDueToIdleConnection ensures that idle clients will be disconnected.
0 commit comments