19
19
20
20
import static org .apache .impala .testutil .LdapUtil .*;
21
21
import static org .junit .Assert .assertEquals ;
22
+ import static org .junit .Assert .assertFalse ;
22
23
import static org .junit .Assert .assertTrue ;
23
24
24
25
import com .google .common .collect .Range ;
25
26
26
27
import java .io .IOException ;
27
28
import java .util .Arrays ;
29
+ import java .util .ArrayList ;
30
+ import java .util .Collections ;
28
31
import java .util .List ;
29
32
import org .apache .directory .server .annotations .CreateLdapServer ;
30
33
import org .apache .directory .server .annotations .CreateTransport ;
@@ -76,7 +79,8 @@ protected boolean pythonSupportsSSLContext() throws Exception {
76
79
// python -c "import ssl; print hasattr(ssl, 'create_default_context')"
77
80
String [] cmd = {
78
81
"python" , "-c" , "import ssl; print(hasattr(ssl, 'create_default_context'))" };
79
- return Boolean .parseBoolean (RunShellCommand .Run (cmd , true , "" , "" ).replace ("\n " , "" ));
82
+ return Boolean .parseBoolean (
83
+ RunShellCommand .Run (cmd , true , "" , "" ).stdout .replace ("\n " , "" ));
80
84
}
81
85
82
86
/**
@@ -129,33 +133,34 @@ protected String[] buildCommand(
129
133
/**
130
134
* Tests ldap authentication using impala-shell.
131
135
*/
132
- protected void testShellLdapAuthImpl () throws Exception {
136
+ protected void testShellLdapAuthImpl (String extra_cookie ) throws Exception {
133
137
String query = "select logged_in_user()" ;
134
138
// Templated shell commands to test a simple 'show tables' command.
135
139
// 1. Valid username, password and default http_cookie_names. Should succeed with
136
140
// cookies are being used.
137
141
String [] validCommand = {"impala-shell.sh" , "" , "--ldap" , "--auth_creds_ok_in_clear" ,
142
+ "--verbose" ,
138
143
String .format ("--user=%s" , TEST_USER_1 ),
139
144
String .format ("--ldap_password_cmd=printf %s" , TEST_PASSWORD_1 ),
140
145
String .format ("--query=%s" , query )};
141
146
// 2. Valid username, password and matching http_cookie_names. Should succeed with
142
147
// cookies are being used.
143
148
String [] validCommandMatchingCookieNames = {"impala-shell.sh" , "" , "--ldap" ,
144
- "--auth_creds_ok_in_clear" , "--http_cookie_names=impala.auth" ,
149
+ "--auth_creds_ok_in_clear" , "--verbose" , "-- http_cookie_names=impala.auth" ,
145
150
String .format ("--user=%s" , TEST_USER_1 ),
146
151
String .format ("--ldap_password_cmd=printf %s" , TEST_PASSWORD_1 ),
147
152
String .format ("--query=%s" , query )};
148
153
// 3. Valid username and password, but not matching http_cookie_names. Should succeed
149
154
// with cookies are not being used.
150
155
String [] validCommandMismatchingCookieNames = {"impala-shell.sh" , "" , "--ldap" ,
151
- "--auth_creds_ok_in_clear" , "--http_cookie_names=impala.conn" ,
156
+ "--auth_creds_ok_in_clear" , "--verbose" , "-- http_cookie_names=impala.conn" ,
152
157
String .format ("--user=%s" , TEST_USER_1 ),
153
158
String .format ("--ldap_password_cmd=printf %s" , TEST_PASSWORD_1 ),
154
159
String .format ("--query=%s" , query )};
155
160
// 4. Valid username and password, but empty http_cookie_names. Should succeed with
156
161
// cookies are not being used.
157
162
String [] validCommandEmptyCookieNames = {"impala-shell.sh" , "" , "--ldap" ,
158
- "--auth_creds_ok_in_clear" , "--http_cookie_names=" ,
163
+ "--auth_creds_ok_in_clear" , "--verbose" , "-- http_cookie_names=" ,
159
164
String .format ("--user=%s" , TEST_USER_1 ),
160
165
String .format ("--ldap_password_cmd=printf %s" , TEST_PASSWORD_1 ),
161
166
String .format ("--query=%s" , query )};
@@ -168,35 +173,53 @@ protected void testShellLdapAuthImpl() throws Exception {
168
173
"impala-shell.sh" , "" , String .format ("--query=%s" , query )};
169
174
String protocolTemplate = "--protocol=%s" ;
170
175
176
+ // Sorted list of cookies for validCommand, where all cookies are preserved.
177
+ List <String > preservedCookiesList = new ArrayList <>();
178
+ preservedCookiesList .add ("impala.auth" );
179
+ if (extra_cookie != null ) {
180
+ preservedCookiesList .add (extra_cookie );
181
+ }
182
+ Collections .sort (preservedCookiesList );
183
+ String preservedCookies = String .join (", " , preservedCookiesList );
184
+
171
185
for (String p : getProtocolsToTest ()) {
172
186
String protocol = String .format (protocolTemplate , p );
173
187
validCommand [1 ] = protocol ;
174
- RunShellCommand .Run (validCommand , /*shouldSucceed*/ true , TEST_USER_1 ,
188
+ RunShellCommand .Output result = RunShellCommand .Run (validCommand ,
189
+ /*shouldSucceed*/ true , TEST_USER_1 ,
175
190
"Starting Impala Shell with LDAP-based authentication" );
176
191
if (p .equals ("hs2-http" )) {
177
192
// Check that cookies are being used.
178
193
verifyMetrics (Range .atLeast (1L ), zero , Range .atLeast (1L ), zero );
194
+ assertTrue (result .stderr ,
195
+ result .stderr .contains ("Preserving cookies: " + preservedCookies ));
179
196
}
180
197
validCommandMatchingCookieNames [1 ] = protocol ;
181
- RunShellCommand .Run (validCommandMatchingCookieNames , /*shouldSucceed*/ true ,
182
- TEST_USER_1 , "Starting Impala Shell with LDAP-based authentication" );
198
+ result = RunShellCommand .Run (validCommandMatchingCookieNames ,
199
+ /*shouldSucceed*/ true , TEST_USER_1 ,
200
+ "Starting Impala Shell with LDAP-based authentication" );
183
201
if (p .equals ("hs2-http" )) {
184
202
// Check that cookies are being used.
185
203
verifyMetrics (Range .atLeast (2L ), zero , Range .atLeast (2L ), zero );
204
+ assertTrue (result .stderr ,
205
+ result .stderr .contains ("Preserving cookies: impala.auth" ));
186
206
}
187
207
validCommandMismatchingCookieNames [1 ] = protocol ;
188
- RunShellCommand .Run (validCommandMismatchingCookieNames , /*shouldSucceed*/ true ,
189
- TEST_USER_1 , "Starting Impala Shell with LDAP-based authentication" );
208
+ result = RunShellCommand .Run (validCommandMismatchingCookieNames ,
209
+ /*shouldSucceed*/ true , TEST_USER_1 ,
210
+ "Starting Impala Shell with LDAP-based authentication" );
190
211
if (p .equals ("hs2-http" )) {
191
212
// Check that cookies are NOT being used.
192
213
verifyMetrics (Range .atLeast (2L ), zero , Range .atLeast (2L ), zero );
214
+ assertFalse (result .stderr , result .stderr .contains ("Preserving cookies:" ));
193
215
}
194
216
validCommandEmptyCookieNames [1 ] = protocol ;
195
- RunShellCommand .Run (validCommandEmptyCookieNames , /*shouldSucceed*/ true ,
217
+ result = RunShellCommand .Run (validCommandEmptyCookieNames , /*shouldSucceed*/ true ,
196
218
TEST_USER_1 , "Starting Impala Shell with LDAP-based authentication" );
197
219
if (p .equals ("hs2-http" )) {
198
220
// Check that cookies are NOT being used.
199
221
verifyMetrics (Range .atLeast (2L ), zero , Range .atLeast (2L ), zero );
222
+ assertFalse (result .stderr , result .stderr .contains ("Preserving cookies:" ));
200
223
}
201
224
202
225
invalidCommand [1 ] = protocol ;
0 commit comments