mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-31 06:38:42 +00:00 
			
		
		
		
	Minor test updates.
This commit is contained in:
		
							parent
							
								
									5f58108717
								
							
						
					
					
						commit
						20e65a93ea
					
				| @ -121,7 +121,7 @@ public class ProviderManagerTests { | |||||||
|                 return authentication; |                 return authentication; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             public boolean supports(Class<? extends Object> authentication) { |             public boolean supports(Class<?> authentication) { | ||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
| @ -152,7 +152,7 @@ public class ProviderManagerTests { | |||||||
|     public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates() throws Exception { |     public void authenticationExceptionIsIgnoredIfLaterProviderAuthenticates() throws Exception { | ||||||
|         ProviderManager mgr = new ProviderManager(); |         ProviderManager mgr = new ProviderManager(); | ||||||
|         final Authentication authReq = mock(Authentication.class); |         final Authentication authReq = mock(Authentication.class); | ||||||
|         mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("")), |         mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("", new Throwable())), | ||||||
|                 createProviderWhichReturns(authReq))); |                 createProviderWhichReturns(authReq))); | ||||||
|         assertSame(authReq, mgr.authenticate(mock(Authentication.class))); |         assertSame(authReq, mgr.authenticate(mock(Authentication.class))); | ||||||
|     } |     } | ||||||
| @ -161,12 +161,13 @@ public class ProviderManagerTests { | |||||||
|     public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() throws Exception { |     public void authenticationExceptionIsRethrownIfNoLaterProviderAuthenticates() throws Exception { | ||||||
|         ProviderManager mgr = new ProviderManager(); |         ProviderManager mgr = new ProviderManager(); | ||||||
| 
 | 
 | ||||||
|         mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("")), |         mgr.setProviders(Arrays.asList(createProviderWhichThrows(new BadCredentialsException("", "extra")), | ||||||
|                 createProviderWhichReturns(null))); |                 createProviderWhichReturns(null))); | ||||||
|         try { |         try { | ||||||
|             mgr.authenticate(mock(Authentication.class)); |             mgr.authenticate(mock(Authentication.class)); | ||||||
|             fail("Expected BadCredentialsException"); |             fail("Expected BadCredentialsException"); | ||||||
|         } catch (BadCredentialsException expected) { |         } catch (BadCredentialsException expected) { | ||||||
|  |             assertEquals("extra", expected.getExtraInformation()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -187,6 +188,21 @@ public class ProviderManagerTests { | |||||||
|         verifyZeroInteractions(otherProvider); |         verifyZeroInteractions(otherProvider); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Test | ||||||
|  |     public void extraInformationIsClearedIfFlagIsSet() throws Exception { | ||||||
|  |         ProviderManager authMgr = makeProviderManager(); | ||||||
|  |         AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException("", "extra"){}); | ||||||
|  | 
 | ||||||
|  |         authMgr.setProviders(Arrays.asList(iThrowAccountStatusException)); | ||||||
|  |         authMgr.setClearExtraInformation(true); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |             authMgr.authenticate(mock(Authentication.class)); | ||||||
|  |             fail("Expected AccountStatusException"); | ||||||
|  |         } catch (AccountStatusException expected) { | ||||||
|  |             assertNull(expected.getExtraInformation()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void parentAuthenticationIsUsedIfProvidersDontAuthenticate() throws Exception { |     public void parentAuthenticationIsUsedIfProvidersDontAuthenticate() throws Exception { | ||||||
| @ -202,7 +218,8 @@ public class ProviderManagerTests { | |||||||
|     @Test |     @Test | ||||||
|     public void parentIsNotCalledIfAccountStatusExceptionIsThrown() throws Exception { |     public void parentIsNotCalledIfAccountStatusExceptionIsThrown() throws Exception { | ||||||
|         ProviderManager mgr = new ProviderManager(); |         ProviderManager mgr = new ProviderManager(); | ||||||
|         AuthenticationProvider iThrowAccountStatusException = createProviderWhichThrows(new AccountStatusException(""){}); |         AuthenticationProvider iThrowAccountStatusException = | ||||||
|  |                 createProviderWhichThrows(new AccountStatusException("", new Throwable()){}); | ||||||
|         mgr.setProviders(Arrays.asList(iThrowAccountStatusException)); |         mgr.setProviders(Arrays.asList(iThrowAccountStatusException)); | ||||||
|         AuthenticationManager parent = mock(AuthenticationManager.class); |         AuthenticationManager parent = mock(AuthenticationManager.class); | ||||||
|         mgr.setParent(parent); |         mgr.setParent(parent); | ||||||
| @ -250,6 +267,7 @@ public class ProviderManagerTests { | |||||||
|             fail("Expected exception"); |             fail("Expected exception"); | ||||||
|         } catch (BadCredentialsException e) { |         } catch (BadCredentialsException e) { | ||||||
|             assertSame(expected, e); |             assertSame(expected, e); | ||||||
|  |             assertSame(authReq, e.getAuthentication()); | ||||||
|         } |         } | ||||||
|         verify(publisher).publishAuthenticationFailure(expected, authReq); |         verify(publisher).publishAuthenticationFailure(expected, authReq); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user