Taglib test fixes to take latest SFW changes into account.

This commit is contained in:
Luke Taylor 2011-08-11 23:44:01 +01:00
parent a087e828a6
commit 594ee9515e
4 changed files with 14 additions and 14 deletions

View File

@ -150,7 +150,6 @@ public class AuthenticationTag extends TagSupport {
/** /**
* Return the HTML escaping setting for this tag, * Return the HTML escaping setting for this tag,
* or the default setting if not overridden. * or the default setting if not overridden.
* @see #isDefaultHtmlEscape()
*/ */
protected boolean isHtmlEscape() { protected boolean isHtmlEscape() {
return htmlEscape; return htmlEscape;

View File

@ -22,6 +22,8 @@ import javax.servlet.jsp.tagext.Tag;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.authority.AuthorityUtils;
@ -131,6 +133,7 @@ public class AuthenticationTagTests {
@Test @Test
public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception { public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", "")); SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
authenticationTag.setPageContext(new MockPageContext(new MockServletContext()));
authenticationTag.setProperty("name"); authenticationTag.setProperty("name");
authenticationTag.setHtmlEscape("false"); authenticationTag.setHtmlEscape("false");
authenticationTag.doStartTag(); authenticationTag.doStartTag();

View File

@ -18,6 +18,8 @@ package org.springframework.security.taglibs.authz;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl; import org.springframework.security.core.authority.GrantedAuthorityImpl;
@ -29,7 +31,6 @@ import javax.servlet.jsp.tagext.Tag;
/** /**
* DOCUMENT ME!
* *
* @author Francois Beausoleil * @author Francois Beausoleil
*/ */
@ -42,7 +43,7 @@ public class AuthorizeTagAttributeTests extends TestCase {
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); authorizeTag.setPageContext(new MockPageContext(new MockServletContext()));
currentUser = new TestingAuthenticationToken("abc", "123", currentUser = new TestingAuthenticationToken("abc", "123",
new GrantedAuthority[] { new GrantedAuthority[] {
@ -75,21 +76,18 @@ public class AuthorizeTagAttributeTests extends TestCase {
assertEquals("prevents request - principal has ROLE_RESTRICTED", Tag.SKIP_BODY, authorizeTag.doStartTag()); assertEquals("prevents request - principal has ROLE_RESTRICTED", Tag.SKIP_BODY, authorizeTag.doStartTag());
} }
public void testAssertsIfNotGrantedIgnoresWhitespaceInAttribute() public void testAssertsIfNotGrantedIgnoresWhitespaceInAttribute() throws JspException {
throws JspException {
authorizeTag.setIfAnyGranted("\tROLE_SUPERVISOR \t, \r\n\t ROLE_TELLER "); authorizeTag.setIfAnyGranted("\tROLE_SUPERVISOR \t, \r\n\t ROLE_TELLER ");
assertEquals("allows request - principal has ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag()); assertEquals("allows request - principal has ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
} }
public void testIfAllGrantedIgnoresWhitespaceInAttribute() public void testIfAllGrantedIgnoresWhitespaceInAttribute() throws JspException {
throws JspException {
authorizeTag.setIfAllGranted("\nROLE_SUPERVISOR\t,ROLE_RESTRICTED\t\n\r "); authorizeTag.setIfAllGranted("\nROLE_SUPERVISOR\t,ROLE_RESTRICTED\t\n\r ");
assertEquals("allows request - principal has ROLE_RESTRICTED " + "and ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE, assertEquals("allows request - principal has ROLE_RESTRICTED " + "and ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE,
authorizeTag.doStartTag()); authorizeTag.doStartTag());
} }
public void testIfNotGrantedIgnoresWhitespaceInAttribute() public void testIfNotGrantedIgnoresWhitespaceInAttribute() throws JspException {
throws JspException {
authorizeTag.setIfNotGranted(" \t ROLE_TELLER \r"); authorizeTag.setIfNotGranted(" \t ROLE_TELLER \r");
assertEquals("allows request - principal does not have ROLE_TELLER", Tag.EVAL_BODY_INCLUDE, assertEquals("allows request - principal does not have ROLE_TELLER", Tag.EVAL_BODY_INCLUDE,
authorizeTag.doStartTag()); authorizeTag.doStartTag());

View File

@ -18,6 +18,8 @@ package org.springframework.security.taglibs.authz;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
@ -41,7 +43,7 @@ public class AuthorizeTagCustomGrantedAuthorityTests extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
authorizeTag.setPageContext(new MockPageContext(new MockServletContext()));
currentUser = new TestingAuthenticationToken("abc", "123", currentUser = new TestingAuthenticationToken("abc", "123",
new GrantedAuthority[] {new CustomGrantedAuthority("ROLE_TELLER")}); new GrantedAuthority[] {new CustomGrantedAuthority("ROLE_TELLER")});
@ -52,14 +54,12 @@ public class AuthorizeTagCustomGrantedAuthorityTests extends TestCase {
SecurityContextHolder.clearContext(); SecurityContextHolder.clearContext();
} }
public void testAllowsRequestWhenCustomAuthorityPresentsCorrectRole() public void testAllowsRequestWhenCustomAuthorityPresentsCorrectRole() throws JspException {
throws JspException {
authorizeTag.setIfAnyGranted("ROLE_TELLER"); authorizeTag.setIfAnyGranted("ROLE_TELLER");
assertEquals("authorized - ROLE_TELLER in both sets", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag()); assertEquals("authorized - ROLE_TELLER in both sets", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
} }
public void testRejectsRequestWhenCustomAuthorityReturnsNull() public void testRejectsRequestWhenCustomAuthorityReturnsNull() throws JspException {
throws JspException {
authorizeTag.setIfAnyGranted("ROLE_TELLER"); authorizeTag.setIfAnyGranted("ROLE_TELLER");
SecurityContextHolder.getContext() SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken("abc", "123", .setAuthentication(new TestingAuthenticationToken("abc", "123",