Update to Mockito 2.10.0
Issue: gh-4608
This commit is contained in:
+2
-2
@@ -40,9 +40,9 @@ public class AclEntryAfterInvocationCollectionFilteringProviderTests {
|
|||||||
public void objectsAreRemovedIfPermissionDenied() throws Exception {
|
public void objectsAreRemovedIfPermissionDenied() throws Exception {
|
||||||
AclService service = mock(AclService.class);
|
AclService service = mock(AclService.class);
|
||||||
Acl acl = mock(Acl.class);
|
Acl acl = mock(Acl.class);
|
||||||
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenReturn(
|
when(acl.isGranted(any(), any(), anyBoolean())).thenReturn(
|
||||||
false);
|
false);
|
||||||
when(service.readAclById(any(ObjectIdentity.class), any(List.class))).thenReturn(
|
when(service.readAclById(any(), any())).thenReturn(
|
||||||
acl);
|
acl);
|
||||||
AclEntryAfterInvocationCollectionFilteringProvider provider = new AclEntryAfterInvocationCollectionFilteringProvider(
|
AclEntryAfterInvocationCollectionFilteringProvider provider = new AclEntryAfterInvocationCollectionFilteringProvider(
|
||||||
service, Arrays.asList(mock(Permission.class)));
|
service, Arrays.asList(mock(Permission.class)));
|
||||||
|
|||||||
+3
-3
@@ -54,7 +54,7 @@ public class AclEntryAfterInvocationProviderTests {
|
|||||||
Acl acl = mock(Acl.class);
|
Acl acl = mock(Acl.class);
|
||||||
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenReturn(
|
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenReturn(
|
||||||
true);
|
true);
|
||||||
when(service.readAclById(any(ObjectIdentity.class), any(List.class))).thenReturn(
|
when(service.readAclById(any(), any())).thenReturn(
|
||||||
acl);
|
acl);
|
||||||
AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(
|
AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(
|
||||||
service, Arrays.asList(mock(Permission.class)));
|
service, Arrays.asList(mock(Permission.class)));
|
||||||
@@ -106,9 +106,9 @@ public class AclEntryAfterInvocationProviderTests {
|
|||||||
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenReturn(
|
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenReturn(
|
||||||
false);
|
false);
|
||||||
// Try a second time with no permissions found
|
// Try a second time with no permissions found
|
||||||
when(acl.isGranted(any(List.class), any(List.class), anyBoolean())).thenThrow(
|
when(acl.isGranted(any(), any(List.class), anyBoolean())).thenThrow(
|
||||||
new NotFoundException(""));
|
new NotFoundException(""));
|
||||||
when(service.readAclById(any(ObjectIdentity.class), any(List.class))).thenReturn(
|
when(service.readAclById(any(), any())).thenReturn(
|
||||||
acl);
|
acl);
|
||||||
AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(
|
AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(
|
||||||
service, Arrays.asList(mock(Permission.class)));
|
service, Arrays.asList(mock(Permission.class)));
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'io.spring.gradle:spring-build-conventions:0.0.4.RELEASE'
|
classpath 'io.spring.gradle:spring-build-conventions:0.0.5.BUILD-SNAPSHOT'
|
||||||
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
|
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ dependencies {
|
|||||||
testCompile project(path : ':spring-security-core', configuration : 'tests')
|
testCompile project(path : ':spring-security-core', configuration : 'tests')
|
||||||
testCompile project(path : ':spring-security-webflux', configuration : 'tests')
|
testCompile project(path : ':spring-security-webflux', configuration : 'tests')
|
||||||
testCompile apachedsDependencies
|
testCompile apachedsDependencies
|
||||||
testCompile powerMockDependencies
|
testCompile powerMock2Dependencies
|
||||||
testCompile spockDependencies
|
testCompile spockDependencies
|
||||||
testCompile 'ch.qos.logback:logback-classic'
|
testCompile 'ch.qos.logback:logback-classic'
|
||||||
testCompile 'javax.annotation:jsr250-api:1.0'
|
testCompile 'javax.annotation:jsr250-api:1.0'
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ public class SecurityNamespaceHandlerTests {
|
|||||||
|
|
||||||
handler.init();
|
handler.init();
|
||||||
|
|
||||||
verifyStatic();
|
verifyStatic(ClassUtils.class);
|
||||||
ClassUtils.forName(eq(FILTER_CHAIN_PROXY_CLASSNAME), any(ClassLoader.class));
|
ClassUtils.forName(eq(FILTER_CHAIN_PROXY_CLASSNAME), any(ClassLoader.class));
|
||||||
verifyZeroInteractions(logger);
|
verifyZeroInteractions(logger);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -104,7 +104,7 @@ public class SessionManagementConfigurerServlet31Tests {
|
|||||||
|
|
||||||
springSecurityFilterChain.doFilter(request, response, chain);
|
springSecurityFilterChain.doFilter(request, response, chain);
|
||||||
|
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -104,7 +104,7 @@ public class SessionManagementConfigServlet31Tests {
|
|||||||
|
|
||||||
springSecurityFilterChain.doFilter(request, response, chain);
|
springSecurityFilterChain.doFilter(request, response, chain);
|
||||||
|
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ public class SessionManagementConfigServlet31Tests {
|
|||||||
|
|
||||||
springSecurityFilterChain.doFilter(request, response, chain);
|
springSecurityFilterChain.doFilter(request, response, chain);
|
||||||
|
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ dependencies {
|
|||||||
optional 'org.springframework:spring-jdbc'
|
optional 'org.springframework:spring-jdbc'
|
||||||
optional 'org.springframework:spring-tx'
|
optional 'org.springframework:spring-tx'
|
||||||
|
|
||||||
testCompile powerMockDependencies
|
testCompile powerMock2Dependencies
|
||||||
testCompile 'commons-collections:commons-collections'
|
testCompile 'commons-collections:commons-collections'
|
||||||
testCompile 'io.projectreactor:reactor-test'
|
testCompile 'io.projectreactor:reactor-test'
|
||||||
testCompile 'org.skyscreamer:jsonassert'
|
testCompile 'org.skyscreamer:jsonassert'
|
||||||
|
|||||||
+2
-2
@@ -89,7 +89,7 @@ public class AspectJMethodSecurityInterceptorTests {
|
|||||||
when(codeSig.getDeclaringType()).thenReturn(TargetObject.class);
|
when(codeSig.getDeclaringType()).thenReturn(TargetObject.class);
|
||||||
when(codeSig.getParameterTypes()).thenReturn(new Class[] { String.class });
|
when(codeSig.getParameterTypes()).thenReturn(new Class[] { String.class });
|
||||||
when(staticPart.getSignature()).thenReturn(codeSig);
|
when(staticPart.getSignature()).thenReturn(codeSig);
|
||||||
when(mds.getAttributes(any(JoinPoint.class))).thenReturn(
|
when(mds.getAttributes(any())).thenReturn(
|
||||||
SecurityConfig.createList("ROLE_USER"));
|
SecurityConfig.createList("ROLE_USER"));
|
||||||
when(authman.authenticate(token)).thenReturn(token);
|
when(authman.authenticate(token)).thenReturn(token);
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ public class AspectJMethodSecurityInterceptorTests {
|
|||||||
@Test
|
@Test
|
||||||
public void callbackIsNotInvokedWhenPermissionDenied() throws Exception {
|
public void callbackIsNotInvokedWhenPermissionDenied() throws Exception {
|
||||||
doThrow(new AccessDeniedException("denied")).when(adm).decide(
|
doThrow(new AccessDeniedException("denied")).when(adm).decide(
|
||||||
any(Authentication.class), any(), any(Collection.class));
|
any(), any(), any());
|
||||||
|
|
||||||
SecurityContextHolder.getContext().setAuthentication(token);
|
SecurityContextHolder.getContext().setAuthentication(token);
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-2
@@ -20,7 +20,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
@@ -76,7 +76,6 @@ public class ReactiveAuthenticationManagerAdapterTests {
|
|||||||
@Test
|
@Test
|
||||||
public void authenticateWhenBadCredentialsThenError() {
|
public void authenticateWhenBadCredentialsThenError() {
|
||||||
when(delegate.authenticate(any())).thenThrow(new BadCredentialsException("Failed"));
|
when(delegate.authenticate(any())).thenThrow(new BadCredentialsException("Failed"));
|
||||||
when(authentication.isAuthenticated()).thenReturn(true);
|
|
||||||
|
|
||||||
Mono<Authentication> result = manager.authenticate(authentication);
|
Mono<Authentication> result = manager.authenticate(authentication);
|
||||||
|
|
||||||
|
|||||||
+5
-13
@@ -40,6 +40,7 @@ import org.hamcrest.BaseMatcher;
|
|||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
@@ -262,19 +263,10 @@ public class DefaultJaasAuthenticationProviderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void verifyFailedLogin() {
|
private void verifyFailedLogin() {
|
||||||
verify(publisher).publishEvent(
|
ArgumentCaptor<JaasAuthenticationFailedEvent> event = ArgumentCaptor.forClass(JaasAuthenticationFailedEvent.class);
|
||||||
argThat(new BaseMatcher<JaasAuthenticationFailedEvent>() {
|
verify(publisher).publishEvent(event.capture());
|
||||||
public void describeTo(Description desc) {
|
assertThat(event.getValue()).isInstanceOf(JaasAuthenticationFailedEvent.class);
|
||||||
desc.appendText("isA(org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent)");
|
assertThat(event.getValue().getException()).isNotNull();
|
||||||
desc.appendText(" && event.getException() != null");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Object arg) {
|
|
||||||
JaasAuthenticationFailedEvent e = (JaasAuthenticationFailedEvent) arg;
|
|
||||||
return e.getException() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
|
||||||
verifyNoMoreInteractions(publisher);
|
verifyNoMoreInteractions(publisher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -19,7 +19,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.event.SmartApplicationListener;
|
import org.springframework.context.event.SmartApplicationListener;
|
||||||
|
|
||||||
@@ -63,7 +63,6 @@ public class DelegatingApplicationListenerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void processEventEventTypeNotSupported() {
|
public void processEventEventTypeNotSupported() {
|
||||||
when(delegate.supportsSourceType(event.getSource().getClass())).thenReturn(true);
|
|
||||||
listener.onApplicationEvent(event);
|
listener.onApplicationEvent(event);
|
||||||
|
|
||||||
verify(delegate, never()).onApplicationEvent(any(ApplicationEvent.class));
|
verify(delegate, never()).onApplicationEvent(any(ApplicationEvent.class));
|
||||||
|
|||||||
+13
-12
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
import static org.powermock.api.mockito.PowerMockito.doReturn;
|
||||||
import static org.powermock.api.mockito.PowerMockito.spy;
|
import static org.powermock.api.mockito.PowerMockito.spy;
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
@@ -85,8 +86,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
String version = "1";
|
String version = "1";
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn(version);
|
doReturn(version).when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn(version);
|
doReturn(version).when(SpringVersion.class,"getVersion");
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
|
|
||||||
@@ -97,8 +98,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
public void noLoggingIfSpringVersionNull() throws Exception {
|
public void noLoggingIfSpringVersionNull() throws Exception {
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn("1");
|
doReturn("1").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn(null);
|
doReturn(null).when(SpringVersion.class,"getVersion");
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
|
|
||||||
@@ -109,8 +110,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
public void warnIfSpringVersionTooSmall() throws Exception {
|
public void warnIfSpringVersionTooSmall() throws Exception {
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn("3");
|
doReturn("3").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn("2");
|
doReturn("2").when(SpringVersion.class,"getVersion");
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
|
|
||||||
@@ -121,8 +122,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
public void noWarnIfSpringVersionLarger() throws Exception {
|
public void noWarnIfSpringVersionLarger() throws Exception {
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn("4.0.0.RELEASE");
|
doReturn("4.0.0.RELEASE").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn("4.0.0.RELEASE");
|
doReturn("4.0.0.RELEASE").when(SpringVersion.class,"getVersion");
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
|
|
||||||
@@ -135,8 +136,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
String minSpringVersion = "3.2.8.RELEASE";
|
String minSpringVersion = "3.2.8.RELEASE";
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn("3.2.0.RELEASE");
|
doReturn("3.2.0.RELEASE").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn("3.2.10.RELEASE");
|
doReturn("3.2.10.RELEASE").when(SpringVersion.class,"getVersion");
|
||||||
|
|
||||||
performChecks(minSpringVersion);
|
performChecks(minSpringVersion);
|
||||||
|
|
||||||
@@ -147,8 +148,8 @@ public class SpringSecurityCoreVersionTests {
|
|||||||
public void noLoggingIfPropertySet() throws Exception {
|
public void noLoggingIfPropertySet() throws Exception {
|
||||||
spy(SpringSecurityCoreVersion.class);
|
spy(SpringSecurityCoreVersion.class);
|
||||||
spy(SpringVersion.class);
|
spy(SpringVersion.class);
|
||||||
when(SpringSecurityCoreVersion.getVersion()).thenReturn("3");
|
doReturn("3").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||||
when(SpringVersion.getVersion()).thenReturn("2");
|
doReturn("2").when(SpringVersion.class,"getVersion");
|
||||||
System.setProperty(getDisableChecksProperty(), Boolean.TRUE.toString());
|
System.setProperty(getDisableChecksProperty(), Boolean.TRUE.toString());
|
||||||
|
|
||||||
performChecks();
|
performChecks();
|
||||||
|
|||||||
+2
-2
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
* Tests {@link JdbcDaoImpl}.
|
* Tests {@link JdbcDaoImpl}.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
*/
|
*/
|
||||||
public class JdbcDaoImplTests {
|
public class JdbcDaoImplTests {
|
||||||
|
|
||||||
@@ -212,6 +212,6 @@ public class JdbcDaoImplTests {
|
|||||||
|
|
||||||
dao.getMessages().getMessage(code);
|
dao.getMessages().getMessage(code);
|
||||||
|
|
||||||
verify(source).getMessage(eq(code), any(Object[].class), any(Locale.class));
|
verify(source).getMessage(eq(code), any(), any());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ dependencyManagement {
|
|||||||
dependency 'opensymphony:sitemesh:2.4.2'
|
dependency 'opensymphony:sitemesh:2.4.2'
|
||||||
dependency 'org.gebish:geb-spock:0.10.0'
|
dependency 'org.gebish:geb-spock:0.10.0'
|
||||||
dependency 'org.jasig.cas:cas-server-webapp:4.0.0'
|
dependency 'org.jasig.cas:cas-server-webapp:4.0.0'
|
||||||
dependency 'org.mockito:mockito-core:1.10.19'
|
dependency 'org.mockito:mockito-core:2.10.0'
|
||||||
dependency 'org.powermock:powermock-api-mockito:1.6.2'
|
dependency 'org.powermock:powermock-api-mockito2:2.0.0-beta.5'
|
||||||
dependency 'org.powermock:powermock-api-support:1.6.2'
|
dependency 'org.powermock:powermock-api-support:2.0.0-beta.5'
|
||||||
dependency 'org.powermock:powermock-core:1.6.2'
|
dependency 'org.powermock:powermock-core:2.0.0-beta.5'
|
||||||
dependency 'org.powermock:powermock-module-junit4-common:1.6.2'
|
dependency 'org.powermock:powermock-module-junit4-common:2.0.0-beta.5'
|
||||||
dependency 'org.powermock:powermock-module-junit4:1.6.2'
|
dependency 'org.powermock:powermock-module-junit4:2.0.0-beta.5'
|
||||||
dependency 'org.powermock:powermock-reflect:1.6.2'
|
dependency 'org.powermock:powermock-reflect:2.0.0-beta.5'
|
||||||
dependency 'org.python:jython:2.5.0'
|
dependency 'org.python:jython:2.5.0'
|
||||||
dependency 'org.seleniumhq.selenium:selenium-java:3.4.0'
|
dependency 'org.seleniumhq.selenium:selenium-java:3.4.0'
|
||||||
dependency 'org.spockframework:spock-core:1.0-groovy-2.4'
|
dependency 'org.spockframework:spock-core:1.0-groovy-2.4'
|
||||||
|
|||||||
-1
@@ -58,7 +58,6 @@ public class SpringSecurityLdapTemplateTests {
|
|||||||
searchControls.capture())).thenReturn(resultsEnum);
|
searchControls.capture())).thenReturn(resultsEnum);
|
||||||
when(resultsEnum.hasMore()).thenReturn(true, false);
|
when(resultsEnum.hasMore()).thenReturn(true, false);
|
||||||
when(resultsEnum.next()).thenReturn(searchResult);
|
when(resultsEnum.next()).thenReturn(searchResult);
|
||||||
when(searchResult.getName()).thenReturn(searchResultName);
|
|
||||||
when(searchResult.getObject()).thenReturn(searchResultObject);
|
when(searchResult.getObject()).thenReturn(searchResultObject);
|
||||||
|
|
||||||
SpringSecurityLdapTemplate.searchForSingleEntryInternal(ctx,
|
SpringSecurityLdapTemplate.searchForSingleEntryInternal(ctx,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ dependencies {
|
|||||||
|
|
||||||
testCompile project(path: ':spring-security-core', configuration: 'tests')
|
testCompile project(path: ':spring-security-core', configuration: 'tests')
|
||||||
testCompile 'commons-codec:commons-codec'
|
testCompile 'commons-codec:commons-codec'
|
||||||
testCompile powerMockDependencies
|
testCompile powerMock2Dependencies
|
||||||
testCompile slf4jDependencies
|
testCompile slf4jDependencies
|
||||||
testCompile spockDependencies
|
testCompile spockDependencies
|
||||||
|
|
||||||
|
|||||||
-1
@@ -100,7 +100,6 @@ public class AndMessageMatcherTest {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiBothFalse() {
|
public void matchesMultiBothFalse() {
|
||||||
when(delegate.matches(message)).thenReturn(false);
|
when(delegate.matches(message)).thenReturn(false);
|
||||||
when(delegate2.matches(message)).thenReturn(false);
|
|
||||||
matcher = new AndMessageMatcher<Object>(delegate, delegate2);
|
matcher = new AndMessageMatcher<Object>(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(message)).isFalse();
|
assertThat(matcher.matches(message)).isFalse();
|
||||||
|
|||||||
-2
@@ -83,7 +83,6 @@ public class OrMessageMatcherTest {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiTrue() {
|
public void matchesMultiTrue() {
|
||||||
when(delegate.matches(message)).thenReturn(true);
|
when(delegate.matches(message)).thenReturn(true);
|
||||||
when(delegate2.matches(message)).thenReturn(true);
|
|
||||||
matcher = new OrMessageMatcher<Object>(delegate, delegate2);
|
matcher = new OrMessageMatcher<Object>(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(message)).isTrue();
|
assertThat(matcher.matches(message)).isTrue();
|
||||||
@@ -109,7 +108,6 @@ public class OrMessageMatcherTest {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiSingleFalse() {
|
public void matchesMultiSingleFalse() {
|
||||||
when(delegate.matches(message)).thenReturn(true);
|
when(delegate.matches(message)).thenReturn(true);
|
||||||
when(delegate2.matches(message)).thenReturn(false);
|
|
||||||
matcher = new OrMessageMatcher<Object>(delegate, delegate2);
|
matcher = new OrMessageMatcher<Object>(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(message)).isTrue();
|
assertThat(matcher.matches(message)).isTrue();
|
||||||
|
|||||||
+9
-9
@@ -16,11 +16,12 @@
|
|||||||
package org.springframework.security.openid;
|
package org.springframework.security.openid;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Matchers.*;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.openid4java.association.AssociationException;
|
import org.openid4java.association.AssociationException;
|
||||||
import org.openid4java.consumer.ConsumerException;
|
import org.openid4java.consumer.ConsumerException;
|
||||||
import org.openid4java.consumer.ConsumerManager;
|
import org.openid4java.consumer.ConsumerManager;
|
||||||
@@ -52,9 +53,9 @@ public class OpenID4JavaConsumerTests {
|
|||||||
AuthRequest authReq = mock(AuthRequest.class);
|
AuthRequest authReq = mock(AuthRequest.class);
|
||||||
DiscoveryInformation di = mock(DiscoveryInformation.class);
|
DiscoveryInformation di = mock(DiscoveryInformation.class);
|
||||||
|
|
||||||
when(mgr.authenticate(any(DiscoveryInformation.class), anyString(), anyString()))
|
when(mgr.authenticate(any(DiscoveryInformation.class), any(), any()))
|
||||||
.thenReturn(authReq);
|
.thenReturn(authReq);
|
||||||
when(mgr.associate(anyList())).thenReturn(di);
|
when(mgr.associate(any())).thenReturn(di);
|
||||||
|
|
||||||
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
||||||
new MockAttributesFactory());
|
new MockAttributesFactory());
|
||||||
@@ -79,7 +80,7 @@ public class OpenID4JavaConsumerTests {
|
|||||||
ConsumerManager mgr = mock(ConsumerManager.class);
|
ConsumerManager mgr = mock(ConsumerManager.class);
|
||||||
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
||||||
new NullAxFetchListFactory());
|
new NullAxFetchListFactory());
|
||||||
when(mgr.discover(anyString())).thenThrow(new DiscoveryException("msg"));
|
when(mgr.discover(any())).thenThrow(new DiscoveryException("msg"));
|
||||||
consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
|
consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +91,8 @@ public class OpenID4JavaConsumerTests {
|
|||||||
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr,
|
||||||
new NullAxFetchListFactory());
|
new NullAxFetchListFactory());
|
||||||
|
|
||||||
when(mgr.authenticate(any(DiscoveryInformation.class), anyString(), anyString()))
|
when(mgr.authenticate(ArgumentMatchers.<DiscoveryInformation>any(), any(), any()))
|
||||||
.thenThrow(new MessageException("msg"), new ConsumerException("msg"));
|
.thenThrow(new MessageException("msg"), new ConsumerException("msg"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
|
consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
|
||||||
fail("OpenIDConsumerException was not thrown");
|
fail("OpenIDConsumerException was not thrown");
|
||||||
@@ -117,7 +117,7 @@ public class OpenID4JavaConsumerTests {
|
|||||||
DiscoveryInformation di = mock(DiscoveryInformation.class);
|
DiscoveryInformation di = mock(DiscoveryInformation.class);
|
||||||
|
|
||||||
when(
|
when(
|
||||||
mgr.verify(anyString(), any(ParameterList.class),
|
mgr.verify(any(), any(ParameterList.class),
|
||||||
any(DiscoveryInformation.class))).thenReturn(vr);
|
any(DiscoveryInformation.class))).thenReturn(vr);
|
||||||
|
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
@@ -136,7 +136,7 @@ public class OpenID4JavaConsumerTests {
|
|||||||
new NullAxFetchListFactory());
|
new NullAxFetchListFactory());
|
||||||
|
|
||||||
when(
|
when(
|
||||||
mgr.verify(anyString(), any(ParameterList.class),
|
mgr.verify(any(), any(ParameterList.class),
|
||||||
any(DiscoveryInformation.class)))
|
any(DiscoveryInformation.class)))
|
||||||
.thenThrow(new MessageException(""))
|
.thenThrow(new MessageException(""))
|
||||||
.thenThrow(new AssociationException(""))
|
.thenThrow(new AssociationException(""))
|
||||||
@@ -184,7 +184,7 @@ public class OpenID4JavaConsumerTests {
|
|||||||
Message msg = mock(Message.class);
|
Message msg = mock(Message.class);
|
||||||
|
|
||||||
when(
|
when(
|
||||||
mgr.verify(anyString(), any(ParameterList.class),
|
mgr.verify(any(), any(ParameterList.class),
|
||||||
any(DiscoveryInformation.class))).thenReturn(vr);
|
any(DiscoveryInformation.class))).thenReturn(vr);
|
||||||
when(vr.getVerifiedId()).thenReturn(id);
|
when(vr.getVerifiedId()).thenReturn(id);
|
||||||
when(vr.getAuthResponse()).thenReturn(msg);
|
when(vr.getAuthResponse()).thenReturn(msg);
|
||||||
|
|||||||
+2
-2
@@ -79,7 +79,7 @@ public class AbstractAuthorizeTagTests {
|
|||||||
|
|
||||||
tag.authorizeUsingUrlCheck();
|
tag.authorizeUsingUrlCheck();
|
||||||
|
|
||||||
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any(Authentication.class));
|
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,7 +93,7 @@ public class AbstractAuthorizeTagTests {
|
|||||||
|
|
||||||
tag.authorizeUsingUrlCheck();
|
tag.authorizeUsingUrlCheck();
|
||||||
|
|
||||||
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any(Authentication.class));
|
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ dependencies {
|
|||||||
testCompile 'org.skyscreamer:jsonassert'
|
testCompile 'org.skyscreamer:jsonassert'
|
||||||
testCompile 'org.springframework:spring-webmvc'
|
testCompile 'org.springframework:spring-webmvc'
|
||||||
testCompile 'org.springframework:spring-tx'
|
testCompile 'org.springframework:spring-tx'
|
||||||
testCompile powerMockDependencies
|
testCompile powerMock2Dependencies
|
||||||
}
|
}
|
||||||
|
|||||||
-3
@@ -55,7 +55,6 @@ public class WithMockUserSecurityContextFactoryTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void usernamePrioritizedOverValue() {
|
public void usernamePrioritizedOverValue() {
|
||||||
when(withUser.value()).thenReturn("valueUser");
|
|
||||||
when(withUser.username()).thenReturn("customUser");
|
when(withUser.username()).thenReturn("customUser");
|
||||||
when(withUser.password()).thenReturn("password");
|
when(withUser.password()).thenReturn("password");
|
||||||
when(withUser.roles()).thenReturn(new String[] { "USER" });
|
when(withUser.roles()).thenReturn(new String[] { "USER" });
|
||||||
@@ -94,7 +93,6 @@ public class WithMockUserSecurityContextFactoryTests {
|
|||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void authoritiesAndRolesInvalid() {
|
public void authoritiesAndRolesInvalid() {
|
||||||
when(withUser.value()).thenReturn("valueUser");
|
when(withUser.value()).thenReturn("valueUser");
|
||||||
when(withUser.password()).thenReturn("password");
|
|
||||||
when(withUser.roles()).thenReturn(new String[] { "CUSTOM" });
|
when(withUser.roles()).thenReturn(new String[] { "CUSTOM" });
|
||||||
when(withUser.authorities()).thenReturn(new String[] { "USER", "CUSTOM" });
|
when(withUser.authorities()).thenReturn(new String[] { "USER", "CUSTOM" });
|
||||||
|
|
||||||
@@ -104,7 +102,6 @@ public class WithMockUserSecurityContextFactoryTests {
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void rolesWithRolePrefixFails() {
|
public void rolesWithRolePrefixFails() {
|
||||||
when(withUser.value()).thenReturn("valueUser");
|
when(withUser.value()).thenReturn("valueUser");
|
||||||
when(withUser.password()).thenReturn("password");
|
|
||||||
when(withUser.roles()).thenReturn(new String[] { "ROLE_FAIL" });
|
when(withUser.roles()).thenReturn(new String[] { "ROLE_FAIL" });
|
||||||
when(withUser.authorities()).thenReturn(new String[] {});
|
when(withUser.authorities()).thenReturn(new String[] {});
|
||||||
|
|
||||||
|
|||||||
-2
@@ -75,7 +75,6 @@ public class WithSecurityContextTestExcecutionListenerTests {
|
|||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public void beforeTestMethodNullSecurityContextNoError() throws Exception {
|
public void beforeTestMethodNullSecurityContextNoError() throws Exception {
|
||||||
Class testClass = FakeTest.class;
|
Class testClass = FakeTest.class;
|
||||||
when(testContext.getApplicationContext()).thenReturn(context);
|
|
||||||
when(testContext.getTestClass()).thenReturn(testClass);
|
when(testContext.getTestClass()).thenReturn(testClass);
|
||||||
when(testContext.getTestMethod()).thenReturn(
|
when(testContext.getTestMethod()).thenReturn(
|
||||||
ReflectionUtils.findMethod(testClass, "testNoAnnotation"));
|
ReflectionUtils.findMethod(testClass, "testNoAnnotation"));
|
||||||
@@ -88,7 +87,6 @@ public class WithSecurityContextTestExcecutionListenerTests {
|
|||||||
public void beforeTestMethodNoApplicationContext() throws Exception {
|
public void beforeTestMethodNoApplicationContext() throws Exception {
|
||||||
Class testClass = FakeTest.class;
|
Class testClass = FakeTest.class;
|
||||||
when(testContext.getApplicationContext()).thenThrow(new IllegalStateException());
|
when(testContext.getApplicationContext()).thenThrow(new IllegalStateException());
|
||||||
when(testContext.getTestClass()).thenReturn(testClass);
|
|
||||||
when(testContext.getTestMethod()).thenReturn(
|
when(testContext.getTestMethod()).thenReturn(
|
||||||
ReflectionUtils.findMethod(testClass, "testWithMockUser"));
|
ReflectionUtils.findMethod(testClass, "testWithMockUser"));
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -32,6 +32,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest;
|
import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
@@ -43,6 +44,7 @@ import org.springframework.security.web.context.SecurityContextRepository;
|
|||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareOnlyThisForTest(WebTestUtils.class)
|
@PrepareOnlyThisForTest(WebTestUtils.class)
|
||||||
|
@PowerMockIgnore("javax.security.auth.*")
|
||||||
public class SecurityMockMvcRequestPostProcessorsAuthenticationTests {
|
public class SecurityMockMvcRequestPostProcessorsAuthenticationTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<SecurityContext> contextCaptor;
|
private ArgumentCaptor<SecurityContext> contextCaptor;
|
||||||
@@ -79,4 +81,4 @@ public class SecurityMockMvcRequestPostProcessorsAuthenticationTests {
|
|||||||
spy(WebTestUtils.class);
|
spy(WebTestUtils.class);
|
||||||
when(WebTestUtils.getSecurityContextRepository(request)).thenReturn(repository);
|
when(WebTestUtils.getSecurityContextRepository(request)).thenReturn(repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ dependencies {
|
|||||||
testCompile 'commons-codec:commons-codec'
|
testCompile 'commons-codec:commons-codec'
|
||||||
testCompile 'org.codehaus.groovy:groovy-all'
|
testCompile 'org.codehaus.groovy:groovy-all'
|
||||||
testCompile 'org.skyscreamer:jsonassert'
|
testCompile 'org.skyscreamer:jsonassert'
|
||||||
testCompile powerMockDependencies
|
testCompile powerMock2Dependencies
|
||||||
testCompile spockDependencies
|
testCompile spockDependencies
|
||||||
testCompile slf4jDependencies
|
testCompile slf4jDependencies
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ public class FilterChainProxyTests {
|
|||||||
fc.doFilter(extraWrapper, (HttpServletResponse) args[1]);
|
fc.doFilter(extraWrapper, (HttpServletResponse) args[1]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(filter).doFilter(any(HttpServletRequest.class),
|
}).when(filter).doFilter(any(),
|
||||||
any(HttpServletResponse.class), any(FilterChain.class));
|
any(), any());
|
||||||
fcp = new FilterChainProxy(new DefaultSecurityFilterChain(matcher,
|
fcp = new FilterChainProxy(new DefaultSecurityFilterChain(matcher,
|
||||||
Arrays.asList(filter)));
|
Arrays.asList(filter)));
|
||||||
fcp.setFilterChainValidator(mock(FilterChainProxy.FilterChainValidator.class));
|
fcp.setFilterChainValidator(mock(FilterChainProxy.FilterChainValidator.class));
|
||||||
@@ -127,12 +127,12 @@ public class FilterChainProxyTests {
|
|||||||
@Test
|
@Test
|
||||||
public void requestIsWrappedForMatchingAndFilteringWhenMatchIsFound()
|
public void requestIsWrappedForMatchingAndFilteringWhenMatchIsFound()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
when(matcher.matches(any(HttpServletRequest.class))).thenReturn(true);
|
when(matcher.matches(any())).thenReturn(true);
|
||||||
fcp.doFilter(request, response, chain);
|
fcp.doFilter(request, response, chain);
|
||||||
verify(matcher).matches(any(FirewalledRequest.class));
|
verify(matcher).matches(any(FirewalledRequest.class));
|
||||||
verify(filter).doFilter(any(FirewalledRequest.class),
|
verify(filter).doFilter(any(FirewalledRequest.class),
|
||||||
any(HttpServletResponse.class), any(FilterChain.class));
|
any(HttpServletResponse.class), any(FilterChain.class));
|
||||||
verify(chain).doFilter(any(FirewalledRequest.class),
|
verify(chain).doFilter(any(),
|
||||||
any(HttpServletResponse.class));
|
any(HttpServletResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ public class FilterChainProxyTests {
|
|||||||
when(fw.getFirewalledRequest(firstFwr)).thenReturn(fwr);
|
when(fw.getFirewalledRequest(firstFwr)).thenReturn(fwr);
|
||||||
when(fwr.getRequest()).thenReturn(firstFwr);
|
when(fwr.getRequest()).thenReturn(firstFwr);
|
||||||
when(firstFwr.getRequest()).thenReturn(request);
|
when(firstFwr.getRequest()).thenReturn(request);
|
||||||
when(matcher.matches(any(HttpServletRequest.class))).thenReturn(true);
|
when(matcher.matches(any())).thenReturn(true);
|
||||||
firstFcp.doFilter(request, response, chain);
|
firstFcp.doFilter(request, response, chain);
|
||||||
verify(firstFwr).reset();
|
verify(firstFwr).reset();
|
||||||
verify(fwr).reset();
|
verify(fwr).reset();
|
||||||
|
|||||||
+1
-7
@@ -72,13 +72,7 @@ public class WebExpressionVoterTests {
|
|||||||
EvaluationContextPostProcessor postProcessor = mock(
|
EvaluationContextPostProcessor postProcessor = mock(
|
||||||
EvaluationContextPostProcessor.class);
|
EvaluationContextPostProcessor.class);
|
||||||
when(postProcessor.postProcess(any(EvaluationContext.class),
|
when(postProcessor.postProcess(any(EvaluationContext.class),
|
||||||
any(FilterInvocation.class))).thenAnswer(new Answer<EvaluationContext>() {
|
any(FilterInvocation.class))).thenAnswer( invocation -> invocation.getArgument(0));
|
||||||
|
|
||||||
public EvaluationContext answer(InvocationOnMock invocation)
|
|
||||||
throws Throwable {
|
|
||||||
return invocation.getArgumentAt(0, EvaluationContext.class);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
WebExpressionConfigAttribute weca = new WebExpressionConfigAttribute(ex,
|
WebExpressionConfigAttribute weca = new WebExpressionConfigAttribute(ex,
|
||||||
postProcessor);
|
postProcessor);
|
||||||
EvaluationContext ctx = mock(EvaluationContext.class);
|
EvaluationContext ctx = mock(EvaluationContext.class);
|
||||||
|
|||||||
+2
-2
@@ -67,7 +67,7 @@ public class AbstractRememberMeServicesServlet3Tests {
|
|||||||
MockRememberMeServices services = new MockRememberMeServices();
|
MockRememberMeServices services = new MockRememberMeServices();
|
||||||
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
|
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
|
||||||
verify(response).addCookie(cookie.capture());
|
verify(response).addCookie(cookie.capture());
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), eq(cookie.getValue()), eq(true));
|
ReflectionUtils.invokeMethod(same(method), eq(cookie.getValue()), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class AbstractRememberMeServicesServlet3Tests {
|
|||||||
mock(UserDetailsService.class));
|
mock(UserDetailsService.class));
|
||||||
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
|
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
|
||||||
verify(response).addCookie(cookie.capture());
|
verify(response).addCookie(cookie.capture());
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), eq(cookie.getValue()), eq(true));
|
ReflectionUtils.invokeMethod(same(method), eq(cookie.getValue()), eq(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -27,6 +27,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest;
|
import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
@@ -50,6 +51,7 @@ import org.springframework.util.StringUtils;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareOnlyThisForTest(ReflectionUtils.class)
|
@PrepareOnlyThisForTest(ReflectionUtils.class)
|
||||||
|
@PowerMockIgnore("javax.security.auth.*")
|
||||||
public class AbstractRememberMeServicesTests {
|
public class AbstractRememberMeServicesTests {
|
||||||
|
|
||||||
static User joe = new User("joe", "password", true, true, true, true,
|
static User joe = new User("joe", "password", true, true, true, true,
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ public class ChangeSessionIdAuthenticationStrategyTests {
|
|||||||
|
|
||||||
new ChangeSessionIdAuthenticationStrategy().applySessionFixation(request);
|
new ChangeSessionIdAuthenticationStrategy().applySessionFixation(request);
|
||||||
|
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(method), eq(request));
|
ReflectionUtils.invokeMethod(same(method), eq(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -309,7 +309,7 @@ public class ConcurrentSessionFilterTests {
|
|||||||
|
|
||||||
filter.doFilter(request, response, new MockFilterChain());
|
filter.doFilter(request, response, new MockFilterChain());
|
||||||
|
|
||||||
verify(handler).logout(eq(request), eq(response), any(Authentication.class));
|
verify(handler).logout(eq(request), eq(response), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
|||||||
-3
@@ -64,9 +64,6 @@ public class WebAsyncManagerIntegrationFilterTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
when(asyncWebRequest.getNativeRequest(HttpServletRequest.class)).thenReturn(
|
|
||||||
request);
|
|
||||||
when(request.getRequestURI()).thenReturn("/");
|
|
||||||
filterChain = new MockFilterChain();
|
filterChain = new MockFilterChain();
|
||||||
|
|
||||||
threadFactory = new JoinableThreadFactory();
|
threadFactory = new JoinableThreadFactory();
|
||||||
|
|||||||
+3
-3
@@ -67,7 +67,7 @@ public class CookieCsrfTokenRepositoryServlet3Tests {
|
|||||||
repository.saveToken(token, request, response);
|
repository.saveToken(token, request, response);
|
||||||
|
|
||||||
verify(response).addCookie(cookie.capture());
|
verify(response).addCookie(cookie.capture());
|
||||||
verifyStatic();
|
verifyStatic(ReflectionUtils.class);
|
||||||
ReflectionUtils.invokeMethod(same(this.method), eq(cookie.getValue()), eq(true));
|
ReflectionUtils.invokeMethod(same(this.method), eq(cookie.getValue()), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +88,8 @@ public class CookieCsrfTokenRepositoryServlet3Tests {
|
|||||||
repository.saveToken(token, request, response);
|
repository.saveToken(token, request, response);
|
||||||
|
|
||||||
verify(response).addCookie(cookie.capture());
|
verify(response).addCookie(cookie.capture());
|
||||||
verifyStatic(never());
|
verifyStatic(ReflectionUtils.class, never());
|
||||||
ReflectionUtils.invokeMethod(same(this.method), eq(cookie.getValue()), eq(true));
|
ReflectionUtils.invokeMethod(same(this.method), eq(cookie.getValue()), eq(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-8
@@ -65,12 +65,8 @@ public class MvcRequestMatcherTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractUriTemplateVariablesSuccess() throws Exception {
|
public void extractUriTemplateVariablesSuccess() throws Exception {
|
||||||
when(this.result.extractUriTemplateVariables())
|
|
||||||
.thenReturn(Collections.singletonMap("p", "path"));
|
|
||||||
when(this.introspector.getMatchableHandlerMapping(this.request))
|
when(this.introspector.getMatchableHandlerMapping(this.request))
|
||||||
.thenReturn(this.mapping);
|
.thenReturn(this.mapping);
|
||||||
when(this.mapping.match(eq(this.request), this.pattern.capture()))
|
|
||||||
.thenReturn(this.result);
|
|
||||||
|
|
||||||
this.matcher = new MvcRequestMatcher(this.introspector, "/{p}");
|
this.matcher = new MvcRequestMatcher(this.introspector, "/{p}");
|
||||||
when(this.introspector.getMatchableHandlerMapping(this.request)).thenReturn(null);
|
when(this.introspector.getMatchableHandlerMapping(this.request)).thenReturn(null);
|
||||||
@@ -123,10 +119,6 @@ public class MvcRequestMatcherTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchesServletPathFalse() throws Exception {
|
public void matchesServletPathFalse() throws Exception {
|
||||||
when(this.introspector.getMatchableHandlerMapping(this.request))
|
|
||||||
.thenReturn(this.mapping);
|
|
||||||
when(this.mapping.match(eq(this.request), this.pattern.capture()))
|
|
||||||
.thenReturn(this.result);
|
|
||||||
this.matcher.setServletPath("/spring");
|
this.matcher.setServletPath("/spring");
|
||||||
this.request.setServletPath("/");
|
this.request.setServletPath("/");
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -27,7 +27,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||||
import org.springframework.security.web.util.matcher.AndRequestMatcher;
|
import org.springframework.security.web.util.matcher.AndRequestMatcher;
|
||||||
|
|
||||||
@@ -107,7 +108,6 @@ public class AndRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiBothFalse() {
|
public void matchesMultiBothFalse() {
|
||||||
when(delegate.matches(request)).thenReturn(false);
|
when(delegate.matches(request)).thenReturn(false);
|
||||||
when(delegate2.matches(request)).thenReturn(false);
|
|
||||||
matcher = new AndRequestMatcher(delegate, delegate2);
|
matcher = new AndRequestMatcher(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(request)).isFalse();
|
assertThat(matcher.matches(request)).isFalse();
|
||||||
@@ -121,4 +121,4 @@ public class AndRequestMatcherTests {
|
|||||||
|
|
||||||
assertThat(matcher.matches(request)).isFalse();
|
assertThat(matcher.matches(request)).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -211,7 +211,6 @@ public class AntPathRequestMatcherTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HttpServletRequest createRequestWithNullMethod(String path) {
|
private HttpServletRequest createRequestWithNullMethod(String path) {
|
||||||
when(this.request.getQueryString()).thenReturn("doesntMatter");
|
|
||||||
when(this.request.getServletPath()).thenReturn(path);
|
when(this.request.getServletPath()).thenReturn(path);
|
||||||
return this.request;
|
return this.request;
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -90,7 +90,6 @@ public class OrRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiTrue() {
|
public void matchesMultiTrue() {
|
||||||
when(delegate.matches(request)).thenReturn(true);
|
when(delegate.matches(request)).thenReturn(true);
|
||||||
when(delegate2.matches(request)).thenReturn(true);
|
|
||||||
matcher = new OrRequestMatcher(delegate, delegate2);
|
matcher = new OrRequestMatcher(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(request)).isTrue();
|
assertThat(matcher.matches(request)).isTrue();
|
||||||
@@ -116,7 +115,6 @@ public class OrRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void matchesMultiSingleFalse() {
|
public void matchesMultiSingleFalse() {
|
||||||
when(delegate.matches(request)).thenReturn(true);
|
when(delegate.matches(request)).thenReturn(true);
|
||||||
when(delegate2.matches(request)).thenReturn(false);
|
|
||||||
matcher = new OrRequestMatcher(delegate, delegate2);
|
matcher = new OrRequestMatcher(delegate, delegate2);
|
||||||
|
|
||||||
assertThat(matcher.matches(request)).isTrue();
|
assertThat(matcher.matches(request)).isTrue();
|
||||||
|
|||||||
-1
@@ -95,7 +95,6 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
|||||||
@Test
|
@Test
|
||||||
public void resolveArgumentWhenIsEmptyThenMonoEmpty() throws Exception {
|
public void resolveArgumentWhenIsEmptyThenMonoEmpty() throws Exception {
|
||||||
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
|
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
|
||||||
when(authentication.getPrincipal()).thenReturn("user");
|
|
||||||
when(exchange.getPrincipal()).thenReturn(Mono.empty());
|
when(exchange.getPrincipal()).thenReturn(Mono.empty());
|
||||||
|
|
||||||
Mono<Object> argument = resolver.resolveArgument(parameter, bindingContext, exchange);
|
Mono<Object> argument = resolver.resolveArgument(parameter, bindingContext, exchange);
|
||||||
|
|||||||
-1
@@ -253,7 +253,6 @@ public class AuthenticationWebFilterTests {
|
|||||||
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
||||||
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
||||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.error(new RuntimeException("Failed")));
|
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.error(new RuntimeException("Failed")));
|
||||||
when(this.failureHandler.onAuthenticationFailure(any(),any())).thenReturn(Mono.empty());
|
|
||||||
|
|
||||||
WebTestClient client = WebTestClientBuilder
|
WebTestClient client = WebTestClientBuilder
|
||||||
.bindToWebFilters(this.filter)
|
.bindToWebFilters(this.filter)
|
||||||
|
|||||||
Reference in New Issue
Block a user