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 userNoExecute = "testNoExecute"
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 : userNoExecute ,
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,74 @@ func TestConnSuccessfully(t *testing.T) {
130
144
require .Nil (t , err )
131
145
}
132
146
147
+ func TestConn_NoExecuteRole_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
+
175
+ func TestConn_NoExecuteRole_Unsupported (t * testing.T ) {
176
+ watchOnceUnsupported , err := test_helpers .IsTarantoolVersionLess (3 , 0 , 0 )
177
+ require .NoError (t , err )
178
+ if ! watchOnceUnsupported {
179
+ t .Skip ("Skipping test for Tarantool with watch once support" )
180
+ }
181
+
182
+ var buf bytes.Buffer
183
+ log .SetOutput (& buf )
184
+ defer log .SetOutput (os .Stderr )
185
+
186
+ healthyServ := servers [0 ]
187
+
188
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
189
+ defer cancel ()
190
+ connPool , err := pool .Connect (ctx ,
191
+ []pool.Instance {makeNoExecuteInstance (healthyServ , connOpts )})
192
+ require .Nilf (t , err , "failed to connect" )
193
+ require .NotNilf (t , connPool , "conn is nil after Connect" )
194
+
195
+ defer connPool .Close ()
196
+
197
+ require .Contains (t , buf .String (),
198
+ fmt .Sprintf ("connect to %s failed: Execute access to function " +
199
+ "'box.info' is denied for user '%s'" , servers [0 ], userNoExecute ))
200
+
201
+ args := test_helpers.CheckStatusesArgs {
202
+ ConnPool : connPool ,
203
+ Mode : pool .ANY ,
204
+ Servers : []string {healthyServ },
205
+ ExpectedPoolStatus : false ,
206
+ ExpectedStatuses : map [string ]bool {
207
+ healthyServ : false ,
208
+ },
209
+ }
210
+
211
+ err = test_helpers .CheckPoolStatuses (args )
212
+ require .Nil (t , err )
213
+ }
214
+
133
215
func TestConnect_empty (t * testing.T ) {
134
216
cases := []struct {
135
217
Name string
0 commit comments