@@ -258,48 +258,15 @@ void preHandleRejectsBlankIdentityValue() {
258258 thenRequestIsRejected ();
259259 }
260260
261- @ DisplayName ("Authentication for orders/search endpoint succeeds if caller identity is valid" )
262- @ Test
263- void ordersSearchValidIdentity () {
264- when (securityManager .checkIdentity ()).thenReturn (true );
265- givenRequest (GET , "/checkouts/search" );
266-
267- boolean actual = interceptorUnderTest .preHandle (request , response , handler );
268-
269- assertThat (actual , is (true ));
270- }
271-
272- @ DisplayName ("Authentication for orders/search endpoint false if caller identity is invalid" )
273- @ Test
274- void ordersSearchInvalidIdentity () {
275- when (securityManager .checkIdentity ()).thenReturn (false );
276- givenRequest (GET , "/checkouts/search" );
277-
278- boolean actual = interceptorUnderTest .preHandle (request , response , handler );
279-
280- assertThat (actual , is (false ));
281- }
282-
283- @ DisplayName ("Authentication for get order item endpoint succeeds if caller identity is valid" )
284- @ Test
285- void getOrderItemValidIdentity () {
286- when (securityManager .checkIdentity ()).thenReturn (true );
287- givenRequest (GET , "/orders/1234/items/5678" );
288-
289- boolean actual = interceptorUnderTest .preHandle (request , response , handler );
290-
291- assertThat (actual , is (true ));
292- }
293-
294- @ DisplayName ("Authentication for orders/search endpoint false if caller identity is invalid" )
295- @ Test
296- void getOrderItemInvalidIdentity () {
297- when (securityManager .checkIdentity ()).thenReturn (false );
298- givenRequest (GET , "/orders/1234/items/5678" );
261+ @ ParameterizedTest (name = "{index}: {0}" )
262+ @ MethodSource ("hasAdminAuthenticationFixtures" )
263+ void ordersSearchValidIdentity (String displayName , String endpoint , boolean isValid ) {
264+ when (securityManager .checkIdentity ()).thenReturn (isValid );
265+ givenRequest (GET , endpoint );
299266
300267 boolean actual = interceptorUnderTest .preHandle (request , response , handler );
301268
302- assertThat (actual , is (false ));
269+ assertThat (actual , is (isValid ));
303270 }
304271
305272 @ Test
@@ -450,4 +417,11 @@ private static Stream<Arguments> signedInGetRequestFixtures() {
450417 arguments ("preHandle accepts get order item request that has signed in user headers" , "/orders/1234/items/5678" ),
451418 arguments ("preHandle accepts get basket links request from a user with OAuth2 authentication" , "/basket/links" ));
452419 }
420+
421+ private static Stream <Arguments > hasAdminAuthenticationFixtures () {
422+ return Stream .of (arguments ("Authentication for orders/search endpoint succeeds if caller identity is valid" , "/checkouts/search" , true ),
423+ arguments ("Authentication for orders/search endpoint fails if caller identity is invalid" , "/checkouts/search" , false ),
424+ arguments ("Authentication for get order item endpoint succeeds if caller identity is valid" , "/orders/1234/items/5678" , true ),
425+ arguments ("Authentication for get order item endpoint fails if caller identity is invalid" , "/orders/1234/items/5678" , false ));
426+ }
453427}
0 commit comments