1
1
package pool_test
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"fmt"
6
7
"log"
@@ -22,6 +23,7 @@ import (
22
23
)
23
24
24
25
var user = "test"
26
+ var userNoExec = "test_noexec"
25
27
var pass = "test"
26
28
var spaceNo = uint32 (520 )
27
29
var spaceName = "testPool"
@@ -68,6 +70,18 @@ func makeInstance(server string, opts tarantool.Opts) pool.Instance {
68
70
}
69
71
}
70
72
73
+ func makeNoExecuteInstance (server string , opts tarantool.Opts ) pool.Instance {
74
+ return pool.Instance {
75
+ Name : server ,
76
+ Dialer : tarantool.NetDialer {
77
+ Address : server ,
78
+ User : userNoExec ,
79
+ Password : pass ,
80
+ },
81
+ Opts : opts ,
82
+ }
83
+ }
84
+
71
85
func makeInstances (servers []string , opts tarantool.Opts ) []pool.Instance {
72
86
var instances []pool.Instance
73
87
for _ , server := range servers {
@@ -130,6 +144,77 @@ func TestConnSuccessfully(t *testing.T) {
130
144
require .Nil (t , err )
131
145
}
132
146
147
+ func TestConn_no_execute_supported (t * testing.T ) {
148
+ test_helpers .SkipIfWatchOnceUnsupported (t )
149
+
150
+ healthyServ := servers [0 ]
151
+
152
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
153
+ defer cancel ()
154
+ connPool , err := pool .Connect (ctx ,
155
+ []pool.Instance {makeNoExecuteInstance (healthyServ , connOpts )})
156
+ require .Nilf (t , err , "failed to connect" )
157
+ require .NotNilf (t , connPool , "conn is nil after Connect" )
158
+
159
+ defer connPool .Close ()
160
+
161
+ args := test_helpers.CheckStatusesArgs {
162
+ ConnPool : connPool ,
163
+ Mode : pool .ANY ,
164
+ Servers : []string {healthyServ },
165
+ ExpectedPoolStatus : true ,
166
+ ExpectedStatuses : map [string ]bool {
167
+ healthyServ : true ,
168
+ },
169
+ }
170
+
171
+ err = test_helpers .CheckPoolStatuses (args )
172
+ require .Nil (t , err )
173
+
174
+ _ , err = connPool .Do (tarantool .NewPingRequest (), pool .ANY ).Get ()
175
+ require .Nil (t , err )
176
+ }
177
+
178
+ func TestConn_no_execute_unsupported (t * testing.T ) {
179
+ test_helpers .SkipIfWatchOnceSupported (t )
180
+
181
+ var buf bytes.Buffer
182
+ log .SetOutput (& buf )
183
+ defer log .SetOutput (os .Stderr )
184
+
185
+ healthyServ := servers [0 ]
186
+
187
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
188
+ defer cancel ()
189
+ connPool , err := pool .Connect (ctx ,
190
+ []pool.Instance {makeNoExecuteInstance (healthyServ , connOpts )})
191
+ require .Nilf (t , err , "failed to connect" )
192
+ require .NotNilf (t , connPool , "conn is nil after Connect" )
193
+
194
+ defer connPool .Close ()
195
+
196
+ require .Contains (t , buf .String (),
197
+ fmt .Sprintf ("connect to %s failed: Execute access to function " +
198
+ "'box.info' is denied for user '%s'" , servers [0 ], userNoExec ))
199
+
200
+ args := test_helpers.CheckStatusesArgs {
201
+ ConnPool : connPool ,
202
+ Mode : pool .ANY ,
203
+ Servers : []string {healthyServ },
204
+ ExpectedPoolStatus : false ,
205
+ ExpectedStatuses : map [string ]bool {
206
+ healthyServ : false ,
207
+ },
208
+ }
209
+
210
+ err = test_helpers .CheckPoolStatuses (args )
211
+ require .Nil (t , err )
212
+
213
+ _ , err = connPool .Do (tarantool .NewPingRequest (), pool .ANY ).Get ()
214
+ require .Error (t , err )
215
+ require .Equal (t , "can't find healthy instance in pool" , err .Error ())
216
+ }
217
+
133
218
func TestConnect_empty (t * testing.T ) {
134
219
cases := []struct {
135
220
Name string
0 commit comments