Committed deletion of previous AuthorityUtilsTests

This commit is contained in:
Luke Taylor 2009-06-09 01:50:35 +00:00
parent 4768e4b13c
commit 4e0d3c644f
1 changed files with 0 additions and 62 deletions

View File

@ -1,62 +0,0 @@
package org.springframework.security.util;
import static org.junit.Assert.*;
import java.util.List;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
/**
* @author Luke Taylor
* @version $Id$
*/
public class AuthorityUtilsTests {
@Before
@After
public void clearContext() {
SecurityContextHolder.clearContext();
}
@Test
public void userHasAuthorityReturnsFalseForUnauthenticatedUser() {
assertFalse(AuthorityUtils.userHasAuthority("SOME_AUTHORITY"));
}
@Test
public void userHasAuthorityReturnsFalseWhenUserHasNoAuthorities() {
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken("user", "password"));
assertFalse(AuthorityUtils.userHasAuthority("SOME_AUTHORITY"));
}
@Test
public void userHasAuthorityReturnsTrueWhenUserHasCorrectAuthority() {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "password",
AuthorityUtils.createAuthorityList("A", "B")));
assertTrue(AuthorityUtils.userHasAuthority("A"));
assertTrue(AuthorityUtils.userHasAuthority("B"));
assertFalse(AuthorityUtils.userHasAuthority("C"));
}
@Test
public void commaSeparatedStringIsParsedCorrectly() {
List<GrantedAuthority> authorityArray =
AuthorityUtils.commaSeparatedStringToAuthorityList(" ROLE_A, B, C, ROLE_D\n,\n E ");
Set<String> authorities = AuthorityUtils.authorityListToSet(authorityArray);
assertTrue(authorities.contains("B"));
assertTrue(authorities.contains("C"));
assertTrue(authorities.contains("E"));
assertTrue(authorities.contains("ROLE_A"));
assertTrue(authorities.contains("ROLE_D"));
}
}