@@ -206,7 +206,7 @@ public void testUserCanConfigureAJob() throws Exception {
206
206
assertEquals ("theOtherServer" , serverName );
207
207
}
208
208
209
- // CS IGNORE MagicNumber FOR NEXT 32 LINES. REASON: test data.
209
+ // CS IGNORE MagicNumber FOR NEXT 200 LINES. REASON: test data.
210
210
211
211
/**
212
212
* Tests that only an admin can read server configuration and manipulate server state.
@@ -223,11 +223,7 @@ public void testOnlyAdminCanPerformServerConfigurationActions() throws Exception
223
223
gerritServer .start ();
224
224
225
225
Setup .lockDown (j );
226
- j .getInstance ().setAuthorizationStrategy (
227
- new MockAuthorizationStrategy ().grant (Item .READ , Item .DISCOVER ).everywhere ().toAuthenticated ()
228
- .grant (Jenkins .READ , Item .DISCOVER ).everywhere ().toEveryone ()
229
- .grant (Item .CONFIGURE ).everywhere ().to ("bob" )
230
- .grant (Jenkins .ADMINISTER ).everywhere ().to ("alice" ));
226
+ grantsToAliceBobAndEveryone ();
231
227
j .jenkins .setCrumbIssuer (null ); //Not really testing csrf right now
232
228
JenkinsRule .WebClient webClient = j .createWebClient ().login ("alice" , "alice" );
233
229
HtmlPage page = webClient .goTo ("plugin/gerrit-trigger/servers/0/" );
@@ -240,6 +236,145 @@ public void testOnlyAdminCanPerformServerConfigurationActions() throws Exception
240
236
post (webClient , "plugin/gerrit-trigger/servers/0/wakeup" , null , 403 );
241
237
}
242
238
239
+ /**
240
+ * Tests that you can't do an http GET request to
241
+ * ${@link GerritServer.DescriptorImpl#doTestConnection(String, int, String, String, String, String)}.
242
+ *
243
+ * @throws Exception if so
244
+ */
245
+ @ Test @ Issue ("SECURITY-1527" )
246
+ public void testGetTestConnectionNotWorking () throws Exception {
247
+ GerritServer gerritServer = new GerritServer (PluginImpl .DEFAULT_SERVER_NAME );
248
+ SshdServerMock .configureFor (sshd , gerritServer );
249
+ PluginImpl .getInstance ().addServer (gerritServer );
250
+ gerritServer .getConfig ().setNumberOfSendingWorkerThreads (NUMBEROFSENDERTHREADS );
251
+ ((Config )gerritServer .getConfig ()).setGerritAuthKeyFile (sshKey .getPrivateKey ());
252
+ gerritServer .start ();
253
+
254
+ Setup .lockDown (j );
255
+ grantsToAliceBobAndEveryone ();
256
+ j .jenkins .setCrumbIssuer (null ); //Not really testing csrf right now
257
+ JenkinsRule .WebClient webClient = j .createWebClient (); //No login this time
258
+
259
+ webClient .assertFails ("descriptorByName/"
260
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
261
+ + "testConnection?"
262
+ + "gerritHostName=foo&"
263
+ + "gerritSshPort=29418&"
264
+ + "gerritProxy=&"
265
+ + "gerritUserName=foo"
266
+ + "gerritAuthKeyFile=/tmp/foo"
267
+ + "gerritAuthKeyFilePassword=bar"
268
+ + "&foo=" ,
269
+ 405 );
270
+
271
+ webClient .assertFails ("descriptorByName/"
272
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
273
+ + "testRestConnection?"
274
+ + "gerritHttpUserName=foo&"
275
+ + "gerritHttpPassword=bar&"
276
+ + "gerritFrontEndUrl=http://localhost:8000/?foo=" ,
277
+ 405 );
278
+
279
+ }
280
+
281
+ /**
282
+ * Tests that you can do an http POST request to
283
+ * ${@link GerritServer.DescriptorImpl#doTestConnection(String, int, String, String, String, String)}.
284
+ *
285
+ * @throws Exception if so
286
+ */
287
+ @ Test @ Issue ("SECURITY-1527" )
288
+ public void testPostTestConnectionNotWorking () throws Exception {
289
+ GerritServer gerritServer = new GerritServer (PluginImpl .DEFAULT_SERVER_NAME );
290
+ SshdServerMock .configureFor (sshd , gerritServer );
291
+ PluginImpl .getInstance ().addServer (gerritServer );
292
+ gerritServer .getConfig ().setNumberOfSendingWorkerThreads (NUMBEROFSENDERTHREADS );
293
+ ((Config )gerritServer .getConfig ()).setGerritAuthKeyFile (sshKey .getPrivateKey ());
294
+ gerritServer .start ();
295
+
296
+ Setup .lockDown (j );
297
+ grantsToAliceBobAndEveryone ();
298
+ j .jenkins .setCrumbIssuer (null ); //Not really testing csrf right now
299
+ JenkinsRule .WebClient webClient = j .createWebClient (); //No login this time
300
+
301
+ post (webClient , "descriptorByName/"
302
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
303
+ + "testConnection?"
304
+ + "gerritHostName=foo&"
305
+ + "gerritSshPort=29418&"
306
+ + "gerritProxy=&"
307
+ + "gerritUserName=foo"
308
+ + "gerritAuthKeyFile=/tmp/foo"
309
+ + "gerritAuthKeyFilePassword=bar" ,
310
+ null , 403 );
311
+
312
+ post (webClient , "descriptorByName/"
313
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
314
+ + "testRestConnection?"
315
+ + "gerritHttpUserName=foo&"
316
+ + "gerritHttpPassword=bar&"
317
+ + "gerritFrontEndUrl=http://localhost:8000/?foo=" ,
318
+ null , 403 );
319
+
320
+ }
321
+
322
+ /**
323
+ * Tests that you can do an http POST request to
324
+ * ${@link GerritServer.DescriptorImpl#doTestConnection(String, int, String, String, String, String)}.
325
+ *
326
+ * @throws Exception if so
327
+ */
328
+ @ Test @ Issue ("SECURITY-1527" )
329
+ public void testPostTestConnectionWorking () throws Exception {
330
+ GerritServer gerritServer = new GerritServer (PluginImpl .DEFAULT_SERVER_NAME );
331
+ SshdServerMock .configureFor (sshd , gerritServer );
332
+ PluginImpl .getInstance ().addServer (gerritServer );
333
+ gerritServer .getConfig ().setNumberOfSendingWorkerThreads (NUMBEROFSENDERTHREADS );
334
+ ((Config )gerritServer .getConfig ()).setGerritAuthKeyFile (sshKey .getPrivateKey ());
335
+ gerritServer .start ();
336
+
337
+ Setup .lockDown (j );
338
+ grantsToAliceBobAndEveryone ();
339
+ j .jenkins .setCrumbIssuer (null ); //Not really testing csrf right now
340
+ JenkinsRule .WebClient webClient = j .createWebClient ().login ("alice" );
341
+
342
+ post (webClient , "descriptorByName/"
343
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
344
+ + "testConnection?"
345
+ + "gerritHostName=foo&"
346
+ + "gerritSshPort=29418&"
347
+ + "gerritProxy=&"
348
+ + "gerritUserName=foo&"
349
+ + "gerritAuthKeyFile=/tmp/foo&"
350
+ + "gerritAuthKeyFilePassword=bar" ,
351
+ null , null );
352
+
353
+ post (webClient , "descriptorByName/"
354
+ + "com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer/"
355
+ + "testRestConnection?"
356
+ + "gerritHttpUserName=foo&"
357
+ + "gerritHttpPassword=bar&"
358
+ + "gerritFrontEndUrl=http://localhost:8000/" ,
359
+ null , null );
360
+
361
+ }
362
+
363
+ /**
364
+ * Grants some permissions.
365
+ *
366
+ * Read and discover to everyone and authenticated.
367
+ * Configure everywhere to bob.
368
+ * Administer everywhere to alice.
369
+ */
370
+ private void grantsToAliceBobAndEveryone () {
371
+ j .getInstance ().setAuthorizationStrategy (
372
+ new MockAuthorizationStrategy ().grant (Item .READ , Item .DISCOVER ).everywhere ().toAuthenticated ()
373
+ .grant (Jenkins .READ , Item .DISCOVER ).everywhere ().toEveryone ()
374
+ .grant (Item .CONFIGURE ).everywhere ().to ("bob" )
375
+ .grant (Jenkins .ADMINISTER ).everywhere ().to ("alice" ));
376
+ }
377
+
243
378
/**
244
379
* Performs an HTTP POST request to the relative url.
245
380
*
0 commit comments