24
24
import org .springframework .beans .factory .annotation .Value ;
25
25
import org .springframework .boot .test .context .SpringBootTest ;
26
26
import org .springframework .cloud .contract .wiremock .AutoConfigureWireMock ;
27
- import org .springframework .http .HttpStatus ;
28
27
import org .springframework .test .context .junit4 .SpringRunner ;
29
28
import org .springframework .test .web .reactive .server .WebTestClient ;
30
29
@@ -186,40 +185,45 @@ public void testGetElements() {
186
185
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user1" ))
187
186
.willReturn (aResponse ()));
188
187
189
- // user2 not allowed
188
+ // user2 allowed
190
189
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user2" ))
191
- .willReturn (aResponse (). withStatus ( HttpStatus . FORBIDDEN . value ()) ));
190
+ .willReturn (aResponse ()));
192
191
193
192
stubFor (get (urlEqualTo (String .format ("/v1/studies/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
194
193
.willReturn (aResponse ()));
195
194
195
+ stubFor (get (urlEqualTo (String .format ("/v1/studies/%s" , uuid ))).withHeader ("userId" , equalTo ("user2" ))
196
+ .willReturn (aResponse ()));
197
+
196
198
stubFor (get (urlEqualTo (String .format ("/v1/studies/metadata?ids=%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
197
199
.willReturn (aResponse ()));
198
200
201
+ stubFor (get (urlEqualTo (String .format ("/v1/studies/metadata?ids=%s" , uuid ))).withHeader ("userId" , equalTo ("user2" ))
202
+ .willReturn (aResponse ()));
203
+
199
204
stubFor (get (urlEqualTo (String .format ("/v1/filters/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
200
205
.willReturn (aResponse ()));
201
206
202
207
stubFor (get (urlEqualTo (String .format ("/v1/contingency-lists/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
203
208
.willReturn (aResponse ()));
204
209
205
- // No uuid element forbidden
206
210
webClient
207
211
.get ().uri ("study/v1/studies" )
208
212
.header ("Authorization" , "Bearer " + tokenUser1 )
209
213
.exchange ()
210
- .expectStatus ().isForbidden ();
214
+ .expectStatus ().isNotFound ();
211
215
212
- // Bad uuid forbidden
216
+ // Bad uuid
213
217
webClient
214
218
.get ().uri (String .format ("study/v1/studies/%s" , "badUuid" ))
215
219
.header ("Authorization" , "Bearer " + tokenUser1 )
216
220
.exchange ()
217
- .expectStatus ().isForbidden ();
221
+ .expectStatus ().isNotFound ();
218
222
webClient
219
223
.get ().uri (String .format ("study/v1/studies/%s" , (UUID ) null ))
220
224
.header ("Authorization" , "Bearer " + tokenUser1 )
221
225
.exchange ()
222
- .expectStatus ().isForbidden ();
226
+ .expectStatus ().isNotFound ();
223
227
224
228
webClient
225
229
.get ().uri (String .format ("study/v1/studies/%s" , uuid ))
@@ -249,25 +253,25 @@ public void testGetElements() {
249
253
.get ().uri (String .format ("study/v1/studies/%s" , uuid ))
250
254
.header ("Authorization" , "Bearer " + tokenUser2 )
251
255
.exchange ()
252
- .expectStatus ().isForbidden ();
256
+ .expectStatus ().isOk ();
253
257
254
258
webClient
255
259
.get ().uri (String .format ("study/v1/studies/metadata?ids=%s" , uuid ))
256
260
.header ("Authorization" , "Bearer " + tokenUser2 )
257
261
.exchange ()
258
- .expectStatus ().isForbidden ();
262
+ .expectStatus ().isOk ();
259
263
260
264
webClient
261
265
.get ().uri (String .format ("actions/v1/contingency-lists/%s" , uuid ))
262
266
.header ("Authorization" , "Bearer " + tokenUser2 )
263
267
.exchange ()
264
- .expectStatus ().isForbidden ();
268
+ .expectStatus ().isNotFound ();
265
269
266
270
webClient
267
271
.get ().uri (String .format ("filter/v1/filters/%s" , uuid ))
268
272
.header ("Authorization" , "Bearer " + tokenUser2 )
269
273
.exchange ()
270
- .expectStatus ().isForbidden ();
274
+ .expectStatus ().isNotFound ();
271
275
}
272
276
273
277
@ Test
@@ -282,11 +286,11 @@ public void testCreateElements() {
282
286
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user1" ))
283
287
.willReturn (aResponse ()));
284
288
285
- // user2 not allowed
289
+ // user2 is also allowed
286
290
stubFor (head (urlEqualTo (String .format ("/v1/directories?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user2" ))
287
- .willReturn (aResponse (). withStatus ( HttpStatus . FORBIDDEN . value ()) ));
291
+ .willReturn (aResponse ()));
288
292
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user2" ))
289
- .willReturn (aResponse (). withStatus ( HttpStatus . FORBIDDEN . value ()) ));
293
+ .willReturn (aResponse ()));
290
294
291
295
stubFor (post (urlEqualTo (String .format ("/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , uuid ))).withHeader ("userId" , equalTo ("user1" ))
292
296
.willReturn (aResponse ()));
@@ -297,55 +301,55 @@ public void testCreateElements() {
297
301
stubFor (post (urlEqualTo (String .format ("/v1/explore/filters?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , uuid ))).withHeader ("userId" , equalTo ("user1" ))
298
302
.willReturn (aResponse ()));
299
303
300
- // Direct creation of elements without going through the explor server is forbidden
304
+ // Direct creation of elements without going through the explore server
301
305
webClient
302
306
.post ().uri ("study/v1/studies" )
303
307
.header ("Authorization" , "Bearer " + tokenUser1 )
304
308
.exchange ()
305
- .expectStatus ().isForbidden ();
309
+ .expectStatus ().isNotFound ();
306
310
webClient
307
311
.post ().uri ("actions/v1/script-contingency-lists" )
308
312
.header ("Authorization" , "Bearer " + tokenUser1 )
309
313
.exchange ()
310
- .expectStatus ().isForbidden ();
314
+ .expectStatus ().isNotFound ();
311
315
webClient
312
316
.post ().uri ("filter/v1/filters" )
313
317
.header ("Authorization" , "Bearer " + tokenUser1 )
314
318
.exchange ()
315
- .expectStatus ().isForbidden ();
319
+ .expectStatus ().isNotFound ();
316
320
317
- // Creation of elements without directory parent is forbidden
321
+ // Creation of elements without directory parent
318
322
webClient
319
323
.post ().uri (String .format ("explore/v1/explore/studies" ))
320
324
.header ("Authorization" , "Bearer " + tokenUser1 )
321
325
.exchange ()
322
- .expectStatus ().isForbidden ();
326
+ .expectStatus ().isNotFound ();
323
327
324
- // Creation of elements with bad parameter for directory parent uuid is forbidden
328
+ // Creation of elements with bad parameter for directory parent uuid
325
329
webClient
326
330
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID + "bad" , uuid ))
327
331
.header ("Authorization" , "Bearer " + tokenUser1 )
328
332
.exchange ()
329
- .expectStatus ().isForbidden ();
333
+ .expectStatus ().isNotFound ();
330
334
331
- // Creation of elements with bad directory parent uuid is forbidden
335
+ // Creation of elements with bad directory parent uuid
332
336
webClient
333
337
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , "badUuid" ))
334
338
.header ("Authorization" , "Bearer " + tokenUser1 )
335
339
.exchange ()
336
- .expectStatus ().isForbidden ();
340
+ .expectStatus ().isNotFound ();
337
341
webClient
338
342
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , null ))
339
343
.header ("Authorization" , "Bearer " + tokenUser1 )
340
344
.exchange ()
341
- .expectStatus ().isForbidden ();
345
+ .expectStatus ().isNotFound ();
342
346
343
- // Creation of elements with multiple directory parent uuids is forbidden
347
+ // Creation of elements with multiple directory parent uuids
344
348
webClient
345
349
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s,%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , uuid , uuid ))
346
350
.header ("Authorization" , "Bearer " + tokenUser1 )
347
351
.exchange ()
348
- .expectStatus ().isForbidden ();
352
+ .expectStatus ().isNotFound ();
349
353
350
354
webClient
351
355
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_PARENT_DIRECTORY_ID , uuid ))
@@ -384,7 +388,7 @@ public void testCreateSubElements() {
384
388
.post ().uri ("study/v1/studies" )
385
389
.header ("Authorization" , "Bearer " + tokenUser1 )
386
390
.exchange ()
387
- .expectStatus ().isForbidden ();
391
+ .expectStatus ().isNotFound ();
388
392
389
393
webClient
390
394
.post ().uri (String .format ("study/v1/studies/%s/tree/nodes" , uuid ))
@@ -403,9 +407,9 @@ public void testUpdateElements() {
403
407
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user1" ))
404
408
.willReturn (aResponse ()));
405
409
406
- // user2 not allowed
410
+ // user2 allowed
407
411
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user2" ))
408
- .willReturn (aResponse (). withStatus ( HttpStatus . FORBIDDEN . value ()) ));
412
+ .willReturn (aResponse ()));
409
413
410
414
stubFor (put (urlEqualTo (String .format ("/v1/studies/%s/nodes/idNode" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
411
415
.willReturn (aResponse ()));
@@ -416,22 +420,22 @@ public void testUpdateElements() {
416
420
stubFor (put (urlEqualTo (String .format ("/v1/filters/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
417
421
.willReturn (aResponse ()));
418
422
419
- // Put with no or bad uuid is forbidden
423
+ // Put with no or bad uuid
420
424
webClient
421
425
.put ().uri ("study/v1/studies/nodes/idNode" )
422
426
.header ("Authorization" , "Bearer " + tokenUser1 )
423
427
.exchange ()
424
- .expectStatus ().isForbidden ();
428
+ .expectStatus ().isNotFound ();
425
429
webClient
426
430
.put ().uri (String .format ("study/v1/studies/%s/nodes/idNode" , (UUID ) null ))
427
431
.header ("Authorization" , "Bearer " + tokenUser1 )
428
432
.exchange ()
429
- .expectStatus ().isForbidden ();
433
+ .expectStatus ().isNotFound ();
430
434
webClient
431
435
.put ().uri (String .format ("study/v1/studies/%s/nodes/idNode" , "badUuid" ))
432
436
.header ("Authorization" , "Bearer " + tokenUser1 )
433
437
.exchange ()
434
- .expectStatus ().isForbidden ();
438
+ .expectStatus ().isNotFound ();
435
439
436
440
webClient
437
441
.put ().uri (String .format ("study/v1/studies/%s/nodes/idNode" , uuid ))
@@ -462,9 +466,9 @@ public void testDeleteElements() {
462
466
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user1" ))
463
467
.willReturn (aResponse ()));
464
468
465
- // user2 not allowed
469
+ // user2 allowed
466
470
stubFor (head (urlEqualTo (String .format ("/v1/elements?ids=%s" , uuid ))).withPort (port ).withHeader ("userId" , equalTo ("user2" ))
467
- .willReturn (aResponse (). withStatus ( HttpStatus . FORBIDDEN . value ()) ));
471
+ .willReturn (aResponse ()));
468
472
469
473
stubFor (delete (urlEqualTo (String .format ("/v1/explore/elements/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
470
474
.willReturn (aResponse ()));
@@ -478,28 +482,28 @@ public void testDeleteElements() {
478
482
stubFor (delete (urlEqualTo (String .format ("/v1/filters/%s" , uuid ))).withHeader ("userId" , equalTo ("user1" ))
479
483
.willReturn (aResponse ()));
480
484
481
- // Delete elements with no or bad uuid is forbidden
485
+ // Delete elements with no or bad uuid
482
486
webClient
483
487
.delete ().uri ("explore/v1/explore/elements" )
484
488
.header ("Authorization" , "Bearer " + tokenUser1 )
485
489
.exchange ()
486
- .expectStatus ().isForbidden ();
490
+ .expectStatus ().isNotFound ();
487
491
webClient
488
492
.delete ().uri (String .format ("explore/v1/explore/elements/%s" , (UUID ) null ))
489
493
.header ("Authorization" , "Bearer " + tokenUser1 )
490
494
.exchange ()
491
- .expectStatus ().isForbidden ();
495
+ .expectStatus ().isNotFound ();
492
496
webClient
493
497
.delete ().uri (String .format ("explore/v1/explore/elements/%s" , "badUuid" ))
494
498
.header ("Authorization" , "Bearer " + tokenUser1 )
495
499
.exchange ()
496
- .expectStatus ().isForbidden ();
500
+ .expectStatus ().isNotFound ();
497
501
498
502
webClient
499
503
.delete ().uri (String .format ("explore/v1/explore/elements/%s" , uuid ))
500
504
.header ("Authorization" , "Bearer " + tokenUser2 )
501
505
.exchange ()
502
- .expectStatus ().isForbidden ();
506
+ .expectStatus ().isNotFound ();
503
507
504
508
webClient
505
509
.delete ().uri (String .format ("explore/v1/explore/elements/%s" , uuid ))
@@ -572,7 +576,7 @@ public void testDuplicateElements() {
572
576
.post ().uri ("study/v1/studies" )
573
577
.header ("Authorization" , "Bearer " + tokenUser1 )
574
578
.exchange ()
575
- .expectStatus ().isForbidden ();
579
+ .expectStatus ().isNotFound ();
576
580
577
581
webClient
578
582
.post ().uri (String .format ("explore/v1/explore/studies?%s=%s" , ExploreServer .QUERY_PARAM_DUPLICATE_FROM_ID , uuid ))
0 commit comments