Start AssertJ Migration

Issue gh-3175
This commit is contained in:
Rob Winch
2015-12-16 10:38:31 -06:00
parent 6cbb439701
commit bb600a473e
355 changed files with 3036 additions and 3133 deletions

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -23,7 +23,7 @@ public class DefaultRedirectStrategyTests {
rds.sendRedirect(request, response, "http://context.blah.com/context/remainder");
assertEquals("remainder", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("remainder");
}
// SEC-2177
@@ -39,6 +39,6 @@ public class DefaultRedirectStrategyTests {
rds.sendRedirect(request, response,
"http://http://context.blah.com/context/remainder");
assertEquals("remainder", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("remainder");
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.After;
@@ -75,8 +75,8 @@ public class FilterChainProxyTests {
public void securityFilterChainIsNotInvokedIfMatchFails() throws Exception {
when(matcher.matches(any(HttpServletRequest.class))).thenReturn(false);
fcp.doFilter(request, response, chain);
assertEquals(1, fcp.getFilterChains().size());
assertSame(filter, fcp.getFilterChains().get(0).getFilters().get(0));
assertThat(fcp.getFilterChains()).hasSize(1);
assertThat(fcp.getFilterChains().get(0).getFilters().get(0)).isSameAs(filter);
verifyZeroInteractions(filter);
// The actual filter chain should be invoked though
@@ -183,7 +183,7 @@ public class FilterChainProxyTests {
fcp.doFilter(request, response, chain);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -205,7 +205,7 @@ public class FilterChainProxyTests {
catch (ServletException success) {
}
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
// SEC-2027
@@ -227,8 +227,7 @@ public class FilterChainProxyTests {
any(HttpServletResponse.class), any(FilterChain.class));
;
fcp.doFilter(request, response, innerChain);
assertSame(expected, SecurityContextHolder.getContext()
.getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(expected);
return null;
}
}).when(filter).doFilter(any(HttpServletRequest.class),
@@ -238,6 +237,6 @@ public class FilterChainProxyTests {
verify(innerChain).doFilter(any(HttpServletRequest.class),
any(HttpServletResponse.class));
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import javax.servlet.FilterChain;
@@ -53,17 +53,14 @@ public class FilterInvocationTests {
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
FilterInvocation fi = new FilterInvocation(request, response, chain);
assertEquals(request, fi.getRequest());
assertEquals(request, fi.getHttpRequest());
assertEquals(response, fi.getResponse());
assertEquals(response, fi.getHttpResponse());
assertEquals(chain, fi.getChain());
assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html",
fi.toString());
assertEquals(
"http://www.example.com/mycontext/HelloWorld/some/more/segments.html",
fi.getFullRequestUrl());
assertThat(fi.getRequest()).isEqualTo(request);
assertThat(fi.getHttpRequest()).isEqualTo(request);
assertThat(fi.getResponse()).isEqualTo(response);
assertThat(fi.getHttpResponse()).isEqualTo(response);
assertThat(fi.getChain()).isEqualTo(chain);
assertThat(fi.getRequestUrl()).isEqualTo("/HelloWorld/some/more/segments.html");
assertThat(fi.toString()).isEqualTo("FilterInvocation: URL: /HelloWorld/some/more/segments.html");
assertThat(fi.getFullRequestUrl()).isEqualTo("http://www.example.com/mycontext/HelloWorld/some/more/segments.html");
}
@Test(expected = IllegalArgumentException.class)
@@ -102,10 +99,9 @@ public class FilterInvocationTests {
MockHttpServletResponse response = new MockHttpServletResponse();
FilterInvocation fi = new FilterInvocation(request, response,
mock(FilterChain.class));
assertEquals("/HelloWorld?foo=bar", fi.getRequestUrl());
assertEquals("FilterInvocation: URL: /HelloWorld?foo=bar", fi.toString());
assertEquals("http://www.example.com/mycontext/HelloWorld?foo=bar",
fi.getFullRequestUrl());
assertThat(fi.getRequestUrl()).isEqualTo("/HelloWorld?foo=bar");
assertThat(fi.toString()).isEqualTo("FilterInvocation: URL: /HelloWorld?foo=bar");
assertThat(fi.getFullRequestUrl()).isEqualTo("http://www.example.com/mycontext/HelloWorld?foo=bar");
}
@Test
@@ -121,10 +117,9 @@ public class FilterInvocationTests {
MockHttpServletResponse response = new MockHttpServletResponse();
FilterInvocation fi = new FilterInvocation(request, response,
mock(FilterChain.class));
assertEquals("/HelloWorld", fi.getRequestUrl());
assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
assertEquals("http://www.example.com/mycontext/HelloWorld",
fi.getFullRequestUrl());
assertThat(fi.getRequestUrl()).isEqualTo("/HelloWorld");
assertThat(fi.toString()).isEqualTo("FilterInvocation: URL: /HelloWorld");
assertThat(fi.getFullRequestUrl()).isEqualTo("http://www.example.com/mycontext/HelloWorld");
}
@Test(expected = UnsupportedOperationException.class)

View File

@@ -15,6 +15,8 @@
package org.springframework.security.web;
import static org.assertj.core.api.Assertions.assertThat;
import junit.framework.TestCase;
import java.util.HashMap;
@@ -33,7 +35,7 @@ public class PortMapperImplTests extends TestCase {
public void testDefaultMappingsAreKnown() throws Exception {
PortMapperImpl portMapper = new PortMapperImpl();
assertEquals(Integer.valueOf(80), portMapper.lookupHttpPort(Integer.valueOf(443)));
assertThat(portMapper.lookupHttpPort(Integer.valueOf(443))).isEqualTo(Integer.valueOf(80));
assertEquals(Integer.valueOf(8080),
portMapper.lookupHttpPort(Integer.valueOf(8443)));
assertEquals(Integer.valueOf(443),
@@ -50,7 +52,7 @@ public class PortMapperImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@@ -62,13 +64,13 @@ public class PortMapperImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testGetTranslatedPortMappings() {
PortMapperImpl portMapper = new PortMapperImpl();
assertEquals(2, portMapper.getTranslatedPortMappings().size());
assertThat(portMapper.getTranslatedPortMappings()).hasSize(2);
}
public void testRejectsOutOfRangeMappings() {
@@ -81,13 +83,13 @@ public class PortMapperImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testReturnsNullIfHttpPortCannotBeFound() {
PortMapperImpl portMapper = new PortMapperImpl();
assertTrue(portMapper.lookupHttpPort(Integer.valueOf("34343")) == null);
assertThat(portMapper.lookupHttpPort(Integer.valueOf("34343")) == null).isTrue();
}
public void testSupportsCustomMappings() {
@@ -97,7 +99,7 @@ public class PortMapperImplTests extends TestCase {
portMapper.setPortMappings(map);
assertEquals(Integer.valueOf(79), portMapper.lookupHttpPort(Integer.valueOf(442)));
assertThat(portMapper.lookupHttpPort(Integer.valueOf(442))).isEqualTo(Integer.valueOf(79));
assertEquals(Integer.valueOf(442),
portMapper.lookupHttpsPort(Integer.valueOf(79)));
}

View File

@@ -15,6 +15,8 @@
package org.springframework.security.web;
import static org.assertj.core.api.Assertions.assertThat;
import junit.framework.TestCase;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -51,7 +53,7 @@ public class PortResolverImplTests extends TestCase {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServerPort(8443);
request.setScheme("HTtP"); // proves case insensitive handling
assertEquals(8080, pr.getServerPort(request));
assertThat(pr.getServerPort(request)).isEqualTo(8080);
}
public void testDetectsBuggyIeHttpsRequest() throws Exception {
@@ -60,7 +62,7 @@ public class PortResolverImplTests extends TestCase {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServerPort(8080);
request.setScheme("HTtPs"); // proves case insensitive handling
assertEquals(8443, pr.getServerPort(request));
assertThat(pr.getServerPort(request)).isEqualTo(8443);
}
public void testDetectsEmptyPortMapper() throws Exception {
@@ -71,15 +73,15 @@ public class PortResolverImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testGettersSetters() throws Exception {
PortResolverImpl pr = new PortResolverImpl();
assertTrue(pr.getPortMapper() != null);
assertThat(pr.getPortMapper() != null).isTrue();
pr.setPortMapper(new PortMapperImpl());
assertTrue(pr.getPortMapper() != null);
assertThat(pr.getPortMapper() != null).isTrue();
}
public void testNormalOperation() throws Exception {
@@ -88,6 +90,6 @@ public class PortResolverImplTests extends TestCase {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerPort(1021);
assertEquals(1021, pr.getServerPort(request));
assertThat(pr.getServerPort(request)).isEqualTo(1021);
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.access;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
@@ -67,8 +67,8 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
interceptor);
when(ods.getAttributes(anyObject())).thenReturn(null);
assertTrue(wipe.isAllowed("/context", "/foo/index.jsp", "GET",
mock(Authentication.class)));
assertThat(wipe.isAllowed("/context", "/foo/index.jsp", "GET",
mock(Authentication.class))).isTrue();
}
@Test
@@ -78,15 +78,15 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
interceptor);
when(ods.getAttributes(anyObject())).thenReturn(null);
interceptor.setRejectPublicInvocations(true);
assertFalse(wipe.isAllowed("/context", "/foo/index.jsp", "GET",
mock(Authentication.class)));
assertThat(wipe.isAllowed("/context", "/foo/index.jsp", "GET",
mock(Authentication.class))).isFalse();
}
@Test
public void deniesAccessIfAuthenticationIsNull() throws Exception {
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
interceptor);
assertFalse(wipe.isAllowed("/foo/index.jsp", null));
assertThat(wipe.isAllowed("/foo/index.jsp", null)).isFalse();
}
@Test
@@ -95,7 +95,7 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
"MOCK_INDEX");
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
interceptor);
assertTrue(wipe.isAllowed("/foo/index.jsp", token));
assertThat(wipe.isAllowed("/foo/index.jsp", token)).isTrue();
}
@SuppressWarnings("unchecked")
@@ -109,6 +109,6 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
doThrow(new AccessDeniedException("")).when(adm).decide(
any(Authentication.class), anyObject(), anyList());
assertFalse(wipe.isAllowed("/foo/index.jsp", token));
assertThat(wipe.isAllowed("/foo/index.jsp", token)).isFalse();
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.access;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -97,13 +97,12 @@ public class ExceptionTranslationFilterTests {
// Test
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(mockEntryPoint);
filter.setAuthenticationTrustResolver(new AuthenticationTrustResolverImpl());
assertNotNull(filter.getAuthenticationTrustResolver());
assertThat(filter.getAuthenticationTrustResolver()).isNotNull();
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, fc);
assertEquals("/mycontext/login.jsp", response.getRedirectedUrl());
assertEquals("http://www.example.com/mycontext/secure/page.html",
getSavedRequestUrl(request));
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/login.jsp");
assertThat(getSavedRequestUrl(request)).isEqualTo("http://www.example.com/mycontext/secure/page.html");
}
@Test
@@ -131,9 +130,8 @@ public class ExceptionTranslationFilterTests {
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, fc);
assertEquals(403, response.getStatus());
assertEquals(AccessDeniedException.class,
request.getAttribute(WebAttributes.ACCESS_DENIED_403).getClass());
assertThat(response.getStatus()).isEqualTo(403);
assertThat(request.getAttribute(WebAttributes.ACCESS_DENIED_403)).isExactlyInstanceOf(AccessDeniedException.class);
}
@Test
@@ -158,9 +156,8 @@ public class ExceptionTranslationFilterTests {
filter.afterPropertiesSet();
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, fc);
assertEquals("/mycontext/login.jsp", response.getRedirectedUrl());
assertEquals("http://www.example.com/mycontext/secure/page.html",
getSavedRequestUrl(request));
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/login.jsp");
assertThat(getSavedRequestUrl(request)).isEqualTo("http://www.example.com/mycontext/secure/page.html");
}
@Test
@@ -188,9 +185,8 @@ public class ExceptionTranslationFilterTests {
filter.afterPropertiesSet();
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, fc);
assertEquals("/mycontext/login.jsp", response.getRedirectedUrl());
assertEquals("http://www.example.com:8080/mycontext/secure/page.html",
getSavedRequestUrl(request));
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/login.jsp");
assertThat(getSavedRequestUrl(request)).isEqualTo("http://www.example.com:8080/mycontext/secure/page.html");
}
@Test(expected = IllegalArgumentException.class)
@@ -211,7 +207,7 @@ public class ExceptionTranslationFilterTests {
// Test
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(mockEntryPoint);
assertSame(mockEntryPoint, filter.getAuthenticationEntryPoint());
assertThat(filter.getAuthenticationEntryPoint()).isSameAs(mockEntryPoint);
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, mock(FilterChain.class));
@@ -236,8 +232,7 @@ public class ExceptionTranslationFilterTests {
fail("Should have thrown Exception");
}
catch (Exception expected) {
assertSame("The exception thrown should not have been wrapped", e,
expected);
assertThat(expected).isSameAs(e);
}
}
}

View File

@@ -55,7 +55,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("A list of ChannelProcessors is required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("A list of ChannelProcessors is required");
}
}
@@ -70,7 +70,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@@ -83,7 +83,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("A list of ChannelProcessors is required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("A list of ChannelProcessors is required");
}
}
@@ -105,7 +105,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
List<ConfigAttribute> cad = SecurityConfig.createList("xyz");
cdm.decide(fi, cad);
assertTrue(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isTrue();
}
public void testAnyChannelAttributeCausesProcessorsToBeSkipped() throws Exception {
@@ -122,7 +122,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
mock(FilterChain.class));
cdm.decide(fi, SecurityConfig.createList(new String[] { "abc", "ANY_CHANNEL" }));
assertFalse(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isFalse();
}
public void testDecideIteratesAllProcessorsIfNoneCommitAResponse() throws Exception {
@@ -141,7 +141,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
mock(FilterChain.class));
cdm.decide(fi, SecurityConfig.createList("SOME_ATTRIBUTE_NO_PROCESSORS_SUPPORT"));
assertFalse(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isFalse();
}
public void testDelegatesSupports() throws Exception {
@@ -154,14 +154,14 @@ public class ChannelDecisionManagerImplTests extends TestCase {
cdm.setChannelProcessors(list);
cdm.afterPropertiesSet();
assertTrue(cdm.supports(new SecurityConfig("xyz")));
assertTrue(cdm.supports(new SecurityConfig("abc")));
assertFalse(cdm.supports(new SecurityConfig("UNSUPPORTED")));
assertThat(cdm.supports(new SecurityConfig("xyz"))).isTrue();
assertThat(cdm.supports(new SecurityConfig("abc"))).isTrue();
assertThat(cdm.supports(new SecurityConfig("UNSUPPORTED"))).isFalse();
}
public void testGettersSetters() {
ChannelDecisionManagerImpl cdm = new ChannelDecisionManagerImpl();
assertNull(cdm.getChannelProcessors());
assertThat(cdm.getChannelProcessors()).isNull();
MockChannelProcessor cpXyz = new MockChannelProcessor("xyz", false);
MockChannelProcessor cpAbc = new MockChannelProcessor("abc", false);
@@ -170,7 +170,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
list.add(cpAbc);
cdm.setChannelProcessors(list);
assertEquals(list, cdm.getChannelProcessors());
assertThat(cdm.getChannelProcessors()).isEqualTo(list);
}
public void testStartupFailsWithEmptyChannelProcessorsList() throws Exception {
@@ -181,7 +181,7 @@ public class ChannelDecisionManagerImplTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("A list of ChannelProcessors is required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("A list of ChannelProcessors is required");
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.access.channel;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -150,13 +150,13 @@ public class ChannelProcessingFilterTests {
public void testGetterSetters() throws Exception {
ChannelProcessingFilter filter = new ChannelProcessingFilter();
filter.setChannelDecisionManager(new MockChannelDecisionManager(false, "MOCK"));
assertTrue(filter.getChannelDecisionManager() != null);
assertThat(filter.getChannelDecisionManager() != null).isTrue();
MockFilterInvocationDefinitionMap fids = new MockFilterInvocationDefinitionMap(
"/path", false, "MOCK");
filter.setSecurityMetadataSource(fids);
assertSame(fids, filter.getSecurityMetadataSource());
assertThat(filter.getSecurityMetadataSource()).isSameAs(fids);
filter.afterPropertiesSet();
}

View File

@@ -51,7 +51,7 @@ public class InsecureChannelProcessorTests extends TestCase {
processor.decide(fi, SecurityConfig.createList("SOME_IGNORED_ATTRIBUTE",
"REQUIRES_INSECURE_CHANNEL"));
assertFalse(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isFalse();
}
public void testDecideDetectsUnacceptableChannel() throws Exception {
@@ -74,7 +74,7 @@ public class InsecureChannelProcessorTests extends TestCase {
SecurityConfig.createList(new String[] { "SOME_IGNORED_ATTRIBUTE",
"REQUIRES_INSECURE_CHANNEL" }));
assertTrue(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isTrue();
}
public void testDecideRejectsNulls() throws Exception {
@@ -86,19 +86,19 @@ public class InsecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testGettersSetters() {
InsecureChannelProcessor processor = new InsecureChannelProcessor();
assertEquals("REQUIRES_INSECURE_CHANNEL", processor.getInsecureKeyword());
assertThat(processor.getInsecureKeyword()).isEqualTo("REQUIRES_INSECURE_CHANNEL");
processor.setInsecureKeyword("X");
assertEquals("X", processor.getInsecureKeyword());
assertThat(processor.getInsecureKeyword()).isEqualTo("X");
assertTrue(processor.getEntryPoint() != null);
assertThat(processor.getEntryPoint() != null).isTrue();
processor.setEntryPoint(null);
assertTrue(processor.getEntryPoint() == null);
assertThat(processor.getEntryPoint() == null).isTrue();
}
public void testMissingEntryPoint() throws Exception {
@@ -110,7 +110,7 @@ public class InsecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("entryPoint required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("entryPoint required");
}
}
@@ -123,7 +123,7 @@ public class InsecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("insecureKeyword required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("insecureKeyword required");
}
processor.setInsecureKeyword("");
@@ -133,14 +133,14 @@ public class InsecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("insecureKeyword required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("insecureKeyword required");
}
}
public void testSupports() {
InsecureChannelProcessor processor = new InsecureChannelProcessor();
assertTrue(processor.supports(new SecurityConfig("REQUIRES_INSECURE_CHANNEL")));
assertFalse(processor.supports(null));
assertFalse(processor.supports(new SecurityConfig("NOT_SUPPORTED")));
assertThat(processor.supports(new SecurityConfig("REQUIRES_INSECURE_CHANNEL"))).isTrue();
assertThat(processor.supports(null)).isFalse();
assertThat(processor.supports(new SecurityConfig("NOT_SUPPORTED"))).isFalse();
}
}

View File

@@ -72,9 +72,9 @@ public class RetryWithHttpEntryPointTests extends TestCase {
ep.setPortMapper(portMapper);
ep.setPortResolver(portResolver);
ep.setRedirectStrategy(redirector);
assertSame(portMapper, ep.getPortMapper());
assertSame(portResolver, ep.getPortResolver());
assertSame(redirector, ep.getRedirectStrategy());
assertThat(ep.getPortMapper()).isSameAs(portMapper);
assertThat(ep.getPortResolver()).isSameAs(portResolver);
assertThat(ep.getRedirectStrategy()).isSameAs(redirector);
}
public void testNormalOperation() throws Exception {
@@ -128,7 +128,7 @@ public class RetryWithHttpEntryPointTests extends TestCase {
ep.setPortResolver(new MockPortResolver(8768, 1234));
ep.commence(request, response);
assertEquals("/bigWebApp?open=true", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/bigWebApp?open=true");
}
public void testOperationWithNonStandardPort() throws Exception {

View File

@@ -63,8 +63,8 @@ public class RetryWithHttpsEntryPointTests extends TestCase {
RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
ep.setPortMapper(new PortMapperImpl());
ep.setPortResolver(new MockPortResolver(8080, 8443));
assertTrue(ep.getPortMapper() != null);
assertTrue(ep.getPortResolver() != null);
assertThat(ep.getPortMapper() != null).isTrue();
assertThat(ep.getPortResolver() != null).isTrue();
}
public void testNormalOperation() throws Exception {
@@ -118,7 +118,7 @@ public class RetryWithHttpsEntryPointTests extends TestCase {
ep.setPortResolver(new MockPortResolver(8768, 1234));
ep.commence(request, response);
assertEquals("/bigWebApp?open=true", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/bigWebApp?open=true");
}
public void testOperationWithNonStandardPort() throws Exception {

View File

@@ -54,7 +54,7 @@ public class SecureChannelProcessorTests extends TestCase {
processor.decide(fi, SecurityConfig.createList("SOME_IGNORED_ATTRIBUTE",
"REQUIRES_SECURE_CHANNEL"));
assertFalse(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isFalse();
}
public void testDecideDetectsUnacceptableChannel() throws Exception {
@@ -76,7 +76,7 @@ public class SecureChannelProcessorTests extends TestCase {
SecurityConfig.createList(new String[] { "SOME_IGNORED_ATTRIBUTE",
"REQUIRES_SECURE_CHANNEL" }));
assertTrue(fi.getResponse().isCommitted());
assertThat(fi.getResponse().isCommitted()).isTrue();
}
public void testDecideRejectsNulls() throws Exception {
@@ -88,19 +88,19 @@ public class SecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testGettersSetters() {
SecureChannelProcessor processor = new SecureChannelProcessor();
assertEquals("REQUIRES_SECURE_CHANNEL", processor.getSecureKeyword());
assertThat(processor.getSecureKeyword()).isEqualTo("REQUIRES_SECURE_CHANNEL");
processor.setSecureKeyword("X");
assertEquals("X", processor.getSecureKeyword());
assertThat(processor.getSecureKeyword()).isEqualTo("X");
assertTrue(processor.getEntryPoint() != null);
assertThat(processor.getEntryPoint() != null).isTrue();
processor.setEntryPoint(null);
assertTrue(processor.getEntryPoint() == null);
assertThat(processor.getEntryPoint() == null).isTrue();
}
public void testMissingEntryPoint() throws Exception {
@@ -112,7 +112,7 @@ public class SecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("entryPoint required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("entryPoint required");
}
}
@@ -125,7 +125,7 @@ public class SecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("secureKeyword required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("secureKeyword required");
}
processor.setSecureKeyword("");
@@ -135,14 +135,14 @@ public class SecureChannelProcessorTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("secureKeyword required", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("secureKeyword required");
}
}
public void testSupports() {
SecureChannelProcessor processor = new SecureChannelProcessor();
assertTrue(processor.supports(new SecurityConfig("REQUIRES_SECURE_CHANNEL")));
assertFalse(processor.supports(null));
assertFalse(processor.supports(new SecurityConfig("NOT_SUPPORTED")));
assertThat(processor.supports(new SecurityConfig("REQUIRES_SECURE_CHANNEL"))).isTrue();
assertThat(processor.supports(null)).isFalse();
assertThat(processor.supports(new SecurityConfig("NOT_SUPPORTED"))).isFalse();
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.access.expression;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -71,9 +71,9 @@ public class DefaultWebSecurityExpressionHandlerTests {
EvaluationContext ctx = handler.createEvaluationContext(
mock(Authentication.class), mock(FilterInvocation.class));
ExpressionParser parser = handler.getExpressionParser();
assertTrue(parser.parseExpression("@role.getAttribute() == 'ROLE_A'").getValue(
assertThat(parser.parseExpression("@role.getAttribute() == 'ROLE_A'").isTrue().getValue(
ctx, Boolean.class));
assertTrue(parser.parseExpression("@role.attribute == 'ROLE_A'").getValue(ctx,
assertThat(parser.parseExpression("@role.attribute == 'ROLE_A'").isTrue().getValue(ctx,
Boolean.class));
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.access.expression;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.security.access.ConfigAttribute;
@@ -24,15 +24,15 @@ public class ExpressionBasedFilterInvocationSecurityMetadataSourceTests {
requestMap.put(AnyRequestMatcher.INSTANCE, SecurityConfig.createList(expression));
ExpressionBasedFilterInvocationSecurityMetadataSource mds = new ExpressionBasedFilterInvocationSecurityMetadataSource(
requestMap, new DefaultWebSecurityExpressionHandler());
assertEquals(1, mds.getAllConfigAttributes().size());
assertThat(mds.getAllConfigAttributes()).hasSize(1);
Collection<ConfigAttribute> attrs = mds.getAttributes(new FilterInvocation(
"/path", "GET"));
assertEquals(1, attrs.size());
assertThat(attrs).hasSize(1);
WebExpressionConfigAttribute attribute = (WebExpressionConfigAttribute) attrs
.toArray()[0];
assertNull(attribute.getAttribute());
assertEquals(expression, attribute.getAuthorizeExpression().getExpressionString());
assertEquals(expression, attribute.toString());
assertThat(attribute.getAttribute()).isNull();
assertThat(attribute.getAuthorizeExpression().getExpressionString()).isEqualTo(expression);
assertThat(attribute.toString()).isEqualTo(expression);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,7 +1,7 @@
package org.springframework.security.web.access.expression;
import static org.fest.assertions.Assertions.*;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
@@ -37,8 +37,8 @@ public class WebExpressionVoterTests {
WebExpressionVoter voter = new WebExpressionVoter();
assertTrue(voter
.supports(new WebExpressionConfigAttribute(mock(Expression.class), mock(SecurityEvaluationContextPostProcessor.class))));
assertTrue(voter.supports(FilterInvocation.class));
assertFalse(voter.supports(MethodInvocation.class));
assertThat(voter.supports(FilterInvocation.class)).isTrue();
assertThat(voter.supports(MethodInvocation.class)).isFalse();
}
@@ -73,10 +73,10 @@ public class WebExpressionVoterTests {
attributes.addAll(SecurityConfig.createList("A", "B", "C"));
attributes.add(weca);
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(user, fi, attributes));
assertThat(fi).isCloseTo(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(user, within(attributes)));
// Second time false
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(user, fi, attributes));
assertThat(fi).isCloseTo(AccessDecisionVoter.ACCESS_DENIED, voter.vote(user, within(attributes)));
}
// SEC-2507

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.access.expression;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import javax.servlet.FilterChain;
@@ -30,11 +30,11 @@ public class WebSecurityExpressionRootTests {
mock(Authentication.class), new FilterInvocation(request,
mock(HttpServletResponse.class), mock(FilterChain.class)));
assertTrue(root.hasIpAddress("192.168.1.1"));
assertThat(root.hasIpAddress("192.168.1.1")).isTrue();
// IPv6 Address
request.setRemoteAddr("fa:db8:85a3::8a2e:370:7334");
assertTrue(root.hasIpAddress("fa:db8:85a3::8a2e:370:7334"));
assertThat(root.hasIpAddress("fa:db8:85a3::8a2e:370:7334")).isTrue();
}
@Test
@@ -46,28 +46,28 @@ public class WebSecurityExpressionRootTests {
mock(HttpServletResponse.class), mock(FilterChain.class)));
for (int i = 0; i < 255; i++) {
request.setRemoteAddr("192.168.1." + i);
assertTrue(root.hasIpAddress("192.168.1.0/24"));
assertThat(root.hasIpAddress("192.168.1.0/24")).isTrue();
}
request.setRemoteAddr("192.168.1.127");
// 25 = FF FF FF 80
assertTrue(root.hasIpAddress("192.168.1.0/25"));
assertThat(root.hasIpAddress("192.168.1.0/25")).isTrue();
// encroach on the mask
request.setRemoteAddr("192.168.1.128");
assertFalse(root.hasIpAddress("192.168.1.0/25"));
assertThat(root.hasIpAddress("192.168.1.0/25")).isFalse();
request.setRemoteAddr("192.168.1.255");
assertTrue(root.hasIpAddress("192.168.1.128/25"));
assertTrue(root.hasIpAddress("192.168.1.192/26"));
assertTrue(root.hasIpAddress("192.168.1.224/27"));
assertTrue(root.hasIpAddress("192.168.1.240/27"));
assertTrue(root.hasIpAddress("192.168.1.255/32"));
assertThat(root.hasIpAddress("192.168.1.128/25")).isTrue();
assertThat(root.hasIpAddress("192.168.1.192/26")).isTrue();
assertThat(root.hasIpAddress("192.168.1.224/27")).isTrue();
assertThat(root.hasIpAddress("192.168.1.240/27")).isTrue();
assertThat(root.hasIpAddress("192.168.1.255/32")).isTrue();
request.setRemoteAddr("202.24.199.127");
assertTrue(root.hasIpAddress("202.24.0.0/14"));
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
request.setRemoteAddr("202.25.179.135");
assertTrue(root.hasIpAddress("202.24.0.0/14"));
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
request.setRemoteAddr("202.26.179.135");
assertTrue(root.hasIpAddress("202.24.0.0/14"));
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.access.intercept;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import java.util.Collection;
@@ -56,7 +56,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
FilterInvocation fi = createFilterInvocation("/SeCuRE/super/somefile.html", null,
null, null);
assertEquals(def, fids.getAttributes(fi));
assertThat(fids.getAttributes(fi)).isEqualTo(def);
}
/**
@@ -71,7 +71,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
null, null);
Collection<ConfigAttribute> response = fids.getAttributes(fi);
assertEquals(def, response);
assertThat(response).isEqualTo(def);
}
@Test
@@ -82,7 +82,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
null, null);
Collection<ConfigAttribute> response = fids.getAttributes(fi);
assertEquals(def, response);
assertThat(response).isEqualTo(def);
}
@Test
@@ -93,7 +93,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
"a=/test", null);
Collection<ConfigAttribute> response = fids.getAttributes(fi);
assertEquals(def, response); // see SEC-161 (it should truncate after ? sign)
assertThat(response); // see SEC-161 (it should truncate after ? sign).isEqualTo(def)
}
@Test(expected = IllegalArgumentException.class)
@@ -107,7 +107,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
FilterInvocation fi = createFilterInvocation("/somepage", null, null, "GET");
Collection<ConfigAttribute> attrs = fids.getAttributes(fi);
assertEquals(def, attrs);
assertThat(attrs).isEqualTo(def);
}
@Test
@@ -116,7 +116,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
FilterInvocation fi = createFilterInvocation("/somepage", null, null, "GET");
Collection<ConfigAttribute> attrs = fids.getAttributes(fi);
assertEquals(def, attrs);
assertThat(attrs).isEqualTo(def);
}
@Test
@@ -125,7 +125,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
FilterInvocation fi = createFilterInvocation("/somepage", null, null, "POST");
Collection<ConfigAttribute> attrs = fids.getAttributes(fi);
assertNull(attrs);
assertThat(attrs).isNull();
}
// SEC-1236
@@ -141,7 +141,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
FilterInvocation fi = createFilterInvocation("/user", null, null, "GET");
Collection<ConfigAttribute> attrs = fids.getAttributes(fi);
assertEquals(userAttrs, attrs);
assertThat(attrs).isEqualTo(userAttrs);
}
/**
@@ -155,12 +155,12 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
null);
Collection<ConfigAttribute> response = fids.getAttributes(fi);
assertEquals(def, response);
assertThat(response).isEqualTo(def);
fi = createFilterInvocation("/someAdminPage.html", null, "?", null);
response = fids.getAttributes(fi);
assertEquals(def, response);
assertThat(response).isEqualTo(def);
}
private FilterInvocation createFilterInvocation(String servletPath, String pathInfo,

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.access.intercept;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
@@ -174,8 +174,8 @@ public class FilterSecurityInterceptorTests {
}
// Check we've changed back
assertSame(ctx, SecurityContextHolder.getContext());
assertSame(token, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext()).isSameAs(ctx);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(token);
}
private FilterInvocation createinvocation() {

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.access.intercept;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.security.web.access.intercept.RequestKey;
@@ -17,10 +17,10 @@ public class RequestKeyTests {
RequestKey key1 = new RequestKey("/someurl");
RequestKey key2 = new RequestKey("/someurl");
assertEquals(key1, key2);
assertThat(key2).isEqualTo(key1);
key1 = new RequestKey("/someurl", "GET");
assertFalse(key1.equals(key2));
assertFalse(key2.equals(key1));
assertThat(key1.equals(key2)).isFalse();
assertThat(key2.equals(key1)).isFalse();
}
@Test
@@ -28,7 +28,7 @@ public class RequestKeyTests {
RequestKey key1 = new RequestKey("/someurl", "GET");
RequestKey key2 = new RequestKey("/someurl", "GET");
assertEquals(key1, key2);
assertThat(key2).isEqualTo(key1);
}
@Test
@@ -36,8 +36,8 @@ public class RequestKeyTests {
RequestKey key1 = new RequestKey("/someurl", "GET");
RequestKey key2 = new RequestKey("/someurl", "POST");
assertFalse(key1.equals(key2));
assertFalse(key2.equals(key1));
assertThat(key1.equals(key2)).isFalse();
assertThat(key2.equals(key1)).isFalse();
}
@Test
@@ -45,7 +45,7 @@ public class RequestKeyTests {
RequestKey key1 = new RequestKey("/someurl", "GET");
RequestKey key2 = new RequestKey("/anotherurl", "GET");
assertFalse(key1.equals(key2));
assertFalse(key2.equals(key1));
assertThat(key1.equals(key2)).isFalse();
assertThat(key2.equals(key1)).isFalse();
}
}

View File

@@ -15,11 +15,11 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
@@ -110,7 +110,7 @@ public class AbstractAuthenticationProcessingFilterTests {
// the firewall ensures that path parameters are ignored
HttpServletRequest firewallRequest = firewall.getFirewalledRequest(request);
assertTrue(filter.requiresAuthentication(firewallRequest, response));
assertThat(filter.requiresAuthentication(firewallRequest, response)).isTrue();
}
@Test
@@ -135,9 +135,9 @@ public class AbstractAuthenticationProcessingFilterTests {
// Test
filter.doFilter(request, response, chain);
assertEquals("/mycontext/logged_in.jsp", response.getRedirectedUrl());
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("test", SecurityContextHolder.getContext().getAuthentication()
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/logged_in.jsp");
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("test")
.getPrincipal().toString());
}
@@ -148,12 +148,12 @@ public class AbstractAuthenticationProcessingFilterTests {
filter.setFilterProcessesUrl("/p");
filter.afterPropertiesSet();
assertNotNull(filter.getRememberMeServices());
assertThat(filter.getRememberMeServices()).isNotNull();
filter.setRememberMeServices(new TokenBasedRememberMeServices("key",
new AbstractRememberMeServicesTests.MockUserDetailsService()));
assertEquals(TokenBasedRememberMeServices.class, filter.getRememberMeServices()
assertThat(filter.getRememberMeServices().isEqualTo(TokenBasedRememberMeServices.class)
.getClass());
assertTrue(filter.getAuthenticationManager() != null);
assertThat(filter.getAuthenticationManager() != null).isTrue();
}
@Test
@@ -204,12 +204,12 @@ public class AbstractAuthenticationProcessingFilterTests {
// Test
filter.doFilter(request, response, chain);
assertEquals("/mycontext/logged_in.jsp", response.getRedirectedUrl());
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("test", SecurityContextHolder.getContext().getAuthentication()
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/logged_in.jsp");
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("test")
.getPrincipal().toString());
// Should still have the same session
assertEquals(sessionPreAuth, request.getSession());
assertThat(request.getSession()).isEqualTo(sessionPreAuth);
}
@Test
@@ -225,7 +225,7 @@ public class AbstractAuthenticationProcessingFilterTests {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("authenticationManager must be specified", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("authenticationManager must be specified");
}
}
@@ -241,7 +241,7 @@ public class AbstractAuthenticationProcessingFilterTests {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("Pattern cannot be null or empty", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("Pattern cannot be null or empty");
}
}
@@ -266,9 +266,9 @@ public class AbstractAuthenticationProcessingFilterTests {
// Test
filter.doFilter(request, response, chain);
assertEquals("/mycontext/logged_in.jsp", response.getRedirectedUrl());
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("test", SecurityContextHolder.getContext().getAuthentication()
assertThat(response.getRedirectedUrl()).isEqualTo("/mycontext/logged_in.jsp");
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("test")
.getPrincipal().toString());
// Now try again but this time have filter deny access
@@ -285,7 +285,7 @@ public class AbstractAuthenticationProcessingFilterTests {
// Test
filter.doFilter(request, response, chain);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -314,7 +314,7 @@ public class AbstractAuthenticationProcessingFilterTests {
verify(successHandler).onAuthenticationSuccess(any(HttpServletRequest.class),
any(HttpServletResponse.class), any(Authentication.class));
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
}
@Test
@@ -341,7 +341,7 @@ public class AbstractAuthenticationProcessingFilterTests {
verify(failureHandler).onAuthenticationFailure(any(HttpServletRequest.class),
any(HttpServletResponse.class), any(AuthenticationException.class));
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
/**
@@ -362,7 +362,7 @@ public class AbstractAuthenticationProcessingFilterTests {
filter.doFilter(request, response, chain);
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
/**
@@ -382,7 +382,7 @@ public class AbstractAuthenticationProcessingFilterTests {
filter.doFilter(request, response, chain);
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
}
/**
@@ -407,7 +407,7 @@ public class AbstractAuthenticationProcessingFilterTests {
filter.doFilter(request, response, chain);
verify(logger).error(anyString(), eq(filter.exceptionToThrow));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED);
}
// ~ Inner Classes
@@ -450,7 +450,7 @@ public class AbstractAuthenticationProcessingFilterTests {
public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
if (expectToProceed) {
assertTrue(true);
}
else {
fail("Did not expect filter chain to proceed");

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.*;
@@ -84,7 +84,7 @@ public class AnonymousAuthenticationFilterTests {
new MockHttpServletResponse(), new MockFilterChain(true));
// Ensure filter didn't change our original object
assertEquals(originalAuth, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isEqualTo(originalAuth);
}
@Test
@@ -101,8 +101,8 @@ public class AnonymousAuthenticationFilterTests {
new MockHttpServletResponse(), new MockFilterChain(true));
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
assertEquals("anonymousUsername", auth.getPrincipal());
assertTrue(AuthorityUtils.authorityListToSet(auth.getAuthorities()).contains(
assertThat(auth.getPrincipal()).isEqualTo("anonymousUsername");
assertThat(AuthorityUtils.authorityListToSet(auth.getAuthorities()).isTrue().contains(
"ROLE_ANONYMOUS"));
SecurityContextHolder.getContext().setAuthentication(null); // so anonymous fires
// again

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Locale;

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -24,7 +24,7 @@ public class ExceptionMappingAuthenticationFailureHandlerTests {
fh.onAuthenticationFailure(new MockHttpServletRequest(), response,
new BadCredentialsException(""));
assertEquals("/failed", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/failed");
}
@Test
@@ -40,7 +40,7 @@ public class ExceptionMappingAuthenticationFailureHandlerTests {
fh.onAuthenticationFailure(new MockHttpServletRequest(), response,
new BadCredentialsException(""));
assertEquals("/badcreds", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/badcreds");
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.authentication;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.*;
@@ -60,17 +60,17 @@ public class LoginUrlAuthenticationEntryPointTests {
"/hello");
ep.setPortMapper(new PortMapperImpl());
ep.setPortResolver(new MockPortResolver(8080, 8443));
assertEquals("/hello", ep.getLoginFormUrl());
assertTrue(ep.getPortMapper() != null);
assertTrue(ep.getPortResolver() != null);
assertThat(ep.getLoginFormUrl()).isEqualTo("/hello");
assertThat(ep.getPortMapper() != null).isTrue();
assertThat(ep.getPortResolver() != null).isTrue();
ep.setForceHttps(false);
assertFalse(ep.isForceHttps());
assertThat(ep.isForceHttps()).isFalse();
ep.setForceHttps(true);
assertTrue(ep.isForceHttps());
assertFalse(ep.isUseForward());
assertThat(ep.isForceHttps()).isTrue();
assertThat(ep.isUseForward()).isFalse();
ep.setUseForward(true);
assertTrue(ep.isUseForward());
assertThat(ep.isUseForward()).isTrue();
}
@Test
@@ -227,7 +227,7 @@ public class LoginUrlAuthenticationEntryPointTests {
MockHttpServletResponse response = new MockHttpServletResponse();
ep.commence(request, response, null);
assertEquals("/hello", response.getForwardedUrl());
assertThat(response.getForwardedUrl()).isEqualTo("/hello");
}
@Test
@@ -263,7 +263,7 @@ public class LoginUrlAuthenticationEntryPointTests {
ep.afterPropertiesSet();
MockHttpServletResponse response = new MockHttpServletResponse();
ep.commence(new MockHttpServletRequest("GET", "/someUrl"), response, null);
assertEquals(loginFormUrl, response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo(loginFormUrl);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.*;
import org.junit.Test;
@@ -47,4 +47,4 @@ public class SavedRequestAwareAuthenticationSuccessHandlerTests {
verify(redirectStrategy).sendRedirect(request, response, redirectUrl);
}
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import org.junit.Test;
@@ -21,13 +21,13 @@ public class SimpleUrlAuthenticationFailureHandlerTests {
SimpleUrlAuthenticationFailureHandler afh = new SimpleUrlAuthenticationFailureHandler();
RedirectStrategy rs = mock(RedirectStrategy.class);
afh.setRedirectStrategy(rs);
assertSame(rs, afh.getRedirectStrategy());
assertThat(afh.getRedirectStrategy()).isSameAs(rs);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
afh.onAuthenticationFailure(request, response,
mock(AuthenticationException.class));
assertEquals(401, response.getStatus());
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -42,7 +42,7 @@ public class SimpleUrlAuthenticationFailureHandlerTests {
afh.onAuthenticationFailure(request, response, e);
assertSame(e,
request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION));
assertEquals("/target", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/target");
}
@Test
@@ -50,13 +50,13 @@ public class SimpleUrlAuthenticationFailureHandlerTests {
SimpleUrlAuthenticationFailureHandler afh = new SimpleUrlAuthenticationFailureHandler(
"/target");
afh.setAllowSessionCreation(false);
assertFalse(afh.isAllowSessionCreation());
assertThat(afh.isAllowSessionCreation()).isFalse();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
afh.onAuthenticationFailure(request, response,
mock(AuthenticationException.class));
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
// SEC-462
@@ -65,18 +65,18 @@ public class SimpleUrlAuthenticationFailureHandlerTests {
SimpleUrlAuthenticationFailureHandler afh = new SimpleUrlAuthenticationFailureHandler(
"/target");
afh.setUseForward(true);
assertTrue(afh.isUseForward());
assertThat(afh.isUseForward()).isTrue();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
AuthenticationException e = mock(AuthenticationException.class);
afh.onAuthenticationFailure(request, response, e);
assertNull(request.getSession(false));
assertNull(response.getRedirectedUrl());
assertEquals("/target", response.getForwardedUrl());
assertThat(request.getSession(false)).isNull();
assertThat(response.getRedirectedUrl()).isNull();
assertThat(response.getForwardedUrl()).isEqualTo("/target");
// Request scope should be used for forward
assertSame(e, request.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION));
assertThat(request.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)).isSameAs(e);
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
@@ -22,7 +22,7 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("/", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/");
}
// SEC-1428
@@ -35,7 +35,7 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
response.setCommitted(true);
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertNull(response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isNull();
}
/**
@@ -50,13 +50,13 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
request.setParameter("targetUrl", "/target");
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("/defaultTarget", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/defaultTarget");
// Try with parameter set
ash.setTargetUrlParameter("targetUrl");
response = new MockHttpServletResponse();
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("/target", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/target");
}
@Test
@@ -69,7 +69,7 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
request.addHeader("Referer", "http://www.springsource.com/");
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("http://www.springsource.com/", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("http://www.springsource.com/");
}
/**
@@ -85,7 +85,7 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("https://monkeymachine.co.uk/", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("https://monkeymachine.co.uk/");
}
@Test
@@ -93,7 +93,7 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
SimpleUrlAuthenticationSuccessHandler ash = new SimpleUrlAuthenticationSuccessHandler();
ash.setTargetUrlParameter("targetUrl");
ash.setTargetUrlParameter(null);
assertEquals(null, ash.getTargetUrlParameter());
assertThat(ash.getTargetUrlParameter()).isEqualTo(null);
}
@Test

View File

@@ -57,7 +57,7 @@ public class UsernamePasswordAuthenticationFilterTests extends TestCase {
Authentication result = filter.attemptAuthentication(request,
new MockHttpServletResponse());
assertTrue(result != null);
assertThat(result != null).isTrue();
assertEquals("127.0.0.1",
((WebAuthenticationDetails) result.getDetails()).getRemoteAddress());
}
@@ -101,7 +101,7 @@ public class UsernamePasswordAuthenticationFilterTests extends TestCase {
Authentication result = filter.attemptAuthentication(request,
new MockHttpServletResponse());
assertNotNull(result);
assertThat(result).isNotNull();
assertEquals("127.0.0.1",
((WebAuthenticationDetails) result.getDetails()).getRemoteAddress());
}
@@ -121,7 +121,7 @@ public class UsernamePasswordAuthenticationFilterTests extends TestCase {
Authentication result = filter.attemptAuthentication(request,
new MockHttpServletResponse());
assertEquals("rod", result.getName());
assertThat(result.getName()).isEqualTo("rod");
}
@Test
@@ -158,7 +158,7 @@ public class UsernamePasswordAuthenticationFilterTests extends TestCase {
filter.attemptAuthentication(request, new MockHttpServletResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
private AuthenticationManager createAuthenticationManager() {

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.logout;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import javax.servlet.http.Cookie;
@@ -23,10 +23,10 @@ public class CookieClearingLogoutHandlerTests {
request.setContextPath("");
CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie");
handler.logout(request, response, mock(Authentication.class));
assertEquals(1, response.getCookies().length);
assertThat(response.getCookies().length).isEqualTo(1);
for (Cookie c : response.getCookies()) {
assertEquals("/", c.getPath());
assertEquals(0, c.getMaxAge());
assertThat(c.getPath()).isEqualTo("/");
assertThat(c.getMaxAge()).isEqualTo(0);
}
}
@@ -38,10 +38,10 @@ public class CookieClearingLogoutHandlerTests {
CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler(
"my_cookie", "my_cookie_too");
handler.logout(request, response, mock(Authentication.class));
assertEquals(2, response.getCookies().length);
assertThat(response.getCookies().length).isEqualTo(2);
for (Cookie c : response.getCookies()) {
assertEquals("/app", c.getPath());
assertEquals(0, c.getMaxAge());
assertThat(c.getPath()).isEqualTo("/app");
assertThat(c.getMaxAge()).isEqualTo(0);
}
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.authentication.logout;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Assert;

View File

@@ -27,7 +27,7 @@ public class LogoutHandlerTests extends TestCase {
request.setQueryString("otherparam=blah");
DefaultHttpFirewall fw = new DefaultHttpFirewall();
assertTrue(filter.requiresLogout(fw.getFirewalledRequest(request), response));
assertThat(filter.requiresLogout(fw.getFirewalledRequest(request), response)).isTrue();
}
public void testRequiresLogoutUrlWorksWithQueryParams() {
@@ -39,7 +39,7 @@ public class LogoutHandlerTests extends TestCase {
request.setRequestURI("/context/logout?param=blah");
request.setQueryString("otherparam=blah");
assertTrue(filter.requiresLogout(request, response));
assertThat(filter.requiresLogout(request, response)).isTrue();
}
}

View File

@@ -12,7 +12,7 @@
*/
package org.springframework.security.web.authentication.logout;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Before;
@@ -59,7 +59,7 @@ public class SecurityContextLogoutHandlerTests {
SecurityContext beforeContext = SecurityContextHolder.getContext();
handler.logout(request, response, SecurityContextHolder.getContext()
.getAuthentication());
assertNull(beforeContext.getAuthentication());
assertThat(beforeContext.getAuthentication()).isNull();
}
@Test
@@ -70,7 +70,7 @@ public class SecurityContextLogoutHandlerTests {
handler.logout(request, response, SecurityContextHolder.getContext()
.getAuthentication());
assertNotNull(beforeContext.getAuthentication());
assertSame(beforeAuthentication, beforeContext.getAuthentication());
assertThat(beforeContext.getAuthentication()).isNotNull();
assertThat(beforeContext.getAuthentication()).isSameAs(beforeAuthentication);
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.logout;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.mock;
import org.junit.Test;
@@ -22,9 +22,9 @@ public class SimpleUrlLogoutSuccessHandlerTests {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setCommitted(true);
lsh.onLogoutSuccess(request, response, mock(Authentication.class));
assertNull(request.getSession(false));
assertNull(response.getRedirectedUrl());
assertNull(response.getForwardedUrl());
assertThat(request.getSession(false)).isNull();
assertThat(response.getRedirectedUrl()).isNull();
assertThat(response.getForwardedUrl()).isNull();
}
@Test
@@ -34,7 +34,7 @@ public class SimpleUrlLogoutSuccessHandlerTests {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
lsh.onLogoutSuccess(request, response, mock(Authentication.class));
assertEquals("http://someurl.com/", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("http://someurl.com/");
}
}

View File

@@ -12,10 +12,10 @@
*/
package org.springframework.security.web.authentication.preauth;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -79,7 +79,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
filter.afterPropertiesSet();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
mock(FilterChain.class));
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
/* SEC-881 */
@@ -94,7 +94,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
filter.afterPropertiesSet();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
mock(FilterChain.class));
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -118,7 +118,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
AuthenticationManager am = mock(AuthenticationManager.class);
filter.setAuthenticationManager(am);
filter.afterPropertiesSet();
assertTrue(filter.initFilterBeanInvoked);
assertThat(filter.initFilterBeanInvoked).isTrue();
}
@Test
@@ -143,7 +143,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
new MockFilterChain());
assertEquals(null, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isEqualTo(null);
}
@Test
@@ -158,7 +158,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
new MockFilterChain());
assertEquals(authentication, SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().isEqualTo(authentication)
.getAuthentication());
}
@@ -332,7 +332,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
getFilter(grantAccess).doFilter(req, res, new MockFilterChain());
assertEquals(grantAccess, null != SecurityContextHolder.getContext()
assertThat(null != SecurityContextHolder.getContext().isEqualTo(grantAccess)
.getAuthentication());
}

View File

@@ -22,7 +22,7 @@ public class Http403ForbiddenEntryPointTests extends TestCase {
try {
fep.commence(req, resp,
new AuthenticationCredentialsNotFoundException("test"));
assertEquals("Incorrect status", resp.getStatus(),
assertThat(resp.getStatus().isEqualTo("Incorrect status"),
HttpServletResponse.SC_FORBIDDEN);
}
catch (IOException e) {

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -39,7 +39,7 @@ public class PreAuthenticatedAuthenticationProviderTests {
Authentication request = new UsernamePasswordAuthenticationToken("dummyUser",
"dummyPwd");
Authentication result = provider.authenticate(request);
assertNull(result);
assertThat(result).isNull();
}
@Test
@@ -47,7 +47,7 @@ public class PreAuthenticatedAuthenticationProviderTests {
PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
Authentication request = new PreAuthenticatedAuthenticationToken(null, "dummyPwd");
Authentication result = provider.authenticate(request);
assertNull(result);
assertThat(result).isNull();
}
@Test
@@ -58,8 +58,8 @@ public class PreAuthenticatedAuthenticationProviderTests {
Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser",
"dummyPwd");
Authentication result = provider.authenticate(request);
assertNotNull(result);
assertEquals(result.getPrincipal(), ud);
assertThat(result).isNotNull();
assertThat(ud).isEqualTo(result.getPrincipal());
// @TODO: Add more asserts?
}
@@ -71,8 +71,8 @@ public class PreAuthenticatedAuthenticationProviderTests {
Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser1",
"dummyPwd2");
Authentication result = provider.authenticate(request);
assertNotNull(result);
assertEquals(result.getPrincipal(), ud);
assertThat(result).isNotNull();
assertThat(ud).isEqualTo(result.getPrincipal());
// @TODO: Add more asserts?
}
@@ -89,20 +89,20 @@ public class PreAuthenticatedAuthenticationProviderTests {
@Test
public final void supportsArbitraryObject() throws Exception {
PreAuthenticatedAuthenticationProvider provider = getProvider(null);
assertFalse(provider.supports(Authentication.class));
assertThat(provider.supports(Authentication.class)).isFalse();
}
@Test
public final void supportsPreAuthenticatedAuthenticationToken() throws Exception {
PreAuthenticatedAuthenticationProvider provider = getProvider(null);
assertTrue(provider.supports(PreAuthenticatedAuthenticationToken.class));
assertThat(provider.supports(PreAuthenticatedAuthenticationToken.class)).isTrue();
}
@Test
public void getSetOrder() throws Exception {
PreAuthenticatedAuthenticationProvider provider = getProvider(null);
provider.setOrder(333);
assertEquals(provider.getOrder(), 333);
assertThat(333).isEqualTo(provider.getOrder());
}
private PreAuthenticatedAuthenticationProvider getProvider(UserDetails aUserDetails)

View File

@@ -23,10 +23,10 @@ public class PreAuthenticatedAuthenticationTokenTests extends TestCase {
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(
principal, credentials);
token.setDetails(details);
assertEquals(principal, token.getPrincipal());
assertEquals(credentials, token.getCredentials());
assertEquals(details, token.getDetails());
assertTrue(token.getAuthorities().isEmpty());
assertThat(token.getPrincipal()).isEqualTo(principal);
assertThat(token.getCredentials()).isEqualTo(credentials);
assertThat(token.getDetails()).isEqualTo(details);
assertThat(token.getAuthorities().isEmpty()).isTrue();
}
public void testPreAuthenticatedAuthenticationTokenRequestWithoutDetails() {
@@ -34,10 +34,10 @@ public class PreAuthenticatedAuthenticationTokenTests extends TestCase {
Object credentials = "dummyCredentials";
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(
principal, credentials);
assertEquals(principal, token.getPrincipal());
assertEquals(credentials, token.getCredentials());
assertNull(token.getDetails());
assertTrue(token.getAuthorities().isEmpty());
assertThat(token.getPrincipal()).isEqualTo(principal);
assertThat(token.getCredentials()).isEqualTo(credentials);
assertThat(token.getDetails()).isNull();
assertThat(token.getAuthorities().isEmpty()).isTrue();
}
public void testPreAuthenticatedAuthenticationTokenResponse() {
@@ -46,10 +46,10 @@ public class PreAuthenticatedAuthenticationTokenTests extends TestCase {
List<GrantedAuthority> gas = AuthorityUtils.createAuthorityList("Role1");
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(
principal, credentials, gas);
assertEquals(principal, token.getPrincipal());
assertEquals(credentials, token.getCredentials());
assertNull(token.getDetails());
assertNotNull(token.getAuthorities());
assertThat(token.getPrincipal()).isEqualTo(principal);
assertThat(token.getCredentials()).isEqualTo(credentials);
assertThat(token.getDetails()).isNull();
assertThat(token.getAuthorities()).isNotNull();
Collection<GrantedAuthority> resultColl = token.getAuthorities();
assertTrue("GrantedAuthority collections do not match; result: " + resultColl
+ ", expected: " + gas,

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.*;
@@ -58,15 +58,15 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests {
}
});
UserDetails ud = svc.loadUserDetails(token);
assertTrue(ud.isAccountNonExpired());
assertTrue(ud.isAccountNonLocked());
assertTrue(ud.isCredentialsNonExpired());
assertTrue(ud.isEnabled());
assertEquals(ud.getUsername(), userName);
assertThat(ud.isAccountNonExpired()).isTrue();
assertThat(ud.isAccountNonLocked()).isTrue();
assertThat(ud.isCredentialsNonExpired()).isTrue();
assertThat(ud.isEnabled()).isTrue();
assertThat(userName).isEqualTo(ud.getUsername());
// Password is not saved by
// PreAuthenticatedGrantedAuthoritiesUserDetailsService
// assertEquals(ud.getPassword(),password);
// assertThat(password).isEqualTo(ud.getPassword());
assertTrue(
"GrantedAuthority collections do not match; result: "

View File

@@ -24,8 +24,8 @@ public class PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetailsTests {
PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails details = new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(
getRequest("testUser", new String[] {}), gas);
String toString = details.toString();
assertTrue("toString should contain Role1", toString.contains("Role1"));
assertTrue("toString should contain Role2", toString.contains("Role2"));
assertThat(toString.contains("Role1")).as("toString should contain Role1").isTrue();
assertThat(toString.contains("Role2")).as("toString should contain Role2").isTrue();
}
@Test

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth.header;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
@@ -50,10 +50,10 @@ public class RequestHeaderAuthenticationFilterTests {
filter.setAuthenticationManager(createAuthenticationManager());
filter.doFilter(request, response, chain);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("cat", SecurityContextHolder.getContext().getAuthentication()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("cat")
.getName());
assertEquals("N/A", SecurityContextHolder.getContext().getAuthentication()
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("N/A")
.getCredentials());
}
@@ -68,8 +68,8 @@ public class RequestHeaderAuthenticationFilterTests {
filter.setPrincipalRequestHeader("myUsernameHeader");
filter.doFilter(request, response, chain);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("wolfman", SecurityContextHolder.getContext().getAuthentication()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("wolfman")
.getName());
}
@@ -85,8 +85,8 @@ public class RequestHeaderAuthenticationFilterTests {
request.addHeader("myCredentialsHeader", "catspassword");
filter.doFilter(request, response, chain);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals("catspassword", SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(SecurityContextHolder.getContext().isEqualTo("catspassword")
.getAuthentication().getCredentials());
}
@@ -104,13 +104,13 @@ public class RequestHeaderAuthenticationFilterTests {
request.addHeader("SM_USER", "dog");
filter.doFilter(request, response, new MockFilterChain());
Authentication dog = SecurityContextHolder.getContext().getAuthentication();
assertNotNull(dog);
assertEquals("dog", dog.getName());
assertThat(dog).isNotNull();
assertThat(dog.getName()).isEqualTo("dog");
// Make sure authentication doesn't occur every time (i.e. if the header *doesn't
// change)
filter.setAuthenticationManager(mock(AuthenticationManager.class));
filter.doFilter(request, response, new MockFilterChain());
assertSame(dog, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(dog);
}
@Test(expected = PreAuthenticatedCredentialsNotFoundException.class)

View File

@@ -91,15 +91,15 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests extend
String[] expectedRoles) {
J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource src = getJ2eeBasedPreAuthenticatedWebAuthenticationDetailsSource(mappedRoles);
Object o = src.buildDetails(getRequest("testUser", userRoles));
assertNotNull(o);
assertThat(o).isNotNull();
assertTrue(
"Returned object not of type PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails, actual type: "
+ o.getClass(),
o instanceof PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails);
PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails details = (PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails) o;
List<GrantedAuthority> gas = details.getGrantedAuthorities();
assertNotNull("Granted authorities should not be null", gas);
assertEquals(expectedRoles.length, gas.size());
assertThat(gas).as("Granted authorities should not be null").isNotNull();
assertThat(gas.size()).isEqualTo(expectedRoles.length);
Collection<String> expectedRolesColl = Arrays.asList(expectedRoles);
Collection<String> gasRolesSet = new HashSet<String>();

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth.j2ee;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
@@ -32,11 +32,11 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests {
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertNotNull(j2eeRoles);
assertTrue("J2eeRoles expected size: " + ROLE1TO4_EXPECTED_ROLES.size()
assertThat(j2eeRoles).isNotNull();
assertThat("J2eeRoles expected size: " + ROLE1TO4_EXPECTED_ROLES.size().isTrue()
+ ", actual size: " + j2eeRoles.size(),
j2eeRoles.size() == ROLE1TO4_EXPECTED_ROLES.size());
assertTrue("J2eeRoles expected contents (arbitrary order): "
assertThat("J2eeRoles expected contents (arbitrary order).isTrue(): "
+ ROLE1TO4_EXPECTED_ROLES + ", actual content: " + j2eeRoles,
j2eeRoles.containsAll(ROLE1TO4_EXPECTED_ROLES));
}
@@ -56,7 +56,7 @@ public class WebXmlJ2eeDefinedRolesRetrieverTests {
});
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertEquals("J2eeRoles expected size: 0, actual size: " + j2eeRoles.size(), 0,
assertThat(actual size: " + j2eeRoles.size().isEqualTo("J2eeRoles expected size: 0), 0,
j2eeRoles.size());
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.preauth.websphere;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@@ -30,7 +30,7 @@ public class SubjectDnX509PrincipalExtractorTests {
public void defaultCNPatternReturnsExcpectedPrincipal() throws Exception {
Object principal = extractor.extractPrincipal(X509TestUtils
.buildTestCertificate());
assertEquals("Luke Taylor", principal);
assertThat(principal).isEqualTo("Luke Taylor");
}
@Test
@@ -38,7 +38,7 @@ public class SubjectDnX509PrincipalExtractorTests {
extractor.setSubjectDnRegex("emailAddress=(.*?),");
Object principal = extractor.extractPrincipal(X509TestUtils
.buildTestCertificate());
assertEquals("luke@monkeymachine", principal);
assertThat(principal).isEqualTo("luke@monkeymachine");
}
@Test(expected = BadCredentialsException.class)
@@ -51,6 +51,6 @@ public class SubjectDnX509PrincipalExtractorTests {
public void defaultCNPatternReturnsPrincipalAtEndOfDNString() throws Exception {
Object principal = extractor.extractPrincipal(X509TestUtils
.buildTestCertificateWithCnAtEnd());
assertEquals("Duke", principal);
assertThat(principal).isEqualTo("Duke");
}
}

View File

@@ -1,8 +1,8 @@
package org.springframework.security.web.authentication.rememberme;
import static org.fest.assertions.Assertions.*;
import static org.assertj.core.api.Assertions.*;
import static org.powermock.api.mockito.PowerMockito.*;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -61,19 +61,19 @@ public class AbstractRememberMeServicesTests {
@Test
public void setAndGetAreConsistent() throws Exception {
MockRememberMeServices services = new MockRememberMeServices(uds);
assertNotNull(services.getCookieName());
assertNotNull(services.getParameter());
assertEquals("xxxx", services.getKey());
assertThat(services.getCookieName()).isNotNull();
assertThat(services.getParameter()).isNotNull();
assertThat(services.getKey()).isEqualTo("xxxx");
services.setParameter("rm");
assertEquals("rm", services.getParameter());
assertThat(services.getParameter()).isEqualTo("rm");
services.setCookieName("kookie");
assertEquals("kookie", services.getCookieName());
assertThat(services.getCookieName()).isEqualTo("kookie");
services.setTokenValiditySeconds(600);
assertEquals(600, services.getTokenValiditySeconds());
assertSame(uds, services.getUserDetailsService());
assertThat(services.getTokenValiditySeconds()).isEqualTo(600);
assertThat(services.getUserDetailsService()).isSameAs(uds);
AuthenticationDetailsSource ads = mock(AuthenticationDetailsSource.class);
services.setAuthenticationDetailsSource(ads);
assertSame(ads, services.getAuthenticationDetailsSource());
assertThat(services.getAuthenticationDetailsSource()).isSameAs(ads);
services.afterPropertiesSet();
}
@@ -84,14 +84,14 @@ public class AbstractRememberMeServicesTests {
String encoded = services.encodeCookie(cookie);
// '=' aren't allowed in version 0 cookies.
assertFalse(encoded.endsWith("="));
assertThat(encoded.endsWith("=")).isFalse();
String[] decoded = services.decodeCookie(encoded);
assertEquals(4, decoded.length);
assertEquals("name", decoded[0]);
assertEquals("cookie", decoded[1]);
assertEquals("tokens", decoded[2]);
assertEquals("blah", decoded[3]);
assertThat(decoded.length).isEqualTo(4);
assertThat(decoded[0]).isEqualTo("name");
assertThat(decoded[1]).isEqualTo("cookie");
assertThat(decoded[2]).isEqualTo("tokens");
assertThat(decoded[3]).isEqualTo("blah");
}
@Test
@@ -101,14 +101,14 @@ public class AbstractRememberMeServicesTests {
MockRememberMeServices services = new MockRememberMeServices(uds);
String[] decoded = services.decodeCookie(services.encodeCookie(cookie));
assertEquals(4, decoded.length);
assertEquals("http://id.openid.zz", decoded[0]);
assertThat(decoded.length).isEqualTo(4);
assertThat(decoded[0]).isEqualTo("http://id.openid.zz");
// Check https (SEC-1410)
cookie[0] = "https://id.openid.zz";
decoded = services.decodeCookie(services.encodeCookie(cookie));
assertEquals(4, decoded.length);
assertEquals("https://id.openid.zz", decoded[0]);
assertThat(decoded.length).isEqualTo(4);
assertThat(decoded[0]).isEqualTo("https://id.openid.zz");
}
@Test
@@ -117,7 +117,7 @@ public class AbstractRememberMeServicesTests {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
// shouldn't try to invalidate our cookie
assertNull(response
@@ -127,7 +127,7 @@ public class AbstractRememberMeServicesTests {
response = new MockHttpServletResponse();
// set non-login cookie
request.setCookies(new Cookie("mycookie", "cookie"));
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
assertNull(response
.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY));
}
@@ -136,7 +136,7 @@ public class AbstractRememberMeServicesTests {
public void successfulAutoLoginReturnsExpectedAuthentication() throws Exception {
MockRememberMeServices services = new MockRememberMeServices(uds);
services.afterPropertiesSet();
assertNotNull(services.getUserDetailsService());
assertThat(services.getUserDetailsService()).isNotNull();
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -145,7 +145,7 @@ public class AbstractRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNotNull(result);
assertThat(result).isNotNull();
}
@Test
@@ -157,7 +157,7 @@ public class AbstractRememberMeServicesTests {
request.setCookies(new Cookie(
AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, "ZZZ"));
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertThat(result).isNull();
assertCookieCancelled(response);
}
@@ -170,7 +170,7 @@ public class AbstractRememberMeServicesTests {
request.setCookies(new Cookie(
AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, ""));
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertThat(result).isNull();
assertCookieCancelled(response);
}
@@ -186,7 +186,7 @@ public class AbstractRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertThat(result).isNull();
assertCookieCancelled(response);
}
@@ -202,7 +202,7 @@ public class AbstractRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertThat(result).isNull();
assertCookieCancelled(response);
}
@@ -220,7 +220,7 @@ public class AbstractRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertThat(result).isNull();
assertCookieCancelled(response);
}
@@ -284,32 +284,32 @@ public class AbstractRememberMeServicesTests {
// No parameter set
services.loginSuccess(request, response, auth);
assertFalse(services.loginSuccessCalled);
assertThat(services.loginSuccessCalled).isFalse();
// Parameter set to true
services = new MockRememberMeServices(uds);
request.setParameter(MockRememberMeServices.DEFAULT_PARAMETER, "true");
services.loginSuccess(request, response, auth);
assertTrue(services.loginSuccessCalled);
assertThat(services.loginSuccessCalled).isTrue();
// Different parameter name, set to true
services = new MockRememberMeServices(uds);
services.setParameter("my_parameter");
request.setParameter("my_parameter", "true");
services.loginSuccess(request, response, auth);
assertTrue(services.loginSuccessCalled);
assertThat(services.loginSuccessCalled).isTrue();
// Parameter set to false
services = new MockRememberMeServices(uds);
request.setParameter(MockRememberMeServices.DEFAULT_PARAMETER, "false");
services.loginSuccess(request, response, auth);
assertFalse(services.loginSuccessCalled);
assertThat(services.loginSuccessCalled).isFalse();
// alwaysRemember set to true
services = new MockRememberMeServices(uds);
services.setAlwaysRemember(true);
services.loginSuccess(request, response, auth);
assertTrue(services.loginSuccessCalled);
assertThat(services.loginSuccessCalled).isTrue();
}
@Test
@@ -326,11 +326,11 @@ public class AbstractRememberMeServicesTests {
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
Cookie cookie = response.getCookie("mycookiename");
assertNotNull(cookie);
assertEquals("mycookie", cookie.getValue());
assertEquals("mycookiename", cookie.getName());
assertEquals("contextpath", cookie.getPath());
assertFalse(cookie.getSecure());
assertThat(cookie).isNotNull();
assertThat(cookie.getValue()).isEqualTo("mycookie");
assertThat(cookie.getName()).isEqualTo("mycookiename");
assertThat(cookie.getPath()).isEqualTo("contextpath");
assertThat(cookie.getSecure()).isFalse();
}
@Test
@@ -348,7 +348,7 @@ public class AbstractRememberMeServicesTests {
services.setCookie(new String[] { "mycookie" }, 1000, request, response);
Cookie cookie = response
.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertTrue(cookie.getSecure());
assertThat(cookie.getSecure()).isTrue();
}
@Test
@@ -358,11 +358,11 @@ public class AbstractRememberMeServicesTests {
.thenReturn(null);
MockRememberMeServices services = new MockRememberMeServices(uds);
assertNull(ReflectionTestUtils.getField(services, "setHttpOnlyMethod"));
assertThat(ReflectionTestUtils.getField(services, "setHttpOnlyMethod")).isNull();
services = new MockRememberMeServices("key", new MockUserDetailsService(joe,
false));
assertNull(ReflectionTestUtils.getField(services, "setHttpOnlyMethod"));
assertThat(ReflectionTestUtils.getField(services, "setHttpOnlyMethod")).isNull();
}
// SEC-2791
@@ -420,8 +420,8 @@ public class AbstractRememberMeServicesTests {
private void assertCookieCancelled(MockHttpServletResponse response) {
Cookie returnedCookie = response
.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
// ~ Inner Classes

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.authentication.rememberme;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
@@ -90,10 +90,10 @@ public class JdbcTokenRepositoryImplTests {
Map<String, Object> results = template
.queryForMap("select * from persistent_logins");
assertEquals(currentDate, results.get("last_used"));
assertEquals("joeuser", results.get("username"));
assertEquals("joesseries", results.get("series"));
assertEquals("atoken", results.get("token"));
assertThat(results.get("last_used")).isEqualTo(currentDate);
assertThat(results.get("username")).isEqualTo("joeuser");
assertThat(results.get("series")).isEqualTo("joesseries");
assertThat(results.get("token")).isEqualTo("atoken");
}
@Test
@@ -103,10 +103,10 @@ public class JdbcTokenRepositoryImplTests {
+ "('joesseries', 'joeuser', 'atoken', '2007-10-09 18:19:25.000000000')");
PersistentRememberMeToken token = repo.getTokenForSeries("joesseries");
assertEquals("joeuser", token.getUsername());
assertEquals("joesseries", token.getSeries());
assertEquals("atoken", token.getTokenValue());
assertEquals(Timestamp.valueOf("2007-10-09 18:19:25.000000000"), token.getDate());
assertThat(token.getUsername()).isEqualTo("joeuser");
assertThat(token.getSeries()).isEqualTo("joesseries");
assertThat(token.getTokenValue()).isEqualTo("atoken");
assertThat(token.getDate()).isEqualTo(Timestamp.valueOf("2007-10-09 18:19:25.000000000"));
}
@Test
@@ -119,7 +119,7 @@ public class JdbcTokenRepositoryImplTests {
// List results =
// template.queryForList("select * from persistent_logins where series = 'joesseries'");
assertNull(repo.getTokenForSeries("joesseries"));
assertThat(repo.getTokenForSeries("joesseries")).isNull();
}
// SEC-1964
@@ -127,7 +127,7 @@ public class JdbcTokenRepositoryImplTests {
public void retrievingTokenWithNoSeriesReturnsNull() {
when(logger.isDebugEnabled()).thenReturn(true);
assertNull(repo.getTokenForSeries("missingSeries"));
assertThat(repo.getTokenForSeries("missingSeries")).isNull();
verify(logger).isDebugEnabled();
verify(logger).debug(
@@ -151,7 +151,7 @@ public class JdbcTokenRepositoryImplTests {
List<Map<String, Object>> results = template
.queryForList("select * from persistent_logins where username = 'joeuser'");
assertEquals(0, results.size());
assertThat(results).isEmpty();
}
@Test
@@ -164,11 +164,11 @@ public class JdbcTokenRepositoryImplTests {
Map<String, Object> results = template
.queryForMap("select * from persistent_logins where series = 'joesseries'");
assertEquals("joeuser", results.get("username"));
assertEquals("joesseries", results.get("series"));
assertEquals("newtoken", results.get("token"));
assertThat(results.get("username")).isEqualTo("joeuser");
assertThat(results.get("series")).isEqualTo("joesseries");
assertThat(results.get("token")).isEqualTo("newtoken");
Date lastUsed = (Date) results.get("last_used");
assertTrue(lastUsed.getTime() > ts.getTime());
assertThat(lastUsed.getTime() > ts.getTime()).isTrue();
}
@Test

View File

@@ -30,9 +30,9 @@ public class NullRememberMeServicesTests extends TestCase {
public void testAlwaysReturnsNull() {
NullRememberMeServices services = new NullRememberMeServices();
assertNull(services.autoLogin(null, null));
assertThat(services.autoLogin(null, null)).isNull();
services.loginFail(null, null);
services.loginSuccess(null, null, null);
assertTrue(true);
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.authentication.rememberme;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@@ -81,12 +81,12 @@ public class PersistentTokenBasedRememberMeServicesTests {
MockHttpServletResponse response = new MockHttpServletResponse();
services.processAutoLoginCookie(new String[] { "series", "token" },
new MockHttpServletRequest(), response);
assertEquals("series", repo.getStoredToken().getSeries());
assertEquals(16, repo.getStoredToken().getTokenValue().length());
assertThat(repo.getStoredToken().getSeries()).isEqualTo("series");
assertThat(repo.getStoredToken().getTokenValue().length()).isEqualTo(16);
String[] cookie = services.decodeCookie(response.getCookie("mycookiename")
.getValue());
assertEquals("series", cookie[0]);
assertEquals(repo.getStoredToken().getTokenValue(), cookie[1]);
assertThat(cookie[0]).isEqualTo("series");
assertThat(cookie[1]).isEqualTo(repo.getStoredToken().getTokenValue());
}
@Test
@@ -98,14 +98,14 @@ public class PersistentTokenBasedRememberMeServicesTests {
MockHttpServletResponse response = new MockHttpServletResponse();
services.loginSuccess(new MockHttpServletRequest(), response,
new UsernamePasswordAuthenticationToken("joe", "password"));
assertEquals(16, repo.getStoredToken().getSeries().length());
assertEquals(16, repo.getStoredToken().getTokenValue().length());
assertThat(repo.getStoredToken().getSeries().length()).isEqualTo(16);
assertThat(repo.getStoredToken().getTokenValue().length()).isEqualTo(16);
String[] cookie = services.decodeCookie(response.getCookie("mycookiename")
.getValue());
assertEquals(repo.getStoredToken().getSeries(), cookie[0]);
assertEquals(repo.getStoredToken().getTokenValue(), cookie[1]);
assertThat(cookie[0]).isEqualTo(repo.getStoredToken().getSeries());
assertThat(cookie[1]).isEqualTo(repo.getStoredToken().getTokenValue());
}
@Test
@@ -119,8 +119,8 @@ public class PersistentTokenBasedRememberMeServicesTests {
services.logout(request, response, new TestingAuthenticationToken("joe",
"somepass", "SOME_AUTH"));
Cookie returnedCookie = response.getCookie("mycookiename");
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
// SEC-1280
services.logout(request, response, null);

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication.rememberme;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
@@ -88,7 +88,7 @@ public class RememberMeAuthenticationFilterTests {
filter.doFilter(request, new MockHttpServletResponse(), fc);
// Ensure filter didn't change our original object
assertSame(originalAuth, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(originalAuth);
verify(fc)
.doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
@@ -108,7 +108,7 @@ public class RememberMeAuthenticationFilterTests {
filter.doFilter(request, new MockHttpServletResponse(), fc);
// Ensure filter setup with our remembered authentication object
assertSame(remembered, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(remembered);
verify(fc)
.doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
@@ -136,7 +136,7 @@ public class RememberMeAuthenticationFilterTests {
request.setRequestURI("x");
filter.doFilter(request, new MockHttpServletResponse(), fc);
assertSame(failedAuth, SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(failedAuth);
verify(fc)
.doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
@@ -156,7 +156,7 @@ public class RememberMeAuthenticationFilterTests {
request.setRequestURI("x");
filter.doFilter(request, response, fc);
assertEquals("/target", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/target");
// Should return after success handler is invoked, so chain should not proceed
verifyZeroInteractions(fc);

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication.rememberme;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices.*;
@@ -103,9 +103,9 @@ public class TokenBasedRememberMeServicesTests {
Authentication result = services
.autoLogin(new MockHttpServletRequest(), response);
assertNull(result);
assertThat(result).isNull();
// No cookie set
assertNull(response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY));
assertThat(response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY)).isNull();
}
@Test
@@ -117,8 +117,8 @@ public class TokenBasedRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNull(result);
assertNull(response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY));
assertThat(result).isNull();
assertThat(response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY)).isNull();
}
@Test
@@ -132,11 +132,11 @@ public class TokenBasedRememberMeServicesTests {
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -148,12 +148,12 @@ public class TokenBasedRememberMeServicesTests {
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -164,12 +164,12 @@ public class TokenBasedRememberMeServicesTests {
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -185,12 +185,12 @@ public class TokenBasedRememberMeServicesTests {
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -202,12 +202,12 @@ public class TokenBasedRememberMeServicesTests {
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -222,12 +222,12 @@ public class TokenBasedRememberMeServicesTests {
MockHttpServletResponse response = new MockHttpServletResponse();
assertNull(services.autoLogin(request, response));
assertThat(services.autoLogin(request, response)).isNull();
Cookie returnedCookie = response
.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(returnedCookie);
assertEquals(0, returnedCookie.getMaxAge());
assertThat(returnedCookie).isNotNull();
assertThat(returnedCookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -244,22 +244,22 @@ public class TokenBasedRememberMeServicesTests {
Authentication result = services.autoLogin(request, response);
assertNotNull(result);
assertEquals(user, result.getPrincipal());
assertThat(result).isNotNull();
assertThat(result.getPrincipal()).isEqualTo(user);
}
@Test
public void testGettersSetters() {
assertEquals(uds, services.getUserDetailsService());
assertThat(services.getUserDetailsService()).isEqualTo(uds);
assertEquals("key", services.getKey());
assertThat(services.getKey()).isEqualTo("key");
assertEquals(DEFAULT_PARAMETER, services.getParameter());
assertThat(services.getParameter()).isEqualTo(DEFAULT_PARAMETER);
services.setParameter("some_param");
assertEquals("some_param", services.getParameter());
assertThat(services.getParameter()).isEqualTo("some_param");
services.setTokenValiditySeconds(12);
assertEquals(12, services.getTokenValiditySeconds());
assertThat(services.getTokenValiditySeconds()).isEqualTo(12);
}
@Test
@@ -269,8 +269,8 @@ public class TokenBasedRememberMeServicesTests {
services.loginFail(request, response);
Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(cookie);
assertEquals(0, cookie.getMaxAge());
assertThat(cookie).isNotNull();
assertThat(cookie.getMaxAge()).isEqualTo(0);
}
@Test
@@ -285,7 +285,7 @@ public class TokenBasedRememberMeServicesTests {
"someone", "password", "ROLE_ABC"));
Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNull(cookie);
assertThat(cookie).isNull();
}
@Test
@@ -303,11 +303,11 @@ public class TokenBasedRememberMeServicesTests {
String expiryTime = services.decodeCookie(cookie.getValue())[1];
long expectedExpiryTime = 1000L * 500000000;
expectedExpiryTime += System.currentTimeMillis();
assertTrue(Long.parseLong(expiryTime) > expectedExpiryTime - 10000);
assertNotNull(cookie);
assertEquals(services.getTokenValiditySeconds(), cookie.getMaxAge());
assertTrue(Base64.isArrayByteBase64(cookie.getValue().getBytes()));
assertTrue(new Date().before(new Date(
assertThat(Long.parseLong(expiryTime) > expectedExpiryTime - 10000).isTrue();
assertThat(cookie).isNotNull();
assertThat(cookie.getMaxAge()).isEqualTo(services.getTokenValiditySeconds());
assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
assertThat(new Date().isTrue().before(new Date(
determineExpiryTimeFromBased64EncodedToken(cookie.getValue()))));
}
@@ -321,10 +321,10 @@ public class TokenBasedRememberMeServicesTests {
"someone", "password", "ROLE_ABC"));
Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(cookie);
assertEquals(services.getTokenValiditySeconds(), cookie.getMaxAge());
assertTrue(Base64.isArrayByteBase64(cookie.getValue().getBytes()));
assertTrue(new Date().before(new Date(
assertThat(cookie).isNotNull();
assertThat(cookie.getMaxAge()).isEqualTo(services.getTokenValiditySeconds());
assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
assertThat(new Date().isTrue().before(new Date(
determineExpiryTimeFromBased64EncodedToken(cookie.getValue()))));
}
@@ -333,7 +333,7 @@ public class TokenBasedRememberMeServicesTests {
public void obtainPasswordReturnsNullForTokenWithNullCredentials() throws Exception {
TestingAuthenticationToken token = new TestingAuthenticationToken("username",
null);
assertNull(services.retrievePassword(token));
assertThat(services.retrievePassword(token)).isNull();
}
// SEC-949
@@ -349,11 +349,11 @@ public class TokenBasedRememberMeServicesTests {
"someone", "password", "ROLE_ABC"));
Cookie cookie = response.getCookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
assertNotNull(cookie);
assertThat(cookie).isNotNull();
// Check the expiry time is within 50ms of two weeks from current time
assertTrue(determineExpiryTimeFromBased64EncodedToken(cookie.getValue())
assertThat(determineExpiryTimeFromBased64EncodedToken(cookie.getValue()).isTrue()
- System.currentTimeMillis() > TWO_WEEKS_S - 50);
assertEquals(-1, cookie.getMaxAge());
assertTrue(Base64.isArrayByteBase64(cookie.getValue().getBytes()));
assertThat(cookie.getMaxAge()).isEqualTo(-1);
assertThat(Base64.isArrayByteBase64(cookie.getValue().getBytes())).isTrue();
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.security.web.authentication.session;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.when;

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication.switchuser;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.*;
@@ -108,7 +108,7 @@ public class SwitchUserFilterTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/j_spring_security_my_exit_user");
assertTrue(filter.requiresExitUser(request));
assertThat(filter.requiresExitUser(request)).isTrue();
}
@Test
@@ -119,7 +119,7 @@ public class SwitchUserFilterTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/j_spring_security_my_switch_user");
assertTrue(filter.requiresSwitchUser(request));
assertThat(filter.requiresSwitchUser(request)).isTrue();
}
@Test(expected = UsernameNotFoundException.class)
@@ -156,7 +156,7 @@ public class SwitchUserFilterTests {
@Test
public void attemptSwitchUserIsSuccessfulWithValidUser() throws Exception {
assertNotNull(switchToUser("jacklord"));
assertThat(switchToUser("jacklord")).isNotNull();
}
@Test
@@ -176,7 +176,7 @@ public class SwitchUserFilterTests {
filter.doFilter(request, response, chain);
verify(chain, never()).doFilter(request, response);
assertNotNull(response.getErrorMessage());
assertThat(response.getErrorMessage()).isNotNull();
// Now check for the redirect
request.setContextPath("/mywebapp");
@@ -192,8 +192,8 @@ public class SwitchUserFilterTests {
filter.doFilter(request, response, chain);
verify(chain, never()).doFilter(request, response);
assertEquals("/mywebapp/switchfailed", response.getRedirectedUrl());
assertEquals("/switchfailed",
assertThat(response.getRedirectedUrl()).isEqualTo("/mywebapp/switchfailed");
assertThat("/switchfailed").isEqualTo(
FieldUtils.getFieldValue(filter, "switchFailureUrl"));
}
@@ -222,7 +222,7 @@ public class SwitchUserFilterTests {
filter.setSwitchUserUrl("/login/impersonate");
request.setRequestURI("/webapp/login/impersonate;jsessionid=8JHDUD723J8");
assertTrue(filter.requiresSwitchUser(request));
assertThat(filter.requiresSwitchUser(request)).isTrue();
}
@Test
@@ -260,8 +260,8 @@ public class SwitchUserFilterTests {
// check current user, should be back to original user (dano)
Authentication targetAuth = SecurityContextHolder.getContext()
.getAuthentication();
assertNotNull(targetAuth);
assertEquals("dano", targetAuth.getPrincipal());
assertThat(targetAuth).isNotNull();
assertThat(targetAuth.getPrincipal()).isEqualTo("dano");
}
@Test(expected = AuthenticationException.class)
@@ -305,7 +305,7 @@ public class SwitchUserFilterTests {
verify(chain, never()).doFilter(request, response);
assertEquals("/webapp/someOtherUrl", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/webapp/someOtherUrl");
}
@Test
@@ -338,7 +338,7 @@ public class SwitchUserFilterTests {
verify(chain, never()).doFilter(request, response);
assertEquals("/someOtherUrl", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/someOtherUrl");
}
@Test
@@ -373,9 +373,9 @@ public class SwitchUserFilterTests {
// check current user
Authentication targetAuth = SecurityContextHolder.getContext()
.getAuthentication();
assertNotNull(targetAuth);
assertTrue(targetAuth.getPrincipal() instanceof UserDetails);
assertEquals("jacklord", ((User) targetAuth.getPrincipal()).getUsername());
assertThat(targetAuth).isNotNull();
assertThat(targetAuth.getPrincipal() instanceof UserDetails).isTrue();
assertThat(((User) targetAuth.getPrincipal()).getUsername()).isEqualTo("jacklord");
}
@Test
@@ -401,9 +401,9 @@ public class SwitchUserFilterTests {
});
Authentication result = filter.attemptSwitchUser(request);
assertTrue(result != null);
assertEquals(2, result.getAuthorities().size());
assertTrue(AuthorityUtils.authorityListToSet(result.getAuthorities()).contains(
assertThat(result != null).isTrue();
assertThat(result.getAuthorities()).hasSize(2);
assertThat(AuthorityUtils.authorityListToSet(result.getAuthorities()).contains(
"ROLE_NEW"));
}
@@ -426,8 +426,8 @@ public class SwitchUserFilterTests {
}
}
assertNotNull(switchedFrom);
assertSame(source, switchedFrom.getSource());
assertThat(switchedFrom).isNotNull();
assertThat(source).isSameAs(switchedFrom.getSource());
}
// gh-3697
@@ -459,9 +459,9 @@ public class SwitchUserFilterTests {
}
}
assertNotNull(switchedFrom);
assertSame(source, switchedFrom.getSource());
assertEquals(switchAuthorityRole, switchedFrom.getAuthority());
assertThat(switchedFrom).isNotNull();
assertThat(switchedFrom.getSource()).isSameAs(source);
assertThat(switchAuthorityRole).isEqualTo(switchedFrom.getAuthority());
}
// ~ Inner Classes

View File

@@ -58,14 +58,14 @@ public class BasicAuthenticationEntryPointTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("realmName must be specified", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("realmName must be specified");
}
}
public void testGettersSetters() {
BasicAuthenticationEntryPoint ep = new BasicAuthenticationEntryPoint();
ep.setRealmName("realm");
assertEquals("realm", ep.getRealmName());
assertThat(ep.getRealmName()).isEqualTo("realm");
}
public void testNormalOperation() throws Exception {
@@ -83,9 +83,9 @@ public class BasicAuthenticationEntryPointTests extends TestCase {
String msg = "These are the jokes kid";
ep.commence(request, response, new DisabledException(msg));
assertEquals(401, response.getStatus());
assertEquals(msg, response.getErrorMessage());
assertThat(response.getStatus()).isEqualTo(401);
assertThat(response.getErrorMessage()).isEqualTo(msg);
assertEquals("Basic realm=\"hello\"", response.getHeader("WWW-Authenticate"));
assertThat(response.getHeader("WWW-Authenticate")).isEqualTo("Basic realm=\"hello\"");
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.authentication.www;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.AdditionalMatchers.not;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

View File

@@ -40,18 +40,18 @@ public class DigestAuthUtilsTests extends TestCase {
Map<String, String> headerMap = DigestAuthUtils
.splitEachArrayElementAndCreateMap(headerEntries, "=", "\"");
assertEquals("rod", headerMap.get("username"));
assertEquals("Contacts Realm", headerMap.get("realm"));
assertThat(headerMap.get("username")).isEqualTo("rod");
assertThat(headerMap.get("realm")).isEqualTo("Contacts Realm");
assertEquals("MTEwOTAyMzU1MTQ4NDo1YzY3OWViYWM5NDNmZWUwM2UwY2NmMDBiNDQzMTQ0OQ==",
headerMap.get("nonce"));
assertEquals(
"/spring-security-sample-contacts-filter/secure/adminPermission.htm?contactId=4",
headerMap.get("uri"));
assertEquals("38644211cf9ac3da63ab639807e2baff", headerMap.get("response"));
assertEquals("auth", headerMap.get("qop"));
assertEquals("00000004", headerMap.get("nc"));
assertEquals("2b8d329a8571b99a", headerMap.get("cnonce"));
assertEquals(8, headerMap.size());
assertThat(headerMap.get("response")).isEqualTo("38644211cf9ac3da63ab639807e2baff");
assertThat(headerMap.get("qop")).isEqualTo("auth");
assertThat(headerMap.get("nc")).isEqualTo("00000004");
assertThat(headerMap.get("cnonce")).isEqualTo("2b8d329a8571b99a");
assertThat(headerMap).hasSize(8);
}
public void testSplitEachArrayElementAndCreateMapRespectsInstructionNotToRemoveCharacters() {
@@ -60,31 +60,31 @@ public class DigestAuthUtilsTests extends TestCase {
Map<String, String> headerMap = DigestAuthUtils
.splitEachArrayElementAndCreateMap(headerEntries, "=", null);
assertEquals("\"rod\"", headerMap.get("username"));
assertEquals("\"Contacts Realm\"", headerMap.get("realm"));
assertThat(headerMap.get("username")).isEqualTo("\"rod\"");
assertThat(headerMap.get("realm")).isEqualTo("\"Contacts Realm\"");
assertEquals(
"\"MTEwOTAyMzU1MTQ4NDo1YzY3OWViYWM5NDNmZWUwM2UwY2NmMDBiNDQzMTQ0OQ==\"",
headerMap.get("nonce"));
assertEquals(
"\"/spring-security-sample-contacts-filter/secure/adminPermission.htm?contactId=4\"",
headerMap.get("uri"));
assertEquals("\"38644211cf9ac3da63ab639807e2baff\"", headerMap.get("response"));
assertEquals("auth", headerMap.get("qop"));
assertEquals("00000004", headerMap.get("nc"));
assertEquals("\"2b8d329a8571b99a\"", headerMap.get("cnonce"));
assertEquals(8, headerMap.size());
assertThat(headerMap.get("response")).isEqualTo("\"38644211cf9ac3da63ab639807e2baff\"");
assertThat(headerMap.get("qop")).isEqualTo("auth");
assertThat(headerMap.get("nc")).isEqualTo("00000004");
assertThat(headerMap.get("cnonce")).isEqualTo("\"2b8d329a8571b99a\"");
assertThat(headerMap).hasSize(8);
}
public void testSplitEachArrayElementAndCreateMapReturnsNullIfArrayEmptyOrNull() {
assertNull(DigestAuthUtils.splitEachArrayElementAndCreateMap(null, "=", "\""));
assertThat(DigestAuthUtils.splitEachArrayElementAndCreateMap(null, "=", "\"")).isNull();
assertNull(DigestAuthUtils.splitEachArrayElementAndCreateMap(new String[] {},
"=", "\""));
}
public void testSplitNormalOperation() {
String unsplit = "username=\"rod==\"";
assertEquals("username", DigestAuthUtils.split(unsplit, "=")[0]);
assertEquals("\"rod==\"", DigestAuthUtils.split(unsplit, "=")[1]); // should not
assertThat("=")[0]).as("username").isEqualTo(DigestAuthUtils.split(unsplit);
assertThat("=")[1]).as("\"rod==\"").isEqualTo(DigestAuthUtils.split(unsplit); // should not
// remove
// quotes or
// extra
@@ -97,7 +97,7 @@ public class DigestAuthUtilsTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
@@ -105,7 +105,7 @@ public class DigestAuthUtilsTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
@@ -113,7 +113,7 @@ public class DigestAuthUtilsTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
@@ -121,7 +121,7 @@ public class DigestAuthUtilsTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
@@ -129,16 +129,16 @@ public class DigestAuthUtilsTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testSplitWorksWithDifferentDelimiters() {
assertEquals(2, DigestAuthUtils.split("18/rod", "/").length);
assertNull(DigestAuthUtils.split("18/rod", "!"));
assertThat("/").length).isEqualTo(2, DigestAuthUtils.split("18/rod");
assertThat(DigestAuthUtils.split("18/rod", "!")).isNull();
// only guarantees to split at FIRST delimiter, not EACH delimiter
assertEquals(2, DigestAuthUtils.split("18|rod|foo|bar", "|").length);
assertThat("|").length).isEqualTo(2, DigestAuthUtils.split("18|rod|foo|bar");
}
public void testAuthorizationHeaderWithCommasIsSplitCorrectly() {
@@ -147,6 +147,6 @@ public class DigestAuthUtilsTests extends TestCase {
String[] parts = DigestAuthUtils.splitIgnoringQuotes(header, ',');
assertEquals(8, parts.length);
assertThat(parts.length).isEqualTo(8);
}
}

View File

@@ -39,14 +39,14 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
// Check the nonce seems to be generated correctly
// format of nonce is:
// base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
assertTrue(Base64.isArrayByteBase64(nonce.getBytes()));
assertThat(Base64.isArrayByteBase64(nonce.getBytes())).isTrue();
String decodedNonce = new String(Base64.decodeBase64(nonce.getBytes()));
String[] nonceTokens = StringUtils.delimitedListToStringArray(decodedNonce, ":");
assertEquals(2, nonceTokens.length);
assertThat(nonceTokens.length).isEqualTo(2);
String expectedNonceSignature = DigestUtils.md5Hex(nonceTokens[0] + ":" + "key");
assertEquals(expectedNonceSignature, nonceTokens[1]);
assertThat(nonceTokens[1]).isEqualTo(expectedNonceSignature);
}
public void testDetectsMissingKey() throws Exception {
@@ -58,7 +58,7 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("key must be specified", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("key must be specified");
}
}
@@ -72,19 +72,19 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
assertEquals("realmName must be specified", expected.getMessage());
assertThat(expected.getMessage()).isEqualTo("realmName must be specified");
}
}
public void testGettersSetters() {
DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint();
assertEquals(300, ep.getNonceValiditySeconds()); // 5 mins default
assertThat(ep.getNonceValiditySeconds()).isEqualTo(300); // 5 mins default
ep.setRealmName("realm");
assertEquals("realm", ep.getRealmName());
assertThat(ep.getRealmName()).isEqualTo("realm");
ep.setKey("dcdc");
assertEquals("dcdc", ep.getKey());
assertThat(ep.getKey()).isEqualTo("dcdc");
ep.setNonceValiditySeconds(12);
assertEquals(12, ep.getNonceValiditySeconds());
assertThat(ep.getNonceValiditySeconds()).isEqualTo(12);
}
public void testNormalOperation() throws Exception {
@@ -102,7 +102,7 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
ep.commence(request, response, new DisabledException("foobar"));
// Check response is properly formed
assertEquals(401, response.getStatus());
assertThat(response.getStatus()).isEqualTo(401);
assertEquals(true,
response.getHeader("WWW-Authenticate").toString().startsWith("Digest "));
@@ -112,9 +112,9 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
Map<String, String> headerMap = DigestAuthUtils
.splitEachArrayElementAndCreateMap(headerEntries, "=", "\"");
assertEquals("hello", headerMap.get("realm"));
assertEquals("auth", headerMap.get("qop"));
assertNull(headerMap.get("stale"));
assertThat(headerMap.get("realm")).isEqualTo("hello");
assertThat(headerMap.get("qop")).isEqualTo("auth");
assertThat(headerMap.get("stale")).isNull();
checkNonceValid((String) headerMap.get("nonce"));
}
@@ -134,8 +134,8 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
ep.commence(request, response, new NonceExpiredException("expired nonce"));
// Check response is properly formed
assertEquals(401, response.getStatus());
assertTrue(response.getHeader("WWW-Authenticate").toString()
assertThat(response.getStatus()).isEqualTo(401);
assertThat(response.getHeader("WWW-Authenticate").toString().isTrue()
.startsWith("Digest "));
// Break up response header
@@ -144,9 +144,9 @@ public class DigestAuthenticationEntryPointTests extends TestCase {
Map<String, String> headerMap = DigestAuthUtils
.splitEachArrayElementAndCreateMap(headerEntries, "=", "\"");
assertEquals("hello", headerMap.get("realm"));
assertEquals("auth", headerMap.get("qop"));
assertEquals("true", headerMap.get("stale"));
assertThat(headerMap.get("realm")).isEqualTo("hello");
assertThat(headerMap.get("qop")).isEqualTo("auth");
assertThat(headerMap.get("stale")).isEqualTo("true");
checkNonceValid((String) headerMap.get("nonce"));
}

View File

@@ -15,9 +15,9 @@
package org.springframework.security.web.authentication.www;
import static org.fest.assertions.Assertions.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -160,14 +160,14 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
String header = response.getHeader("WWW-Authenticate").toString().substring(7);
String[] headerEntries = StringUtils.commaDelimitedListToStringArray(header);
Map<String, String> headerMap = DigestAuthUtils
.splitEachArrayElementAndCreateMap(headerEntries, "=", "\"");
assertEquals("true", headerMap.get("stale"));
assertThat(headerMap.get("stale")).isEqualTo("true");
}
@Test
@@ -175,22 +175,22 @@ public class DigestAuthenticationFilterTests {
throws Exception {
executeFilterInContainerSimulator(filter, request, true);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
public void testGettersSetters() {
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
filter.setUserDetailsService(mock(UserDetailsService.class));
assertTrue(filter.getUserDetailsService() != null);
assertThat(filter.getUserDetailsService() != null).isTrue();
filter.setAuthenticationEntryPoint(new DigestAuthenticationEntryPoint());
assertTrue(filter.getAuthenticationEntryPoint() != null);
assertThat(filter.getAuthenticationEntryPoint() != null).isTrue();
filter.setUserCache(null);
assertNull(filter.getUserCache());
assertThat(filter.getUserCache()).isNull();
filter.setUserCache(new NullUserCache());
assertNotNull(filter.getUserCache());
assertThat(filter.getUserCache()).isNotNull();
}
@Test
@@ -203,8 +203,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertEquals(401, response.getStatus());
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(response.getStatus()).isEqualTo(401);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -214,8 +214,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -233,8 +233,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -253,8 +253,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -272,8 +272,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -292,8 +292,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -310,8 +310,8 @@ public class DigestAuthenticationFilterTests {
executeFilterInContainerSimulator(filter, request, true);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(USERNAME, ((UserDetails) SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(((UserDetails) SecurityContextHolder.getContext().isEqualTo(USERNAME)
.getAuthentication().getPrincipal()).getUsername());
}
@@ -327,10 +327,10 @@ public class DigestAuthenticationFilterTests {
executeFilterInContainerSimulator(filter, request, true);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(USERNAME, ((UserDetails) SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(((UserDetails) SecurityContextHolder.getContext().isEqualTo(USERNAME)
.getAuthentication().getPrincipal()).getUsername());
assertFalse(SecurityContextHolder.getContext().getAuthentication()
assertThat(SecurityContextHolder.getContext().getAuthentication().isFalse()
.isAuthenticated());
}
@@ -348,12 +348,12 @@ public class DigestAuthenticationFilterTests {
filter.setCreateAuthenticatedToken(true);
executeFilterInContainerSimulator(filter, request, true);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(USERNAME, ((UserDetails) SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
assertThat(((UserDetails) SecurityContextHolder.getContext().isEqualTo(USERNAME)
.getAuthentication().getPrincipal()).getUsername());
assertTrue(SecurityContextHolder.getContext().getAuthentication()
assertThat(SecurityContextHolder.getContext().getAuthentication().isTrue()
.isAuthenticated());
assertEquals(AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"),
assertThat("ROLE_TWO").isEqualTo(AuthorityUtils.createAuthorityList("ROLE_ONE"),
SecurityContextHolder.getContext().getAuthentication().getAuthorities());
}
@@ -363,7 +363,7 @@ public class DigestAuthenticationFilterTests {
executeFilterInContainerSimulator(filter, request, true);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test(expected = IllegalArgumentException.class)
@@ -393,7 +393,7 @@ public class DigestAuthenticationFilterTests {
executeFilterInContainerSimulator(filter, request, true);
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
// Now retry, giving an invalid nonce
responseDigest = DigestAuthUtils.generateDigest(false, USERNAME, REALM,
@@ -409,8 +409,8 @@ public class DigestAuthenticationFilterTests {
request, false);
// Check we lost our previous authentication
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -428,8 +428,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -446,8 +446,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -464,8 +464,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
@Test
@@ -481,8 +481,8 @@ public class DigestAuthenticationFilterTests {
MockHttpServletResponse response = executeFilterInContainerSimulator(filter,
request, false);
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertEquals(401, response.getStatus());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
assertThat(response.getStatus()).isEqualTo(401);
}
// SEC-3108

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.bind.support;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.concurrent;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Date;
@@ -66,7 +66,7 @@ public class ConcurrentSessionFilterTests {
// Expect that the filter chain will not be invoked, as we redirect to expiredUrl
verifyZeroInteractions(fc);
assertEquals("/expired.jsp", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/expired.jsp");
}
// As above, but with no expiredUrl set.
@@ -126,7 +126,7 @@ public class ConcurrentSessionFilterTests {
filter.doFilter(request, response, fc);
verify(fc).doFilter(request, response);
assertTrue(registry.getSessionInformation(session.getId()).getLastRequest()
assertThat(registry.getSessionInformation(session.getId()).getLastRequest().isTrue()
.after(lastRequest));
}
}

View File

@@ -12,8 +12,8 @@
*/
package org.springframework.security.web.context;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@@ -119,9 +119,9 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
response);
SecurityContext context = repo.loadContext(holder);
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
repo.saveContext(context, holder.getRequest(), holder.getResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
@Test
@@ -136,7 +136,7 @@ public class HttpSessionSecurityContextRepositoryTests {
// Change context
context.setAuthentication(testToken);
repo.saveContext(context, holder.getRequest(), holder.getResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
@Test
@@ -152,12 +152,12 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
response);
SecurityContext context = repo.loadContext(holder);
assertNotNull(context);
assertEquals(testToken, context.getAuthentication());
assertThat(context).isNotNull();
assertThat(context.getAuthentication()).isEqualTo(testToken);
// Won't actually be saved as it hasn't changed, but go through the use case
// anyway
repo.saveContext(context, holder.getRequest(), holder.getResponse());
assertEquals(context, request.getSession().getAttribute("imTheContext"));
assertThat(request.getSession().getAttribute("imTheContext")).isEqualTo(context);
}
// SEC-1528
@@ -175,7 +175,7 @@ public class HttpSessionSecurityContextRepositoryTests {
request.setSession(session);
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
new MockHttpServletResponse());
assertSame(ctx, repo.loadContext(holder));
assertThat(repo.loadContext(holder)).isSameAs(ctx);
// Modify context contents. Same user, different role
SecurityContextHolder.getContext().setAuthentication(
@@ -197,8 +197,8 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
response);
SecurityContext context = repo.loadContext(holder);
assertNotNull(context);
assertNull(context.getAuthentication());
assertThat(context).isNotNull();
assertThat(context.getAuthentication()).isNull();
}
@Test
@@ -209,11 +209,11 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
response);
SecurityContext context = repo.loadContext(holder);
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
// Simulate authentication during the request
context.setAuthentication(testToken);
repo.saveContext(context, holder.getRequest(), holder.getResponse());
assertNotNull(request.getSession(false));
assertThat(request.getSession(false)).isNotNull();
assertEquals(context,
request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
}
@@ -229,14 +229,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().sendRedirect("/doesntmatter");
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -251,14 +251,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().sendError(404);
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -274,14 +274,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().flushBuffer();
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -297,14 +297,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().getWriter().flush();
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -320,14 +320,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().getWriter().close();
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -343,14 +343,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().getOutputStream().flush();
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -366,14 +366,14 @@ public class HttpSessionSecurityContextRepositoryTests {
SecurityContextHolder.setContext(repo.loadContext(holder));
SecurityContextHolder.getContext().setAuthentication(testToken);
holder.getResponse().getOutputStream().close();
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
assertTrue(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse())
assertThat(((SaveContextOnUpdateOrErrorResponseWrapper) holder.getResponse()).isTrue()
.isContextSaved());
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
// Check it's still the same
assertEquals(SecurityContextHolder.getContext(), request.getSession()
assertThat(request.getSession().isEqualTo(SecurityContextHolder.getContext())
.getAttribute("imTheContext"));
}
@@ -425,7 +425,7 @@ public class HttpSessionSecurityContextRepositoryTests {
request.getSession().invalidate();
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
// SEC-1315
@@ -442,7 +442,7 @@ public class HttpSessionSecurityContextRepositoryTests {
.createAuthorityList("ANON")));
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
// SEC-1587
@@ -460,7 +460,7 @@ public class HttpSessionSecurityContextRepositoryTests {
new AnonymousAuthenticationToken("x", "x", testToken.getAuthorities()));
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
assertNull(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
assertThat(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY)).isNull();
}
@Test
@@ -477,7 +477,7 @@ public class HttpSessionSecurityContextRepositoryTests {
// Save an empty context
repo.saveContext(SecurityContextHolder.getContext(), holder.getRequest(),
holder.getResponse());
assertNull(request.getSession().getAttribute("imTheContext"));
assertThat(request.getSession().getAttribute("imTheContext")).isNull();
}
// SEC-1735
@@ -516,7 +516,7 @@ public class HttpSessionSecurityContextRepositoryTests {
ctxInSession.setAuthentication(null);
repo.saveContext(ctxInSession, holder.getRequest(), holder.getResponse());
assertNull(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
assertThat(request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY)).isNull();
}
@Test
@@ -551,17 +551,17 @@ public class HttpSessionSecurityContextRepositoryTests {
response);
repo.loadContext(holder);
String url = "/aUrl";
assertEquals(url + sessionId, holder.getResponse().encodeRedirectUrl(url));
assertEquals(url + sessionId, holder.getResponse().encodeRedirectURL(url));
assertEquals(url + sessionId, holder.getResponse().encodeUrl(url));
assertEquals(url + sessionId, holder.getResponse().encodeURL(url));
assertThat(holder.getResponse().encodeRedirectUrl(url)).isEqualTo(url + sessionId);
assertThat(holder.getResponse().encodeRedirectURL(url)).isEqualTo(url + sessionId);
assertThat(holder.getResponse().encodeUrl(url)).isEqualTo(url + sessionId);
assertThat(holder.getResponse().encodeURL(url)).isEqualTo(url + sessionId);
repo.setDisableUrlRewriting(true);
holder = new HttpRequestResponseHolder(request, response);
repo.loadContext(holder);
assertEquals(url, holder.getResponse().encodeRedirectUrl(url));
assertEquals(url, holder.getResponse().encodeRedirectURL(url));
assertEquals(url, holder.getResponse().encodeUrl(url));
assertEquals(url, holder.getResponse().encodeURL(url));
assertThat(holder.getResponse().encodeRedirectUrl(url)).isEqualTo(url);
assertThat(holder.getResponse().encodeRedirectURL(url)).isEqualTo(url);
assertThat(holder.getResponse().encodeUrl(url)).isEqualTo(url);
assertThat(holder.getResponse().encodeURL(url)).isEqualTo(url);
}
@Test
@@ -596,14 +596,14 @@ public class HttpSessionSecurityContextRepositoryTests {
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
response);
SecurityContext context = repo.loadContext(holder);
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
// Simulate authentication during the request
context.setAuthentication(testToken);
repo.saveContext(context, new HttpServletRequestWrapper(holder.getRequest()),
new HttpServletResponseWrapper(holder.getResponse()));
assertNotNull(request.getSession(false));
assertThat(request.getSession(false)).isNotNull();
assertEquals(context,
request.getSession().getAttribute(SPRING_SECURITY_CONTEXT_KEY));
}

View File

@@ -28,7 +28,7 @@ import org.mockito.runners.MockitoJUnitRunner;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -1119,4 +1119,4 @@ public class OnCommittedResponseWrapperTests {
assertThat(committed).isFalse();
}
}
}

View File

@@ -12,7 +12,7 @@
*/
package org.springframework.security.web.context;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import javax.servlet.http.HttpServletResponse;

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.context;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
@@ -38,7 +38,7 @@ public class SecurityContextPersistenceFilterTests {
filter.doFilter(request, response, chain);
verify(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class));
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -57,7 +57,7 @@ public class SecurityContextPersistenceFilterTests {
catch (IOException expected) {
}
assertNull(SecurityContextHolder.getContext().getAuthentication());
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
@Test
@@ -80,7 +80,7 @@ public class SecurityContextPersistenceFilterTests {
final FilterChain chain = new FilterChain() {
public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
assertEquals(beforeAuth, SecurityContextHolder.getContext()
assertThat(SecurityContextHolder.getContext().isEqualTo(beforeAuth)
.getAuthentication());
// Change the context here
SecurityContextHolder.setContext(scExpectedAfter);
@@ -114,7 +114,7 @@ public class SecurityContextPersistenceFilterTests {
SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter();
filter.setForceEagerSessionCreation(true);
filter.doFilter(request, response, chain);
assertNotNull(request.getSession(false));
assertThat(request.getSession(false)).isNotNull();
}
@Test
@@ -127,7 +127,7 @@ public class SecurityContextPersistenceFilterTests {
SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(
repo);
filter.doFilter(request, response, chain);
assertFalse(repo.containsContext(request));
assertNull(request.getSession(false));
assertThat(repo.containsContext(request)).isFalse();
assertThat(request.getSession(false)).isNull();
}
}

View File

@@ -12,7 +12,7 @@
*/
package org.springframework.security.web.context.request.async;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.Callable;

View File

@@ -12,7 +12,7 @@
*/
package org.springframework.security.web.context.request.async;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import java.util.concurrent.Callable;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.csrf;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.csrf;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
@@ -31,8 +31,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fest.assertions.GenericAssert;
import org.fest.assertions.ObjectAssert;
import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.ObjectAssert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -361,7 +361,7 @@ public class CsrfFilterTests {
}
private static class CsrfTokenAssert extends
GenericAssert<CsrfTokenAssert, CsrfToken> {
AbstractObjectAssert<CsrfTokenAssert, CsrfToken> {
/**
* Creates a new </code>{@link ObjectAssert}</code>.
@@ -369,7 +369,7 @@ public class CsrfFilterTests {
* @param actual the target to verify.
*/
protected CsrfTokenAssert(CsrfToken actual) {
super(CsrfTokenAssert.class, actual);
super(actual,CsrfTokenAssert.class);
}
public CsrfTokenAssert isEqualTo(CsrfToken expected) {

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.csrf;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;

View File

@@ -1,7 +1,7 @@
package org.springframework.security.web.debug;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
@@ -73,7 +73,7 @@ public class DebugFilterTest {
verify(logger).info(anyString());
verify(request).setAttribute(requestAttr, Boolean.TRUE);
verify(fcp).doFilter(requestCaptor.capture(), eq(response), eq(filterChain));
assertEquals(DebugRequestWrapper.class, requestCaptor.getValue().getClass());
assertThat(requestCaptor.getValue().getClass()).isEqualTo(DebugRequestWrapper.class);
verify(request).removeAttribute(requestAttr);
}
@@ -121,4 +121,4 @@ public class DebugFilterTest {
+ "A: A Value, Another Value\n" + "B: B Value\n" + "\n" + "\n"
+ "Security filter chain: no match");
}
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.firewall;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;

View File

@@ -1,7 +1,7 @@
package org.springframework.security.web.firewall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.*;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -17,7 +17,7 @@ public class FirewalledResponseTests {
FirewalledResponse fwResponse = new FirewalledResponse(response);
fwResponse.sendRedirect("/theURL");
assertEquals("/theURL", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/theURL");
try {
fwResponse.sendRedirect("/theURL\r\nsomething");

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.firewall;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.LinkedHashMap;
@@ -40,9 +40,9 @@ public class RequestWrapperTests {
String expectedResult = entry.getValue();
request.setServletPath(path);
RequestWrapper wrapper = new RequestWrapper(request);
assertEquals(expectedResult, wrapper.getServletPath());
assertThat(wrapper.getServletPath()).isEqualTo(expectedResult);
wrapper.reset();
assertEquals(path, wrapper.getServletPath());
assertThat(wrapper.getServletPath()).isEqualTo(path);
}
}
@@ -59,9 +59,9 @@ public class RequestWrapperTests {
}
request.setPathInfo(path);
RequestWrapper wrapper = new RequestWrapper(request);
assertEquals(expectedResult, wrapper.getPathInfo());
assertThat(wrapper.getPathInfo()).isEqualTo(expectedResult);
wrapper.reset();
assertEquals(path, wrapper.getPathInfo());
assertThat(wrapper.getPathInfo()).isEqualTo(path);
}
}
@@ -82,7 +82,7 @@ public class RequestWrapperTests {
verify(mockRequest).getRequestDispatcher(forwardPath);
verify(mockDispatcher).forward(mockRequest, mockResponse);
assertEquals(denormalizedPath, wrapper.getPathInfo());
assertThat(wrapper.getPathInfo()).isEqualTo(denormalizedPath);
verify(mockRequest, times(2)).getPathInfo();
// validate wrapper.getServletPath() delegates to the mock
wrapper.getServletPath();
@@ -98,6 +98,6 @@ public class RequestWrapperTests {
when(request.getRequestDispatcher(path)).thenReturn(dispatcher);
RequestWrapper wrapper = new RequestWrapper(request);
wrapper.reset();
assertSame(dispatcher, wrapper.getRequestDispatcher(path));
assertThat(wrapper.getRequestDispatcher(path)).isSameAs(dispatcher);
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.URI;
import java.net.URISyntaxException;
@@ -26,7 +23,10 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
/**
* @author Tim Ysewyn
@@ -66,7 +66,7 @@ public class HpkpHeaderWriterTests {
public void writeHeadersDefaultValues() {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\"");
}
@@ -78,7 +78,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=2592000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\"");
}
@@ -90,7 +90,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=2592000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; includeSubDomains");
}
@@ -101,7 +101,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins")).isEqualTo(
"max-age=2592000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; includeSubDomains");
}
@@ -112,7 +112,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=2592000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\"");
}
@@ -123,7 +123,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; includeSubDomains");
}
@@ -134,7 +134,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\"");
}
@@ -146,7 +146,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; report-uri=\"http://example.com/pkp-report\"");
}
@@ -158,7 +158,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; report-uri=\"http://example.com/pkp-report\"");
}
@@ -168,7 +168,7 @@ public class HpkpHeaderWriterTests {
writer.addSha256Pins("d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=", "E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=");
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().size()).isEqualTo(1);
assertThat(response.getHeaderNames()).hasSize(1);
assertThat(response.getHeader("Public-Key-Pins-Report-Only")).isEqualTo(
"max-age=5184000 ; pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\" ; pin-sha256=\"E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=\"");
}
@@ -179,7 +179,7 @@ public class HpkpHeaderWriterTests {
writer.writeHeaders(request, response);
assertThat(response.getHeaderNames().isEmpty()).isTrue();
assertThat(response.getHeaderNames()).isEmpty();
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collections;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers.frameoptions;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.header.writers.frameoptions;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import java.util.Collections;

View File

@@ -6,7 +6,7 @@ import org.springframework.security.web.header.writers.frameoptions.StaticAllowF
import java.net.URI;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for the StaticAllowFromStrategy.
@@ -20,6 +20,6 @@ public class StaticAllowFromStrategyTests {
public void shouldReturnUri() {
String uri = "http://www.test.com";
StaticAllowFromStrategy strategy = new StaticAllowFromStrategy(URI.create(uri));
assertEquals(uri, strategy.getAllowFromValue(new MockHttpServletRequest()));
assertThat(strategy.getAllowFromValue(new MockHttpServletRequest())).isEqualTo(uri);
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.jaasapi;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -137,7 +137,7 @@ public class JaasApiIntegrationFilterTests {
*/
@Test
public void currentSubjectNull() {
assertNull(Subject.getSubject(AccessController.getContext()));
assertThat(Subject.getSubject(AccessController.getContext())).isNull();
}
@Test
@@ -165,7 +165,7 @@ public class JaasApiIntegrationFilterTests {
public void obtainSubjectNullSubject() throws Exception {
LoginContext ctx = new LoginContext("obtainSubjectNullSubject", null,
callbackHandler, testConfiguration);
assertNull(ctx.getSubject());
assertThat(ctx.getSubject()).isNull();
token = new JaasAuthenticationToken("un", "pwd",
AuthorityUtils.createAuthorityList("ROLE_ADMIN"), ctx);
SecurityContextHolder.getContext().setAuthentication(token);
@@ -175,7 +175,7 @@ public class JaasApiIntegrationFilterTests {
@Test
public void obtainSubject() throws Exception {
SecurityContextHolder.getContext().setAuthentication(token);
assertEquals(authenticatedSubject, filter.obtainSubject(request));
assertThat(filter.obtainSubject(request)).isEqualTo(authenticatedSubject);
}
@Test
@@ -211,7 +211,7 @@ public class JaasApiIntegrationFilterTests {
// See if the subject was updated
Subject currentSubject = Subject
.getSubject(AccessController.getContext());
assertEquals(expectedValue, currentSubject);
assertThat(currentSubject).isEqualTo(expectedValue);
// run so we know the chain was executed
super.doFilter(request, response);
@@ -219,10 +219,10 @@ public class JaasApiIntegrationFilterTests {
};
filter.doFilter(request, response, chain);
// ensure that the chain was actually invoked
assertNotNull(chain.getRequest());
assertThat(chain.getRequest()).isNotNull();
}
private void assertNullSubject(Subject subject) {
assertNull("Subject is expected to be null, but is not. Got " + subject, subject);
assertThat("Subject is expected to be null, but is not. Got " + subject, subject).isNull();
}
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.method.annotation;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.method.annotation;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Method;

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.savedrequest;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.security.MockPortResolver;
@@ -19,7 +19,7 @@ public class DefaultSavedRequestTests {
request.addHeader("USER-aGenT", "Mozilla");
DefaultSavedRequest saved = new DefaultSavedRequest(request,
new MockPortResolver(8080, 8443));
assertEquals("Mozilla", saved.getHeaderValues("user-agent").get(0));
assertThat(saved.getHeaderValues("user-agent").get(0)).isEqualTo("Mozilla");
}
// SEC-1412
@@ -29,7 +29,7 @@ public class DefaultSavedRequestTests {
request.addHeader("If-None-Match", "somehashvalue");
DefaultSavedRequest saved = new DefaultSavedRequest(request,
new MockPortResolver(8080, 8443));
assertTrue(saved.getHeaderValues("if-none-match").isEmpty());
assertThat(saved.getHeaderValues("if-none-match").isEmpty()).isTrue();
}
// SEC-3082
@@ -40,7 +40,7 @@ public class DefaultSavedRequestTests {
request.addParameter("thisisatest", "Hi mom");
DefaultSavedRequest saved = new DefaultSavedRequest(request,
new MockPortResolver(8080, 8443));
assertEquals("Hi mom", saved.getParameterValues("thisisatest")[0]);
assertNull(saved.getParameterValues("anothertest"));
assertThat(saved.getParameterValues("thisisatest")[0]).isEqualTo("Hi mom");
assertThat(saved.getParameterValues("anothertest")).isNull();
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.savedrequest;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -33,14 +33,14 @@ public class HttpSessionRequestCacheTests {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/destination");
MockHttpServletResponse response = new MockHttpServletResponse();
cache.saveRequest(request, response);
assertNotNull(request.getSession().getAttribute(
assertThat(request.getSession().isNotNull().getAttribute(
HttpSessionRequestCache.SAVED_REQUEST));
assertNotNull(cache.getRequest(request, response));
assertThat(cache.getRequest(request, response)).isNotNull();
MockHttpServletRequest newRequest = new MockHttpServletRequest("POST",
"/destination");
newRequest.setSession(request.getSession());
assertNull(cache.getMatchingRequest(newRequest, response));
assertThat(cache.getMatchingRequest(newRequest, response)).isNull();
}
@@ -57,10 +57,10 @@ public class HttpSessionRequestCacheTests {
"/destination");
MockHttpServletResponse response = new MockHttpServletResponse();
cache.saveRequest(request, response);
assertNull(cache.getRequest(request, response));
assertNull(cache.getRequest(new MockHttpServletRequest(),
assertThat(cache.getRequest(request, response)).isNull();
assertThat(cache.getRequest(new MockHttpServletRequest().isNull(),
new MockHttpServletResponse()));
assertNull(cache.getMatchingRequest(request, response));
assertThat(cache.getMatchingRequest(request, response)).isNull();
}
// SEC-2246

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.savedrequest;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.mock.web.MockFilterChain;
@@ -18,11 +18,11 @@ public class RequestCacheAwareFilterTests {
"/destination");
MockHttpServletResponse response = new MockHttpServletResponse();
cache.saveRequest(request, response);
assertNotNull(request.getSession().getAttribute(
assertThat(request.getSession().isNotNull().getAttribute(
HttpSessionRequestCache.SAVED_REQUEST));
filter.doFilter(request, response, new MockFilterChain());
assertNull(request.getSession().getAttribute(
assertThat(request.getSession().isNull().getAttribute(
HttpSessionRequestCache.SAVED_REQUEST));
}
}

View File

@@ -25,46 +25,46 @@ public class SavedCookieTests extends TestCase {
}
public void testGetName() throws Exception {
assertEquals(cookie.getName(), savedCookie.getName());
assertThat(savedCookie.getName()).isEqualTo(cookie.getName());
}
public void testGetValue() throws Exception {
assertEquals(cookie.getValue(), savedCookie.getValue());
assertThat(savedCookie.getValue()).isEqualTo(cookie.getValue());
}
public void testGetComment() throws Exception {
assertEquals(cookie.getComment(), savedCookie.getComment());
assertThat(savedCookie.getComment()).isEqualTo(cookie.getComment());
}
public void testGetDomain() throws Exception {
assertEquals(cookie.getDomain(), savedCookie.getDomain());
assertThat(savedCookie.getDomain()).isEqualTo(cookie.getDomain());
}
public void testGetMaxAge() throws Exception {
assertEquals(cookie.getMaxAge(), savedCookie.getMaxAge());
assertThat(savedCookie.getMaxAge()).isEqualTo(cookie.getMaxAge());
}
public void testGetPath() throws Exception {
assertEquals(cookie.getPath(), savedCookie.getPath());
assertThat(savedCookie.getPath()).isEqualTo(cookie.getPath());
}
public void testGetVersion() throws Exception {
assertEquals(cookie.getVersion(), savedCookie.getVersion());
assertThat(savedCookie.getVersion()).isEqualTo(cookie.getVersion());
}
public void testGetCookie() throws Exception {
Cookie other = savedCookie.getCookie();
assertEquals(cookie.getComment(), other.getComment());
assertEquals(cookie.getDomain(), other.getDomain());
assertEquals(cookie.getMaxAge(), other.getMaxAge());
assertEquals(cookie.getName(), other.getName());
assertEquals(cookie.getPath(), other.getPath());
assertEquals(cookie.getSecure(), other.getSecure());
assertEquals(cookie.getValue(), other.getValue());
assertEquals(cookie.getVersion(), other.getVersion());
assertThat(other.getComment()).isEqualTo(cookie.getComment());
assertThat(other.getDomain()).isEqualTo(cookie.getDomain());
assertThat(other.getMaxAge()).isEqualTo(cookie.getMaxAge());
assertThat(other.getName()).isEqualTo(cookie.getName());
assertThat(other.getPath()).isEqualTo(cookie.getPath());
assertThat(other.getSecure()).isEqualTo(cookie.getSecure());
assertThat(other.getValue()).isEqualTo(cookie.getValue());
assertThat(other.getVersion()).isEqualTo(cookie.getVersion());
}
public void testSerializable() throws Exception {
assertTrue(savedCookie instanceof Serializable);
assertThat(savedCookie instanceof Serializable).isTrue();
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.savedrequest;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -33,8 +33,8 @@ public class SavedRequestAwareWrapperTests {
MockHttpServletRequest savedRequest = new MockHttpServletRequest();
savedRequest.setCookies(new Cookie[] { new Cookie("cookie", "fromsaved") });
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, newRequest);
assertEquals(1, wrapper.getCookies().length);
assertEquals("fromnew", wrapper.getCookies()[0].getValue());
assertThat(wrapper.getCookies().length).isEqualTo(1);
assertThat(wrapper.getCookies()[0].getValue()).isEqualTo("fromnew");
}
@Test
@@ -45,17 +45,17 @@ public class SavedRequestAwareWrapperTests {
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest,
new MockHttpServletRequest());
assertNull(wrapper.getHeader("nonexistent"));
assertThat(wrapper.getHeader("nonexistent")).isNull();
Enumeration headers = wrapper.getHeaders("nonexistent");
assertFalse(headers.hasMoreElements());
assertThat(headers.hasMoreElements()).isFalse();
assertEquals("savedheader", wrapper.getHeader("Header"));
assertThat(wrapper.getHeader("Header")).isEqualTo("savedheader");
headers = wrapper.getHeaders("heaDer");
assertTrue(headers.hasMoreElements());
assertEquals("savedheader", headers.nextElement());
assertFalse(headers.hasMoreElements());
assertTrue(wrapper.getHeaderNames().hasMoreElements());
assertEquals("header", wrapper.getHeaderNames().nextElement());
assertThat(headers.hasMoreElements()).isTrue();
assertThat(headers.nextElement()).isEqualTo("savedheader");
assertThat(headers.hasMoreElements()).isFalse();
assertThat(wrapper.getHeaderNames().hasMoreElements()).isTrue();
assertThat(wrapper.getHeaderNames().nextElement()).isEqualTo("header");
}
@Test
@@ -69,13 +69,13 @@ public class SavedRequestAwareWrapperTests {
savedRequest.setParameter("action", "foo");
MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
assertEquals("foo", wrapper.getParameter("action"));
assertThat(wrapper.getParameter("action")).isEqualTo("foo");
// The request after forward
wrappedRequest.setParameter("action", "bar");
assertEquals("bar", wrapper.getParameter("action"));
assertThat(wrapper.getParameter("action")).isEqualTo("bar");
// Both values should be set, but "bar" should be first
assertEquals(2, wrapper.getParameterValues("action").length);
assertEquals("bar", wrapper.getParameterValues("action")[0]);
assertThat(wrapper.getParameterValues("action").length).isEqualTo(2);
assertThat(wrapper.getParameterValues("action")[0]).isEqualTo("bar");
}
@Test
@@ -85,9 +85,9 @@ public class SavedRequestAwareWrapperTests {
MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
wrappedRequest.setParameter("action", "foo");
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
assertEquals(1, wrapper.getParameterValues("action").length);
assertEquals(1, wrapper.getParameterMap().size());
assertEquals(1, ((String[]) wrapper.getParameterMap().get("action")).length);
assertThat(wrapper.getParameterValues("action").length).isEqualTo(1);
assertThat(wrapper.getParameterMap()).hasSize(1);
assertThat(((String[]) wrapper.getParameterMap().get("action")).length).isEqualTo(1);
}
@Test
@@ -97,15 +97,15 @@ public class SavedRequestAwareWrapperTests {
MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
wrappedRequest.addHeader("Authorization", "bar");
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
assertEquals("foo", wrapper.getHeader("Authorization"));
assertThat(wrapper.getHeader("Authorization")).isEqualTo("foo");
}
@Test
public void getParameterValuesReturnsNullIfParameterIsntSet() {
SavedRequestAwareWrapper wrapper = createWrapper(new MockHttpServletRequest(),
new MockHttpServletRequest());
assertNull(wrapper.getParameterValues("action"));
assertNull(wrapper.getParameterMap().get("action"));
assertThat(wrapper.getParameterValues("action")).isNull();
assertThat(wrapper.getParameterMap().get("action")).isNull();
}
@Test
@@ -115,14 +115,14 @@ public class SavedRequestAwareWrapperTests {
MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
assertArrayEquals(new Object[] { "foo" }, wrapper.getParameterValues("action"));
assertThat(wrapper.getParameterValues("action")).isEqualTo(new Object[] { "foo" });
wrappedRequest.setParameter("action", "bar");
assertArrayEquals(new Object[] { "bar", "foo" },
wrapper.getParameterValues("action"));
// Check map is consistent
String[] valuesFromMap = (String[]) wrapper.getParameterMap().get("action");
assertEquals(2, valuesFromMap.length);
assertEquals("bar", valuesFromMap[0]);
assertThat(valuesFromMap.length).isEqualTo(2);
assertThat(valuesFromMap[0]).isEqualTo("bar");
}
@Test
@@ -135,9 +135,9 @@ public class SavedRequestAwareWrapperTests {
request.addHeader("header", nowString);
SavedRequestAwareWrapper wrapper = createWrapper(request,
new MockHttpServletRequest());
assertEquals(now.getTime(), wrapper.getDateHeader("header"));
assertThat(wrapper.getDateHeader("header")).isEqualTo(now.getTime());
assertEquals(-1L, wrapper.getDateHeader("nonexistent"));
assertThat(wrapper.getDateHeader("nonexistent")).isEqualTo(-1L);
}
@Test(expected = IllegalArgumentException.class)
@@ -154,7 +154,7 @@ public class SavedRequestAwareWrapperTests {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/notused");
SavedRequestAwareWrapper wrapper = createWrapper(request,
new MockHttpServletRequest("GET", "/notused"));
assertEquals("PUT", wrapper.getMethod());
assertThat(wrapper.getMethod()).isEqualTo("PUT");
}
@Test
@@ -165,8 +165,8 @@ public class SavedRequestAwareWrapperTests {
SavedRequestAwareWrapper wrapper = createWrapper(request,
new MockHttpServletRequest());
assertEquals(999, wrapper.getIntHeader("header"));
assertEquals(-1, wrapper.getIntHeader("nonexistent"));
assertThat(wrapper.getIntHeader("header")).isEqualTo(999);
assertThat(wrapper.getIntHeader("nonexistent")).isEqualTo(-1);
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.servlet.support.csrf;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Method;
import java.util.HashMap;

View File

@@ -17,7 +17,7 @@
package org.springframework.security.web.servletapi;
import static junit.framework.Assert.fail;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;

View File

@@ -46,10 +46,10 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "");
assertEquals("rod", wrapper.getRemoteUser());
assertTrue(wrapper.isUserInRole("ROLE_FOO"));
assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
assertEquals(auth, wrapper.getUserPrincipal());
assertThat(wrapper.getRemoteUser()).isEqualTo("rod");
assertThat(wrapper.isUserInRole("ROLE_FOO")).isTrue();
assertThat(wrapper.isUserInRole("ROLE_NOT_GRANTED")).isFalse();
assertThat(wrapper.getUserPrincipal()).isEqualTo(auth);
}
public void testUseOfRolePrefixMeansItIsntNeededWhenCallngIsUserInRole() {
@@ -62,7 +62,7 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "ROLE_");
assertTrue(wrapper.isUserInRole("FOO"));
assertThat(wrapper.isUserInRole("FOO")).isTrue();
}
public void testCorrectOperationWithUserDetailsBasedPrincipal() throws Exception {
@@ -77,12 +77,12 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "");
assertEquals("rodAsUserDetails", wrapper.getRemoteUser());
assertFalse(wrapper.isUserInRole("ROLE_FOO"));
assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
assertEquals(auth, wrapper.getUserPrincipal());
assertThat(wrapper.getRemoteUser()).isEqualTo("rodAsUserDetails");
assertThat(wrapper.isUserInRole("ROLE_FOO")).isFalse();
assertThat(wrapper.isUserInRole("ROLE_NOT_GRANTED")).isFalse();
assertThat(wrapper.isUserInRole("ROLE_FOOBAR")).isTrue();
assertThat(wrapper.isUserInRole("ROLE_HELLO")).isTrue();
assertThat(wrapper.getUserPrincipal()).isEqualTo(auth);
}
public void testRoleIsntHeldIfAuthenticationIsNull() throws Exception {
@@ -93,9 +93,9 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "");
assertNull(wrapper.getRemoteUser());
assertFalse(wrapper.isUserInRole("ROLE_ANY"));
assertNull(wrapper.getUserPrincipal());
assertThat(wrapper.getRemoteUser()).isNull();
assertThat(wrapper.isUserInRole("ROLE_ANY")).isFalse();
assertThat(wrapper.getUserPrincipal()).isNull();
}
public void testRolesArentHeldIfAuthenticationPrincipalIsNull() throws Exception {
@@ -109,10 +109,10 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "");
assertNull(wrapper.getRemoteUser());
assertFalse(wrapper.isUserInRole("ROLE_HELLO")); // principal is null, so reject
assertFalse(wrapper.isUserInRole("ROLE_FOOBAR")); // principal is null, so reject
assertNull(wrapper.getUserPrincipal());
assertThat(wrapper.getRemoteUser()).isNull();
assertThat(wrapper.isUserInRole("ROLE_HELLO")).isFalse(); // principal is null, so reject
assertThat(wrapper.isUserInRole("ROLE_FOOBAR")).isFalse(); // principal is null, so reject
assertThat(wrapper.getUserPrincipal()).isNull();
}
public void testRolePrefix() {
@@ -125,8 +125,8 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "ROLE_");
assertTrue(wrapper.isUserInRole("HELLO"));
assertTrue(wrapper.isUserInRole("FOOBAR"));
assertThat(wrapper.isUserInRole("HELLO")).isTrue();
assertThat(wrapper.isUserInRole("FOOBAR")).isTrue();
}
// SEC-3020
@@ -140,7 +140,7 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(
request, "ROLE_");
assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
assertThat(wrapper.isUserInRole("ROLE_HELLO")).isTrue();
assertThat(wrapper.isUserInRole("ROLE_FOOBAR")).isTrue();
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.security.web.session;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import javax.servlet.http.HttpServletRequest;
@@ -47,7 +47,7 @@ public class DefaultSessionAuthenticationStrategyTests {
strategy.onAuthentication(mock(Authentication.class), request,
new MockHttpServletResponse());
assertNull(request.getSession(false));
assertThat(request.getSession(false)).isNull();
}
@Test
@@ -59,7 +59,7 @@ public class DefaultSessionAuthenticationStrategyTests {
strategy.onAuthentication(mock(Authentication.class), request,
new MockHttpServletResponse());
assertFalse(sessionId.equals(request.getSession().getId()));
assertThat(sessionId.equals(request.getSession().getId())).isFalse();
}
// SEC-2002
@@ -85,18 +85,18 @@ public class DefaultSessionAuthenticationStrategyTests {
.forClass(ApplicationEvent.class);
verify(eventPublisher).publishEvent(eventArgumentCaptor.capture());
assertFalse(oldSessionId.equals(request.getSession().getId()));
assertNotNull(request.getSession().getAttribute("blah"));
assertNotNull(request.getSession().getAttribute(
assertThat(oldSessionId.equals(request.getSession().getId())).isFalse();
assertThat(request.getSession().getAttribute("blah")).isNotNull();
assertThat(request.getSession().isNotNull().getAttribute(
"SPRING_SECURITY_SAVED_REQUEST_KEY"));
assertNotNull(eventArgumentCaptor.getValue());
assertTrue(eventArgumentCaptor.getValue() instanceof SessionFixationProtectionEvent);
assertThat(eventArgumentCaptor.getValue()).isNotNull();
assertThat(eventArgumentCaptor.getValue() instanceof SessionFixationProtectionEvent).isTrue();
SessionFixationProtectionEvent event = (SessionFixationProtectionEvent) eventArgumentCaptor
.getValue();
assertEquals(oldSessionId, event.getOldSessionId());
assertEquals(request.getSession().getId(), event.getNewSessionId());
assertSame(mockAuthentication, event.getAuthentication());
assertThat(event.getOldSessionId()).isEqualTo(oldSessionId);
assertThat(event.getNewSessionId()).isEqualTo(request.getSession().getId());
assertThat(event.getAuthentication()).isSameAs(mockAuthentication);
}
// See SEC-1077
@@ -113,8 +113,8 @@ public class DefaultSessionAuthenticationStrategyTests {
strategy.onAuthentication(mock(Authentication.class), request,
new MockHttpServletResponse());
assertNull(request.getSession().getAttribute("blah"));
assertNotNull(request.getSession().getAttribute(
assertThat(request.getSession().getAttribute("blah")).isNull();
assertThat(request.getSession().isNotNull().getAttribute(
"SPRING_SECURITY_SAVED_REQUEST_KEY"));
}
@@ -142,17 +142,17 @@ public class DefaultSessionAuthenticationStrategyTests {
.forClass(ApplicationEvent.class);
verify(eventPublisher).publishEvent(eventArgumentCaptor.capture());
assertNull(request.getSession().getAttribute("blah"));
assertNotNull(request.getSession().getAttribute(
assertThat(request.getSession().getAttribute("blah")).isNull();
assertThat(request.getSession().isNotNull().getAttribute(
"SPRING_SECURITY_SAVED_REQUEST_KEY"));
assertNotNull(eventArgumentCaptor.getValue());
assertTrue(eventArgumentCaptor.getValue() instanceof SessionFixationProtectionEvent);
assertThat(eventArgumentCaptor.getValue()).isNotNull();
assertThat(eventArgumentCaptor.getValue() instanceof SessionFixationProtectionEvent).isTrue();
SessionFixationProtectionEvent event = (SessionFixationProtectionEvent) eventArgumentCaptor
.getValue();
assertEquals(oldSessionId, event.getOldSessionId());
assertEquals(request.getSession().getId(), event.getNewSessionId());
assertSame(mockAuthentication, event.getAuthentication());
assertThat(event.getOldSessionId()).isEqualTo(oldSessionId);
assertThat(event.getNewSessionId()).isEqualTo(request.getSession().getId());
assertThat(event.getAuthentication()).isSameAs(mockAuthentication);
}
@Test
@@ -162,7 +162,7 @@ public class DefaultSessionAuthenticationStrategyTests {
HttpServletRequest request = new MockHttpServletRequest();
strategy.onAuthentication(mock(Authentication.class), request,
new MockHttpServletResponse());
assertNotNull(request.getSession(false));
assertThat(request.getSession(false)).isNotNull();
}
}

View File

@@ -1,6 +1,6 @@
package org.springframework.security.web.session;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
@@ -34,22 +34,22 @@ public class HttpSessionDestroyedEventTests {
@Test
public void getSecurityContexts() {
List<SecurityContext> securityContexts = destroyedEvent.getSecurityContexts();
assertEquals(1, securityContexts.size());
assertSame(session.getAttribute("context"), securityContexts.get(0));
assertThat(securityContexts).hasSize(1);
assertThat(securityContexts.get(0)).isSameAs(session.getAttribute("context"));
}
@Test
public void getSecurityContextsMulti() {
session.setAttribute("another", new SecurityContextImpl());
List<SecurityContext> securityContexts = destroyedEvent.getSecurityContexts();
assertEquals(2, securityContexts.size());
assertThat(securityContexts).hasSize(2);
}
@Test
public void getSecurityContextsDiffImpl() {
session.setAttribute("context", mock(SecurityContext.class));
List<SecurityContext> securityContexts = destroyedEvent.getSecurityContexts();
assertEquals(1, securityContexts.size());
assertSame(session.getAttribute("context"), securityContexts.get(0));
assertThat(securityContexts).hasSize(1);
assertThat(securityContexts.get(0)).isSameAs(session.getAttribute("context"));
}
}
}

View File

@@ -15,7 +15,7 @@
package org.springframework.security.web.session;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import javax.servlet.http.HttpSessionEvent;
@@ -60,17 +60,17 @@ public class HttpSessionEventPublisherTests {
publisher.sessionCreated(event);
assertNotNull(listener.getCreatedEvent());
assertNull(listener.getDestroyedEvent());
assertEquals(session, listener.getCreatedEvent().getSession());
assertThat(listener.getCreatedEvent()).isNotNull();
assertThat(listener.getDestroyedEvent()).isNull();
assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
listener.setCreatedEvent(null);
listener.setDestroyedEvent(null);
publisher.sessionDestroyed(event);
assertNotNull(listener.getDestroyedEvent());
assertNull(listener.getCreatedEvent());
assertEquals(session, listener.getDestroyedEvent().getSession());
assertThat(listener.getDestroyedEvent()).isNotNull();
assertThat(listener.getCreatedEvent()).isNull();
assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
}
@Test
@@ -96,17 +96,17 @@ public class HttpSessionEventPublisherTests {
publisher.sessionCreated(event);
assertNotNull(listener.getCreatedEvent());
assertNull(listener.getDestroyedEvent());
assertEquals(session, listener.getCreatedEvent().getSession());
assertThat(listener.getCreatedEvent()).isNotNull();
assertThat(listener.getDestroyedEvent()).isNull();
assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
listener.setCreatedEvent(null);
listener.setDestroyedEvent(null);
publisher.sessionDestroyed(event);
assertNotNull(listener.getDestroyedEvent());
assertNull(listener.getCreatedEvent());
assertEquals(session, listener.getDestroyedEvent().getSession());
assertThat(listener.getDestroyedEvent()).isNotNull();
assertThat(listener.getCreatedEvent()).isNull();
assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
}
// SEC-2599

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.security.web.session;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
@@ -58,7 +58,7 @@ public class SessionManagementFilterTests {
filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
assertEquals(sessionId, request.getSession().getId());
assertThat(request.getSession().getId()).isEqualTo(sessionId);
}
@Test
@@ -144,7 +144,7 @@ public class SessionManagementFilterTests {
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, new MockFilterChain());
assertNull(response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isNull();
// Now set a redirect URL
request = new MockHttpServletRequest();
@@ -158,7 +158,7 @@ public class SessionManagementFilterTests {
filter.doFilter(request, response, fc);
verifyZeroInteractions(fc);
assertEquals("/timedOut", response.getRedirectedUrl());
assertThat(response.getRedirectedUrl()).isEqualTo("/timedOut");
}
@Test

Some files were not shown because too many files have changed in this diff Show More