Reformat code using spring-javaformat
Run `./gradlew format` to reformat all java files. Issue gh-8945
This commit is contained in:
@@ -27,9 +27,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TldTests {
|
||||
|
||||
//SEC-2324
|
||||
// SEC-2324
|
||||
@Test
|
||||
public void testTldVersionIsCorrect() throws Exception{
|
||||
public void testTldVersionIsCorrect() throws Exception {
|
||||
String SPRING_SECURITY_VERSION = "springSecurityVersion";
|
||||
|
||||
String version = System.getProperty(SPRING_SECURITY_VERSION);
|
||||
@@ -45,5 +45,4 @@ public class TldTests {
|
||||
assertThat(version).startsWith(tlibVersion);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -45,14 +45,17 @@ import org.springframework.security.web.access.expression.DefaultWebSecurityExpr
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rob Winch
|
||||
*
|
||||
*/
|
||||
public class AbstractAuthorizeTagTests {
|
||||
|
||||
private AbstractAuthorizeTag tag;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
private MockServletContext servletContext;
|
||||
|
||||
@Before
|
||||
@@ -73,8 +76,7 @@ public class AbstractAuthorizeTagTests {
|
||||
String uri = "/something";
|
||||
WebInvocationPrivilegeEvaluator expected = mock(WebInvocationPrivilegeEvaluator.class);
|
||||
tag.setUrl(uri);
|
||||
request.setAttribute(WebAttributes.WEB_INVOCATION_PRIVILEGE_EVALUATOR_ATTRIBUTE,
|
||||
expected);
|
||||
request.setAttribute(WebAttributes.WEB_INVOCATION_PRIVILEGE_EVALUATOR_ATTRIBUTE, expected);
|
||||
|
||||
tag.authorizeUsingUrlCheck();
|
||||
|
||||
@@ -87,7 +89,8 @@ public class AbstractAuthorizeTagTests {
|
||||
WebInvocationPrivilegeEvaluator expected = mock(WebInvocationPrivilegeEvaluator.class);
|
||||
tag.setUrl(uri);
|
||||
WebApplicationContext wac = mock(WebApplicationContext.class);
|
||||
when(wac.getBeansOfType(WebInvocationPrivilegeEvaluator.class)).thenReturn(Collections.singletonMap("wipe", expected));
|
||||
when(wac.getBeansOfType(WebInvocationPrivilegeEvaluator.class))
|
||||
.thenReturn(Collections.singletonMap("wipe", expected));
|
||||
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
tag.authorizeUsingUrlCheck();
|
||||
@@ -102,7 +105,8 @@ public class AbstractAuthorizeTagTests {
|
||||
DefaultWebSecurityExpressionHandler expected = new DefaultWebSecurityExpressionHandler();
|
||||
tag.setAccess("permitAll");
|
||||
WebApplicationContext wac = mock(WebApplicationContext.class);
|
||||
when(wac.getBeansOfType(SecurityExpressionHandler.class)).thenReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
|
||||
when(wac.getBeansOfType(SecurityExpressionHandler.class))
|
||||
.thenReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
|
||||
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
assertThat(tag.authorize()).isTrue();
|
||||
@@ -124,5 +128,7 @@ public class AbstractAuthorizeTagTests {
|
||||
protected ServletContext getServletContext() {
|
||||
return servletContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,16 +34,19 @@ import javax.servlet.jsp.tagext.Tag;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @author Rob Winch
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AccessControlListTagTests {
|
||||
|
||||
AccessControlListTag tag;
|
||||
|
||||
PermissionEvaluator pe;
|
||||
|
||||
MockPageContext pageContext;
|
||||
|
||||
Authentication bob = new TestingAuthenticationToken("bob", "bobspass", "A");
|
||||
|
||||
@Before
|
||||
@@ -60,10 +63,8 @@ public class AccessControlListTagTests {
|
||||
when(ctx.getBeansOfType(PermissionEvaluator.class)).thenReturn(beanMap);
|
||||
|
||||
MockServletContext servletCtx = new MockServletContext();
|
||||
servletCtx.setAttribute(
|
||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
|
||||
pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(),
|
||||
new MockHttpServletResponse());
|
||||
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
|
||||
pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
tag.setPageContext(pageContext);
|
||||
}
|
||||
|
||||
@@ -179,4 +180,5 @@ public class AccessControlListTagTests {
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,13 +35,15 @@ import org.springframework.security.core.userdetails.User;
|
||||
* @author Ben Alex
|
||||
*/
|
||||
public class AuthenticationTagTests {
|
||||
|
||||
// ~ Instance fields
|
||||
// ================================================================================================
|
||||
|
||||
private final MyAuthenticationTag authenticationTag = new MyAuthenticationTag();
|
||||
private final Authentication auth = new TestingAuthenticationToken(new User(
|
||||
"rodUserDetails", "koala", true, true, true, true,
|
||||
AuthorityUtils.NO_AUTHORITIES), "koala", AuthorityUtils.NO_AUTHORITIES);
|
||||
|
||||
private final Authentication auth = new TestingAuthenticationToken(
|
||||
new User("rodUserDetails", "koala", true, true, true, true, AuthorityUtils.NO_AUTHORITIES), "koala",
|
||||
AuthorityUtils.NO_AUTHORITIES);
|
||||
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@@ -64,8 +66,7 @@ public class AuthenticationTagTests {
|
||||
@Test
|
||||
public void testOperationWhenPrincipalIsAString() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("rodAsString", "koala",
|
||||
AuthorityUtils.NO_AUTHORITIES));
|
||||
new TestingAuthenticationToken("rodAsString", "koala", AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
authenticationTag.setProperty("principal");
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
@@ -85,9 +86,8 @@ public class AuthenticationTagTests {
|
||||
|
||||
@Test
|
||||
public void testOperationWhenPrincipalIsNull() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken(null, "koala",
|
||||
AuthorityUtils.NO_AUTHORITIES));
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
authenticationTag.setProperty("principal");
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
@@ -127,8 +127,7 @@ public class AuthenticationTagTests {
|
||||
|
||||
@Test
|
||||
public void htmlEscapingIsUsedByDefault() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("<>& ", ""));
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
|
||||
authenticationTag.setProperty("name");
|
||||
authenticationTag.doStartTag();
|
||||
authenticationTag.doEndTag();
|
||||
@@ -137,8 +136,7 @@ public class AuthenticationTagTests {
|
||||
|
||||
@Test
|
||||
public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("<>& ", ""));
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
|
||||
authenticationTag.setProperty("name");
|
||||
authenticationTag.setHtmlEscape("false");
|
||||
authenticationTag.doStartTag();
|
||||
@@ -150,6 +148,7 @@ public class AuthenticationTagTests {
|
||||
// ==================================================================================================
|
||||
|
||||
private class MyAuthenticationTag extends AuthenticationTag {
|
||||
|
||||
String lastMessage = null;
|
||||
|
||||
public String getLastMessage() {
|
||||
@@ -159,5 +158,7 @@ public class AuthenticationTagTests {
|
||||
protected void writeMessage(String msg) {
|
||||
lastMessage = msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,15 +48,19 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthorizeTagTests {
|
||||
|
||||
// ~ Instance fields
|
||||
// ================================================================================================
|
||||
|
||||
@Mock
|
||||
private PermissionEvaluator permissionEvaluator;
|
||||
|
||||
private JspAuthorizeTag authorizeTag;
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
private final TestingAuthenticationToken currentUser = new TestingAuthenticationToken(
|
||||
"abc", "123", "ROLE SUPERVISOR", "ROLE_TELLER");
|
||||
|
||||
private final TestingAuthenticationToken currentUser = new TestingAuthenticationToken("abc", "123",
|
||||
"ROLE SUPERVISOR", "ROLE_TELLER");
|
||||
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@@ -70,15 +74,12 @@ public class AuthorizeTagTests {
|
||||
.rootBeanDefinition(DefaultWebSecurityExpressionHandler.class);
|
||||
webExpressionHandler.addPropertyValue("permissionEvaluator", permissionEvaluator);
|
||||
|
||||
ctx.registerBeanDefinition("expressionHandler",
|
||||
webExpressionHandler.getBeanDefinition());
|
||||
ctx.registerBeanDefinition("expressionHandler", webExpressionHandler.getBeanDefinition());
|
||||
ctx.registerSingleton("wipe", MockWebInvocationPrivilegeEvaluator.class);
|
||||
MockServletContext servletCtx = new MockServletContext();
|
||||
servletCtx.setAttribute(
|
||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
|
||||
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
|
||||
authorizeTag = new JspAuthorizeTag();
|
||||
authorizeTag.setPageContext(new MockPageContext(servletCtx, request,
|
||||
new MockHttpServletResponse()));
|
||||
authorizeTag.setPageContext(new MockPageContext(servletCtx, request, new MockHttpServletResponse()));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -92,10 +93,8 @@ public class AuthorizeTagTests {
|
||||
public void taglibsDocumentationHasPermissionOr() throws Exception {
|
||||
Object domain = new Object();
|
||||
request.setAttribute("domain", domain);
|
||||
authorizeTag
|
||||
.setAccess("hasPermission(#domain,'read') or hasPermission(#domain,'write')");
|
||||
when(permissionEvaluator.hasPermission(eq(currentUser), eq(domain), anyString()))
|
||||
.thenReturn(true);
|
||||
authorizeTag.setAccess("hasPermission(#domain,'read') or hasPermission(#domain,'write')");
|
||||
when(permissionEvaluator.hasPermission(eq(currentUser), eq(domain), anyString())).thenReturn(true);
|
||||
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
@@ -154,16 +153,16 @@ public class AuthorizeTagTests {
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
public static class MockWebInvocationPrivilegeEvaluator implements
|
||||
WebInvocationPrivilegeEvaluator {
|
||||
public static class MockWebInvocationPrivilegeEvaluator implements WebInvocationPrivilegeEvaluator {
|
||||
|
||||
public boolean isAllowed(String uri, Authentication authentication) {
|
||||
return "/allowed".equals(uri);
|
||||
}
|
||||
|
||||
public boolean isAllowed(String contextPath, String uri, String method,
|
||||
Authentication authentication) {
|
||||
public boolean isAllowed(String contextPath, String uri, String method, Authentication authentication) {
|
||||
return "/allowed".equals(uri) && (method == null || "GET".equals(method));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
public class AbstractCsrfTagTests {
|
||||
|
||||
public MockTag tag;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
@Before
|
||||
@@ -45,8 +47,7 @@ public class AbstractCsrfTagTests {
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
this.request = new MockHttpServletRequest(servletContext);
|
||||
this.response = new MockHttpServletResponse();
|
||||
MockPageContext pageContext = new MockPageContext(servletContext, this.request,
|
||||
this.response);
|
||||
MockPageContext pageContext = new MockPageContext(servletContext, this.request, this.response);
|
||||
this.tag = new MockTag();
|
||||
this.tag.setPageContext(pageContext);
|
||||
}
|
||||
@@ -59,15 +60,14 @@ public class AbstractCsrfTagTests {
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.").isEqualTo("");
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasCsrfRendersReturnedValue() throws JspException,
|
||||
UnsupportedEncodingException {
|
||||
public void hasCsrfRendersReturnedValue() throws JspException, UnsupportedEncodingException {
|
||||
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf",
|
||||
"abc123def456ghi789");
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
this.request.setAttribute(CsrfToken.class.getName(), token);
|
||||
|
||||
this.tag.handleReturn = "fooBarBazQux";
|
||||
@@ -75,16 +75,15 @@ public class AbstractCsrfTagTests {
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.").isEqualTo("fooBarBazQux");
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("fooBarBazQux");
|
||||
assertThat(this.tag.token).as("The token is not correct.").isSameAs(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasCsrfRendersDifferentValue() throws JspException,
|
||||
UnsupportedEncodingException {
|
||||
public void hasCsrfRendersDifferentValue() throws JspException, UnsupportedEncodingException {
|
||||
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf",
|
||||
"abc123def456ghi789");
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
this.request.setAttribute(CsrfToken.class.getName(), token);
|
||||
|
||||
this.tag.handleReturn = "<input type=\"hidden\" />";
|
||||
@@ -92,13 +91,15 @@ public class AbstractCsrfTagTests {
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.").isEqualTo("<input type=\"hidden\" />");
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" />");
|
||||
assertThat(this.tag.token).as("The token is not correct.").isSameAs(token);
|
||||
}
|
||||
|
||||
private static class MockTag extends AbstractCsrfTag {
|
||||
|
||||
private CsrfToken token;
|
||||
|
||||
private String handleReturn;
|
||||
|
||||
@Override
|
||||
@@ -106,5 +107,7 @@ public class AbstractCsrfTagTests {
|
||||
this.token = token;
|
||||
return this.handleReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,24 +36,24 @@ public class CsrfInputTagTests {
|
||||
|
||||
@Test
|
||||
public void handleTokenReturnsHiddenInput() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf",
|
||||
"abc123def456ghi789");
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(
|
||||
value).withFailMessage("The output is not correct.").isEqualTo("<input type=\"hidden\" name=\"_csrf\" value=\"abc123def456ghi789\" />");
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" name=\"_csrf\" value=\"abc123def456ghi789\" />");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleTokenReturnsHiddenInputDifferentTokenValue() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "csrfParameter",
|
||||
"fooBarBazQux");
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "csrfParameter", "fooBarBazQux");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<input type=\"hidden\" name=\"csrfParameter\" value=\"fooBarBazQux\" />");
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" name=\"csrfParameter\" value=\"fooBarBazQux\" />");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,27 +36,28 @@ public class CsrfMetaTagsTagTests {
|
||||
|
||||
@Test
|
||||
public void handleTokenRendersTags() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf",
|
||||
"abc123def456ghi789");
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<meta name=\"_csrf_parameter\" content=\"_csrf\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"X-Csrf-Token\" />"
|
||||
+ "<meta name=\"_csrf\" content=\"abc123def456ghi789\" />");
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<meta name=\"_csrf_parameter\" content=\"_csrf\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"X-Csrf-Token\" />"
|
||||
+ "<meta name=\"_csrf\" content=\"abc123def456ghi789\" />");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleTokenRendersTagsDifferentToken() {
|
||||
CsrfToken token = new DefaultCsrfToken("csrfHeader", "csrfParameter",
|
||||
"fooBarBazQux");
|
||||
CsrfToken token = new DefaultCsrfToken("csrfHeader", "csrfParameter", "fooBarBazQux");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<meta name=\"_csrf_parameter\" content=\"csrfParameter\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"csrfHeader\" />"
|
||||
+ "<meta name=\"_csrf\" content=\"fooBarBazQux\" />");
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<meta name=\"_csrf_parameter\" content=\"csrfParameter\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"csrfHeader\" />"
|
||||
+ "<meta name=\"_csrf\" content=\"fooBarBazQux\" />");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user