11package pool_test
22
33import (
4+ "bytes"
45 "context"
56 "fmt"
67 "log"
@@ -22,6 +23,7 @@ import (
2223)
2324
2425var user = "test"
26+ var userNoExec = "test_noexec"
2527var pass = "test"
2628var spaceNo = uint32 (520 )
2729var spaceName = "testPool"
@@ -68,6 +70,18 @@ func makeInstance(server string, opts tarantool.Opts) pool.Instance {
6870 }
6971}
7072
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+
7185func makeInstances (servers []string , opts tarantool.Opts ) []pool.Instance {
7286 var instances []pool.Instance
7387 for _ , server := range servers {
@@ -130,6 +144,77 @@ func TestConnSuccessfully(t *testing.T) {
130144 require .Nil (t , err )
131145}
132146
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+
133218func TestConnect_empty (t * testing.T ) {
134219 cases := []struct {
135220 Name string
0 commit comments