Start AssertJ Migration
Issue gh-3175
This commit is contained in:
+4
-4
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.event.AuthorizationFailureEvent;
|
||||
@@ -61,8 +61,8 @@ public class AuthorizationFailureEventTests {
|
||||
public void gettersReturnCtorSuppliedData() throws Exception {
|
||||
AuthorizationFailureEvent event = new AuthorizationFailureEvent(new Object(),
|
||||
attributes, foo, exception);
|
||||
assertSame(attributes, event.getConfigAttributes());
|
||||
assertSame(exception, event.getAccessDeniedException());
|
||||
assertSame(foo, event.getAuthentication());
|
||||
assertThat(event.getConfigAttributes()).isSameAs(attributes);
|
||||
assertThat(event.getAccessDeniedException()).isSameAs(exception);
|
||||
assertThat(event.getAuthentication()).isSameAs(foo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
|
||||
package org.springframework.security.access;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
@@ -34,7 +35,7 @@ public class SecurityConfigTests {
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
SecurityConfig config = new SecurityConfig("TEST");
|
||||
Assert.assertEquals("TEST".hashCode(), config.hashCode());
|
||||
assertThat(config.hashCode()).isEqualTo("TEST".hashCode());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -56,32 +57,32 @@ public class SecurityConfigTests {
|
||||
public void testObjectEquals() throws Exception {
|
||||
SecurityConfig security1 = new SecurityConfig("TEST");
|
||||
SecurityConfig security2 = new SecurityConfig("TEST");
|
||||
Assert.assertEquals(security1, security2);
|
||||
assertThat(security2).isEqualTo(security1);
|
||||
|
||||
// SEC-311: Must observe symmetry requirement of Object.equals(Object) contract
|
||||
String securityString1 = "TEST";
|
||||
Assert.assertNotSame(security1, securityString1);
|
||||
assertThat(securityString1).isNotSameAs(security1);
|
||||
|
||||
String securityString2 = "NOT_EQUAL";
|
||||
Assert.assertTrue(!security1.equals(securityString2));
|
||||
assertThat(!security1.equals(securityString2)).isTrue();
|
||||
|
||||
SecurityConfig security3 = new SecurityConfig("NOT_EQUAL");
|
||||
Assert.assertTrue(!security1.equals(security3));
|
||||
assertThat(!security1.equals(security3)).isTrue();
|
||||
|
||||
MockConfigAttribute mock1 = new MockConfigAttribute("TEST");
|
||||
Assert.assertEquals(security1, mock1);
|
||||
assertThat(mock1).isEqualTo(security1);
|
||||
|
||||
MockConfigAttribute mock2 = new MockConfigAttribute("NOT_EQUAL");
|
||||
Assert.assertTrue(!security1.equals(mock2));
|
||||
assertThat(!security1.equals(mock2)).isTrue();
|
||||
|
||||
Integer int1 = Integer.valueOf(987);
|
||||
Assert.assertTrue(!security1.equals(int1));
|
||||
assertThat(!security1.equals(int1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
SecurityConfig config = new SecurityConfig("TEST");
|
||||
Assert.assertEquals("TEST", config.toString());
|
||||
assertThat(config.toString()).isEqualTo("TEST");
|
||||
}
|
||||
|
||||
// ~ Inner Classes
|
||||
|
||||
+25
-27
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.access.annotation;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -53,38 +52,37 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
@Test
|
||||
public void methodWithRolesAllowedHasCorrectAttribute() throws Exception {
|
||||
ConfigAttribute[] accessAttributes = findAttributes("adminMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("ROLE_ADMIN", accessAttributes[0].toString());
|
||||
assertThat(accessAttributes.length).isEqualTo(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void permitAllMethodHasPermitAllAttribute() throws Exception {
|
||||
ConfigAttribute[] accessAttributes = findAttributes("permitAllMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("javax.annotation.security.PermitAll",
|
||||
accessAttributes[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("javax.annotation.security.PermitAll");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noRoleMethodHasNoAttributes() throws Exception {
|
||||
Collection<ConfigAttribute> accessAttributes = mds.findAttributes(a.getClass()
|
||||
.getMethod("noRoleMethod"), null);
|
||||
Assert.assertNull(accessAttributes);
|
||||
assertThat(accessAttributes).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classRoleIsAppliedToNoRoleMethod() throws Exception {
|
||||
Collection<ConfigAttribute> accessAttributes = mds.findAttributes(userAllowed
|
||||
.getClass().getMethod("noRoleMethod"), null);
|
||||
Assert.assertNull(accessAttributes);
|
||||
assertThat(accessAttributes).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodRoleOverridesClassRole() throws Exception {
|
||||
Collection<ConfigAttribute> accessAttributes = mds.findAttributes(userAllowed
|
||||
.getClass().getMethod("adminMethod"), null);
|
||||
assertEquals(1, accessAttributes.size());
|
||||
assertEquals("ROLE_ADMIN", accessAttributes.toArray()[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,8 +90,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
mds.setDefaultRolePrefix("CUSTOMPREFIX_");
|
||||
|
||||
ConfigAttribute[] accessAttributes = findAttributes("adminMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("CUSTOMPREFIX_ADMIN", accessAttributes[0].toString());
|
||||
assertThat(accessAttributes.length).isEqualTo(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("CUSTOMPREFIX_ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,8 +99,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
mds.setDefaultRolePrefix("");
|
||||
|
||||
ConfigAttribute[] accessAttributes = findAttributes("adminMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("ADMIN", accessAttributes[0].toString());
|
||||
assertThat(accessAttributes.length).isEqualTo(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,15 +108,15 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
mds.setDefaultRolePrefix(null);
|
||||
|
||||
ConfigAttribute[] accessAttributes = findAttributes("adminMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("ADMIN", accessAttributes[0].toString());
|
||||
assertThat(accessAttributes.length).isEqualTo(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("ADMIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alreadyHasDefaultPrefix() throws Exception {
|
||||
ConfigAttribute[] accessAttributes = findAttributes("roleAdminMethod");
|
||||
assertEquals(1, accessAttributes.length);
|
||||
assertEquals("ROLE_ADMIN", accessAttributes[0].toString());
|
||||
assertThat(accessAttributes.length).isEqualTo(1);
|
||||
assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
// JSR-250 Spec Tests
|
||||
@@ -148,8 +146,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
"overriden");
|
||||
|
||||
Collection<ConfigAttribute> accessAttributes = mds.getAttributes(mi);
|
||||
assertEquals(1, accessAttributes.size());
|
||||
assertEquals("ROLE_DERIVED", accessAttributes.toArray()[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_DERIVED");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,8 +157,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
"defaults");
|
||||
|
||||
Collection<ConfigAttribute> accessAttributes = mds.getAttributes(mi);
|
||||
assertEquals(1, accessAttributes.size());
|
||||
assertEquals("ROLE_DERIVED", accessAttributes.toArray()[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_DERIVED");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,8 +168,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
"explicitMethod");
|
||||
|
||||
Collection<ConfigAttribute> accessAttributes = mds.getAttributes(mi);
|
||||
assertEquals(1, accessAttributes.size());
|
||||
assertEquals("ROLE_EXPLICIT", accessAttributes.toArray()[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_EXPLICIT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,8 +204,8 @@ public class Jsr250MethodSecurityMetadataSourceTests {
|
||||
"overridenIgnored");
|
||||
|
||||
Collection<ConfigAttribute> accessAttributes = mds.getAttributes(mi);
|
||||
assertEquals(1, accessAttributes.size());
|
||||
assertEquals("ROLE_DERIVED", accessAttributes.toArray()[0].toString());
|
||||
assertThat(accessAttributes).hasSize(1);
|
||||
assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_DERIVED");
|
||||
}
|
||||
|
||||
// ~ Inner Classes
|
||||
|
||||
+11
-11
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,19 +27,19 @@ public class Jsr250VoterTests {
|
||||
attrs.add(new Jsr250SecurityConfig("B"));
|
||||
attrs.add(new Jsr250SecurityConfig("C"));
|
||||
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "A"), new Object(), attrs));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "B"), new Object(), attrs));
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "C"), new Object(), attrs));
|
||||
assertThat(voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "A"), new Object(), attrs)).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
assertThat(voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "B"), new Object(), attrs)).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
assertThat(voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "C"), new Object(), attrs)).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(
|
||||
assertThat(voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "NONE"), new Object(),
|
||||
attrs));
|
||||
attrs)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
|
||||
|
||||
assertEquals(AccessDecisionVoter.ACCESS_ABSTAIN, voter.vote(
|
||||
assertThat(voter.vote(
|
||||
new TestingAuthenticationToken("user", "pwd", "A"), new Object(),
|
||||
SecurityConfig.createList("A", "B", "C")));
|
||||
SecurityConfig.createList("A", "B", "C"))).isEqualTo(AccessDecisionVoter.ACCESS_ABSTAIN);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -14,11 +14,11 @@
|
||||
*/
|
||||
package org.springframework.security.access.annotation;
|
||||
|
||||
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.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
@@ -71,14 +71,14 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
Collection<ConfigAttribute> attrs = mds.findAttributes(method,
|
||||
DepartmentServiceImpl.class);
|
||||
|
||||
assertNotNull(attrs);
|
||||
assertThat(attrs).isNotNull();
|
||||
|
||||
// expect 1 attribute
|
||||
assertTrue("Did not find 1 attribute", attrs.size() == 1);
|
||||
assertThat(attrs.size() == 1).as("Did not find 1 attribute").isTrue();
|
||||
|
||||
// should have 1 SecurityConfig
|
||||
for (ConfigAttribute sc : attrs) {
|
||||
assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute());
|
||||
assertThat(sc.getAttribute()).as("Found an incorrect role").isEqualTo("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
Method superMethod = null;
|
||||
@@ -94,14 +94,14 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
Collection<ConfigAttribute> superAttrs = this.mds.findAttributes(superMethod,
|
||||
DepartmentServiceImpl.class);
|
||||
|
||||
assertNotNull(superAttrs);
|
||||
assertThat(superAttrs).isNotNull();
|
||||
|
||||
// This part of the test relates to SEC-274
|
||||
// expect 1 attribute
|
||||
assertEquals("Did not find 1 attribute", 1, superAttrs.size());
|
||||
assertThat(superAttrs).as("Did not find 1 attribute").hasSize(1);
|
||||
// should have 1 SecurityConfig
|
||||
for (ConfigAttribute sc : superAttrs) {
|
||||
assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute());
|
||||
assertThat(sc.getAttribute()).as("Found an incorrect role").isEqualTo("ROLE_ADMIN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,15 +110,15 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
Collection<ConfigAttribute> attrs = this.mds
|
||||
.findAttributes(BusinessService.class);
|
||||
|
||||
assertNotNull(attrs);
|
||||
assertThat(attrs).isNotNull();
|
||||
|
||||
// expect 1 annotation
|
||||
assertEquals(1, attrs.size());
|
||||
assertThat(attrs).hasSize(1);
|
||||
|
||||
// should have 1 SecurityConfig
|
||||
SecurityConfig sc = (SecurityConfig) attrs.toArray()[0];
|
||||
|
||||
assertEquals("ROLE_USER", sc.getAttribute());
|
||||
assertThat(sc.getAttribute()).isEqualTo("ROLE_USER");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,17 +136,17 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
Collection<ConfigAttribute> attrs = this.mds.findAttributes(method,
|
||||
BusinessService.class);
|
||||
|
||||
assertNotNull(attrs);
|
||||
assertThat(attrs).isNotNull();
|
||||
|
||||
// expect 2 attributes
|
||||
assertEquals(2, attrs.size());
|
||||
assertThat(attrs).hasSize(2);
|
||||
|
||||
boolean user = false;
|
||||
boolean admin = false;
|
||||
|
||||
// should have 2 SecurityConfigs
|
||||
for (ConfigAttribute sc : attrs) {
|
||||
assertTrue(sc instanceof SecurityConfig);
|
||||
assertThat(sc instanceof SecurityConfig).isTrue();
|
||||
|
||||
if (sc.getAttribute().equals("ROLE_USER")) {
|
||||
user = true;
|
||||
@@ -157,7 +157,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
}
|
||||
|
||||
// expect to have ROLE_USER and ROLE_ADMIN
|
||||
assertTrue(user && admin);
|
||||
assertThat(user && admin).isTrue();
|
||||
}
|
||||
|
||||
// SEC-1491
|
||||
@@ -167,8 +167,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
new CustomSecurityAnnotationMetadataExtractor());
|
||||
Collection<ConfigAttribute> attrs = mds
|
||||
.findAttributes(CustomAnnotatedService.class);
|
||||
assertEquals(1, attrs.size());
|
||||
assertEquals(SecurityEnum.ADMIN, attrs.toArray()[0]);
|
||||
assertThat(attrs).hasSize(1);
|
||||
assertThat(attrs.toArray()[0]).isEqualTo(SecurityEnum.ADMIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,8 +180,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertEquals("CUSTOM", attrs[0].getAttribute());
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,8 +193,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertEquals("CUSTOM", attrs[0].getAttribute());
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,8 +205,8 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertEquals("CUSTOM", attrs[0].getAttribute());
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0].getAttribute()).isEqualTo("CUSTOM");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,7 +214,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
||||
MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation();
|
||||
Collection<ConfigAttribute> attributes = mds.getAttributes(mi);
|
||||
assertThat(attributes.size()).isEqualTo(1);
|
||||
assertThat(attributes).onProperty("attribute").containsOnly("ROLE_PERSON");
|
||||
assertThat(attributes).extracting("attribute").containsOnly("ROLE_PERSON");
|
||||
}
|
||||
|
||||
// Inner classes
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
package org.springframework.security.access.expression;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -37,8 +38,8 @@ public class AbstractSecurityExpressionHandlerTests {
|
||||
|
||||
Expression expression = handler.getExpressionParser().parseExpression(
|
||||
"@number10.compareTo(@number20) < 0");
|
||||
assertTrue((Boolean) expression.getValue(handler.createEvaluationContext(
|
||||
mock(Authentication.class), new Object())));
|
||||
assertThat(expression.getValue(handler.createEvaluationContext(
|
||||
mock(Authentication.class), new Object()))).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -50,7 +51,7 @@ public class AbstractSecurityExpressionHandlerTests {
|
||||
public void setExpressionParser() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
handler.setExpressionParser(parser);
|
||||
assertTrue(parser == handler.getExpressionParser());
|
||||
assertThat(parser == handler.getExpressionParser()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -1,9 +1,9 @@
|
||||
package org.springframework.security.access.expression;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.fest.assertions.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -35,10 +35,10 @@ public class SecurityExpressionRootTests {
|
||||
|
||||
@Test
|
||||
public void denyAllIsFalsePermitAllTrue() throws Exception {
|
||||
assertFalse(root.denyAll());
|
||||
assertFalse(root.denyAll);
|
||||
assertTrue(root.permitAll());
|
||||
assertTrue(root.permitAll);
|
||||
assertThat(root.denyAll()).isFalse();
|
||||
assertThat(root.denyAll).isFalse();
|
||||
assertThat(root.permitAll()).isTrue();
|
||||
assertThat(root.permitAll).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,8 +46,8 @@ public class SecurityExpressionRootTests {
|
||||
AuthenticationTrustResolver atr = mock(AuthenticationTrustResolver.class);
|
||||
root.setTrustResolver(atr);
|
||||
when(atr.isRememberMe(JOE)).thenReturn(true);
|
||||
assertTrue(root.isRememberMe());
|
||||
assertFalse(root.isFullyAuthenticated());
|
||||
assertThat(root.isRememberMe()).isTrue();
|
||||
assertThat(root.isFullyAuthenticated()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,13 +59,13 @@ public class SecurityExpressionRootTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(root.hasRole("C"));
|
||||
assertTrue(root.hasAuthority("ROLE_C"));
|
||||
assertFalse(root.hasRole("A"));
|
||||
assertFalse(root.hasRole("B"));
|
||||
assertTrue(root.hasAnyRole("C", "A", "B"));
|
||||
assertTrue(root.hasAnyAuthority("ROLE_C", "ROLE_A", "ROLE_B"));
|
||||
assertFalse(root.hasAnyRole("A", "B"));
|
||||
assertThat(root.hasRole("C")).isTrue();
|
||||
assertThat(root.hasAuthority("ROLE_C")).isTrue();
|
||||
assertThat(root.hasRole("A")).isFalse();
|
||||
assertThat(root.hasRole("B")).isFalse();
|
||||
assertThat(root.hasAnyRole("C", "A", "B")).isTrue();
|
||||
assertThat(root.hasAnyAuthority("ROLE_C", "ROLE_A", "ROLE_B")).isTrue();
|
||||
assertThat(root.hasAnyRole("A", "B")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+18
-18
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.expression.method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -28,9 +28,9 @@ public class MethodExpressionVoterTests {
|
||||
public void hasRoleExpressionAllowsUserWithRole() throws Exception {
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingAnArray());
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, mi,
|
||||
assertThat(am.vote(joe, mi,
|
||||
createAttributes(new PreInvocationExpressionAttribute(null, null,
|
||||
"hasRole('blah')"))));
|
||||
"hasRole('blah')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,16 +39,17 @@ public class MethodExpressionVoterTests {
|
||||
cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingAnArray());
|
||||
assertEquals(AccessDecisionVoter.ACCESS_DENIED, am.vote(joe, mi, cad));
|
||||
assertThat(am.vote(joe, mi, cad)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchingArgAgainstAuthenticationNameIsSuccessful() throws Exception {
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingAString(), "joe");
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, mi,
|
||||
assertThat(am.vote(joe, mi,
|
||||
createAttributes(new PreInvocationExpressionAttribute(null, null,
|
||||
"(#argument == principal) and (principal == 'joe')"))));
|
||||
"(#argument == principal) and (principal == 'joe')"))))
|
||||
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,11 +57,12 @@ public class MethodExpressionVoterTests {
|
||||
Collection arg = createCollectionArg("joe", "bob", "sam");
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingACollection(), arg);
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, mi,
|
||||
assertThat(am.vote(joe, mi,
|
||||
createAttributes(new PreInvocationExpressionAttribute(
|
||||
"(filterObject == 'jim')", "collection", null))));
|
||||
"(filterObject == 'jim')", "collection", null))))
|
||||
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
// All objects should have been removed, because the expression is always false
|
||||
assertEquals(0, arg.size());
|
||||
assertThat(arg).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +73,7 @@ public class MethodExpressionVoterTests {
|
||||
am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(
|
||||
"(filterObject == 'joe' or filterObject == 'sam')", "collection",
|
||||
"permitAll")));
|
||||
assertEquals("joe and sam should still be in the list", 2, arg.size());
|
||||
assertEquals("joe", arg.get(0));
|
||||
assertEquals("sam", arg.get(1));
|
||||
assertThat(arg).containsExactly("joe","sam");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -104,12 +104,12 @@ public class MethodExpressionVoterTests {
|
||||
public void ruleDefinedInAClassMethodIsApplied() throws Exception {
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingAString(), "joe");
|
||||
assertEquals(
|
||||
AccessDecisionVoter.ACCESS_GRANTED,
|
||||
am.vote(joe,
|
||||
mi,
|
||||
createAttributes(new PreInvocationExpressionAttribute(null, null,
|
||||
"T(org.springframework.security.access.expression.method.SecurityRules).isJoe(#argument)"))));
|
||||
assertThat(
|
||||
|
||||
am.vote(joe, mi,
|
||||
createAttributes(new PreInvocationExpressionAttribute(null, null,
|
||||
"T(org.springframework.security.access.expression.method.SecurityRules).isJoe(#argument)"))))
|
||||
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
}
|
||||
|
||||
private List<ConfigAttribute> createAttributes(ConfigAttribute... attributes) {
|
||||
|
||||
+12
-12
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.expression.method;
|
||||
|
||||
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.*;
|
||||
@@ -44,19 +44,19 @@ public class MethodSecurityExpressionRootTests {
|
||||
ctx.setVariable("var", "somestring");
|
||||
Expression e = parser.parseExpression("#var.length() == 10");
|
||||
|
||||
assertTrue(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAnonymousReturnsTrueIfTrustResolverReportsAnonymous() {
|
||||
when(trustResolver.isAnonymous(user)).thenReturn(true);
|
||||
assertTrue(root.isAnonymous());
|
||||
assertThat(root.isAnonymous()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAnonymousReturnsFalseIfTrustResolverReportsNonAnonymous() {
|
||||
when(trustResolver.isAnonymous(user)).thenReturn(false);
|
||||
assertFalse(root.isAnonymous());
|
||||
assertThat(root.isAnonymous()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class MethodSecurityExpressionRootTests {
|
||||
root.setPermissionEvaluator(pe);
|
||||
when(pe.hasPermission(user, dummyDomainObject, "ignored")).thenReturn(false);
|
||||
|
||||
assertFalse(root.hasPermission(dummyDomainObject, "ignored"));
|
||||
assertThat(root.hasPermission(dummyDomainObject, "ignored")).isFalse();
|
||||
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class MethodSecurityExpressionRootTests {
|
||||
root.setPermissionEvaluator(pe);
|
||||
when(pe.hasPermission(user, dummyDomainObject, "ignored")).thenReturn(true);
|
||||
|
||||
assertTrue(root.hasPermission(dummyDomainObject, "ignored"));
|
||||
assertThat(root.hasPermission(dummyDomainObject, "ignored")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,13 +95,13 @@ public class MethodSecurityExpressionRootTests {
|
||||
|
||||
Expression e = parser.parseExpression("hasPermission(#domainObject, 0xA)");
|
||||
// evaluator returns true
|
||||
assertTrue(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isTrue();
|
||||
e = parser.parseExpression("hasPermission(#domainObject, 10)");
|
||||
// evaluator returns true
|
||||
assertTrue(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isTrue();
|
||||
e = parser.parseExpression("hasPermission(#domainObject, 0xFF)");
|
||||
// evaluator returns false, make sure return value matches
|
||||
assertFalse(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,11 +119,11 @@ public class MethodSecurityExpressionRootTests {
|
||||
when(pe.hasPermission(user, "x", i)).thenReturn(true);
|
||||
|
||||
Expression e = parser.parseExpression("hasPermission(this, 2)");
|
||||
assertTrue(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isTrue();
|
||||
e = parser.parseExpression("hasPermission(this, 2)");
|
||||
assertFalse(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isFalse();
|
||||
|
||||
e = parser.parseExpression("hasPermission(this.x, 2)");
|
||||
assertTrue(ExpressionUtils.evaluateAsBoolean(e, ctx));
|
||||
assertThat(ExpressionUtils.evaluateAsBoolean(e, ctx)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+37
-48
@@ -1,10 +1,6 @@
|
||||
package org.springframework.security.access.expression.method;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
@@ -78,12 +74,12 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("someExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNull(pre.getFilterExpression());
|
||||
assertThat(pre.getAuthorizeExpression()).isNotNull();
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression");
|
||||
assertThat(pre.getFilterExpression()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,13 +87,12 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertEquals("someExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertEquals("somePreFilterExpression", pre.getFilterExpression()
|
||||
.getExpressionString());
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression");
|
||||
assertThat(pre.getFilterExpression()).isNotNull();
|
||||
assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,13 +100,12 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl3).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertEquals("permitAll", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertEquals("somePreFilterExpression", pre.getFilterExpression()
|
||||
.getExpressionString());
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll");
|
||||
assertThat(pre.getFilterExpression()).isNotNull();
|
||||
assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,15 +113,14 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(listImpl1).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(2, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertTrue(attrs[1] instanceof PostInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(2);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
assertThat(attrs[1] instanceof PostInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
PostInvocationExpressionAttribute post = (PostInvocationExpressionAttribute) attrs[1];
|
||||
assertEquals("permitAll", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(post.getFilterExpression());
|
||||
assertEquals("somePostFilterExpression", post.getFilterExpression()
|
||||
.getExpressionString());
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll");
|
||||
assertThat(post.getFilterExpression()).isNotNull();
|
||||
assertThat(post.getFilterExpression().getExpressionString()).isEqualTo("somePostFilterExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,15 +128,13 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(notherListImpl1).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("interfaceMethodAuthzExpression", pre.getAuthorizeExpression()
|
||||
.getExpressionString());
|
||||
assertEquals("interfacePreFilterExpression", pre.getFilterExpression()
|
||||
.getExpressionString());
|
||||
assertThat(pre.getFilterExpression()).isNotNull();
|
||||
assertThat(pre.getAuthorizeExpression()).isNotNull();
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression");
|
||||
assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("interfacePreFilterExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,15 +142,13 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(notherListImpl2).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue();
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("interfaceMethodAuthzExpression", pre.getAuthorizeExpression()
|
||||
.getExpressionString());
|
||||
assertEquals("classMethodPreFilterExpression", pre.getFilterExpression()
|
||||
.getExpressionString());
|
||||
assertThat(pre.getFilterExpression()).isNotNull();
|
||||
assertThat(pre.getAuthorizeExpression()).isNotNull();
|
||||
assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression");
|
||||
assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("classMethodPreFilterExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,7 +156,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,7 +164,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +172,7 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray(
|
||||
new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.length);
|
||||
assertThat(attrs.length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -22,13 +22,13 @@ public class RoleHierarchyAuthoritiesMapperTests {
|
||||
Collection<? extends GrantedAuthority> authorities = mapper
|
||||
.mapAuthorities(AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_D"));
|
||||
|
||||
assertEquals(4, authorities.size());
|
||||
assertThat(authorities).hasSize(4);
|
||||
|
||||
mapper = new RoleHierarchyAuthoritiesMapper(new NullRoleHierarchy());
|
||||
|
||||
authorities = mapper.mapAuthorities(AuthorityUtils.createAuthorityList("ROLE_A",
|
||||
"ROLE_D"));
|
||||
|
||||
assertEquals(2, authorities.size());
|
||||
assertThat(authorities).hasSize(2);
|
||||
}
|
||||
}
|
||||
|
||||
core/src/test/java/org/springframework/security/access/hierarchicalroles/RoleHierarchyImplTests.java
Executable → Regular
+7
-6
@@ -14,6 +14,9 @@
|
||||
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,12 +41,10 @@ public class RoleHierarchyImplTests extends TestCase {
|
||||
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
|
||||
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
|
||||
|
||||
assertNotNull(roleHierarchyImpl.getReachableGrantedAuthorities(authorities0));
|
||||
assertEquals(0, roleHierarchyImpl.getReachableGrantedAuthorities(authorities0)
|
||||
.size());
|
||||
assertNotNull(roleHierarchyImpl.getReachableGrantedAuthorities(authorities1));
|
||||
assertEquals(0, roleHierarchyImpl.getReachableGrantedAuthorities(authorities1)
|
||||
.size());
|
||||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(authorities0)).isNotNull();
|
||||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(authorities0)).isEmpty();;
|
||||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(authorities1)).isNotNull();
|
||||
assertThat(roleHierarchyImpl.getReachableGrantedAuthorities(authorities1)).isEmpty();;
|
||||
}
|
||||
|
||||
public void testSimpleRoleHierarchy() {
|
||||
|
||||
Executable → Regular
+62
-62
@@ -14,7 +14,7 @@
|
||||
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -45,29 +45,29 @@ public class TestHelperTests {
|
||||
List<GrantedAuthority> authorities5 = AuthorityUtils.createAuthorityList(
|
||||
"ROLE_A", "ROLE_A");
|
||||
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
null));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities1));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities2));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities2, authorities1));
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
null)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities1)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities2)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities2, authorities1)).isTrue();
|
||||
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, null));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities3));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities3, authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities4));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities5));
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, null)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities3)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities3, authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities4)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities5)).isFalse();
|
||||
}
|
||||
|
||||
// SEC-863
|
||||
@@ -103,25 +103,25 @@ public class TestHelperTests {
|
||||
authoritiesStrings5.add("ROLE_A");
|
||||
authoritiesStrings5.add("ROLE_A");
|
||||
|
||||
assertTrue(CollectionUtils.isEqualCollection(
|
||||
assertThat(CollectionUtils.isEqualCollection(
|
||||
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities1),
|
||||
authoritiesStrings1));
|
||||
authoritiesStrings1)).isTrue();
|
||||
|
||||
assertTrue(CollectionUtils.isEqualCollection(
|
||||
assertThat(CollectionUtils.isEqualCollection(
|
||||
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities2),
|
||||
authoritiesStrings2));
|
||||
authoritiesStrings2)).isTrue();
|
||||
|
||||
assertTrue(CollectionUtils.isEqualCollection(
|
||||
assertThat(CollectionUtils.isEqualCollection(
|
||||
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities3),
|
||||
authoritiesStrings3));
|
||||
authoritiesStrings3)).isTrue();
|
||||
|
||||
assertTrue(CollectionUtils.isEqualCollection(
|
||||
assertThat(CollectionUtils.isEqualCollection(
|
||||
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities4),
|
||||
authoritiesStrings4));
|
||||
authoritiesStrings4)).isTrue();
|
||||
|
||||
assertTrue(CollectionUtils.isEqualCollection(
|
||||
assertThat(CollectionUtils.isEqualCollection(
|
||||
HierarchicalRolesTestHelper.toCollectionOfAuthorityStrings(authorities5),
|
||||
authoritiesStrings5));
|
||||
authoritiesStrings5)).isTrue();
|
||||
}
|
||||
|
||||
// SEC-863
|
||||
@@ -138,29 +138,29 @@ public class TestHelperTests {
|
||||
List<GrantedAuthority> authorities5 = AuthorityUtils.createAuthorityList(
|
||||
"ROLE_A", "ROLE_A");
|
||||
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
null));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities1));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities2));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities2, authorities1));
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
null)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities1)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities2)).isTrue();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities2, authorities1)).isTrue();
|
||||
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, null));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities3));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities3, authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities4));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities1));
|
||||
assertFalse(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities5));
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(null,
|
||||
authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, null)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities3)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities3, authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities1, authorities4)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities1)).isFalse();
|
||||
assertThat(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(
|
||||
authorities4, authorities5)).isFalse();
|
||||
}
|
||||
|
||||
// SEC-863
|
||||
@@ -170,9 +170,9 @@ public class TestHelperTests {
|
||||
.createAuthorityList("ROLE_A", "ROLE_B");
|
||||
List<GrantedAuthority> authorities2 = AuthorityUtils.createAuthorityList(
|
||||
"ROLE_A", "ROLE_B");
|
||||
assertTrue(HierarchicalRolesTestHelper
|
||||
assertThat(HierarchicalRolesTestHelper
|
||||
.containTheSameGrantedAuthoritiesCompareByAuthorityString(authorities1,
|
||||
authorities2));
|
||||
authorities2)).isTrue();
|
||||
}
|
||||
|
||||
// SEC-863
|
||||
@@ -180,13 +180,13 @@ public class TestHelperTests {
|
||||
public void testCreateAuthorityList() {
|
||||
List<GrantedAuthority> authorities1 = HierarchicalRolesTestHelper
|
||||
.createAuthorityList("ROLE_A");
|
||||
assertEquals(authorities1.size(), 1);
|
||||
assertEquals("ROLE_A", authorities1.get(0).getAuthority());
|
||||
assertThat(1).isEqualTo(authorities1.size());
|
||||
assertThat(authorities1.get(0).getAuthority()).isEqualTo("ROLE_A");
|
||||
|
||||
List<GrantedAuthority> authorities2 = HierarchicalRolesTestHelper
|
||||
.createAuthorityList("ROLE_A", "ROLE_C");
|
||||
assertEquals(authorities2.size(), 2);
|
||||
assertEquals("ROLE_A", authorities2.get(0).getAuthority());
|
||||
assertEquals("ROLE_C", authorities2.get(1).getAuthority());
|
||||
assertThat(2).isEqualTo(authorities2.size());
|
||||
assertThat(authorities2.get(0).getAuthority()).isEqualTo("ROLE_A");
|
||||
assertThat(authorities2.get(1).getAuthority()).isEqualTo("ROLE_C");
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -51,7 +53,7 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
list.add(new MockAfterInvocationProvider("swap3", MethodInvocation.class,
|
||||
new SecurityConfig("GIVE_ME_SWAP3")));
|
||||
manager.setProviders(list);
|
||||
assertEquals(list, manager.getProviders());
|
||||
assertThat(manager.getProviders()).isEqualTo(list);
|
||||
manager.afterPropertiesSet();
|
||||
|
||||
List<ConfigAttribute> attr1 = SecurityConfig
|
||||
@@ -65,20 +67,20 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
List<ConfigAttribute> attr4 = SecurityConfig
|
||||
.createList(new String[] { "NEVER_CAUSES_SWAP" });
|
||||
|
||||
assertEquals("swap1", manager.decide(null, new SimpleMethodInvocation(), attr1,
|
||||
"content-before-swapping"));
|
||||
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr1,
|
||||
"content-before-swapping")).isEqualTo("swap1");
|
||||
|
||||
assertEquals("swap2", manager.decide(null, new SimpleMethodInvocation(), attr2,
|
||||
"content-before-swapping"));
|
||||
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr2,
|
||||
"content-before-swapping")).isEqualTo("swap2");
|
||||
|
||||
assertEquals("swap3", manager.decide(null, new SimpleMethodInvocation(), attr3,
|
||||
"content-before-swapping"));
|
||||
assertThat(manager.decide(null, new SimpleMethodInvocation(), attr3,
|
||||
"content-before-swapping")).isEqualTo("swap3");
|
||||
|
||||
assertEquals("content-before-swapping", manager.decide(null,
|
||||
new SimpleMethodInvocation(), attr4, "content-before-swapping"));
|
||||
assertThat(manager.decide(null,
|
||||
new SimpleMethodInvocation(), attr4, "content-before-swapping")).isEqualTo("content-before-swapping");
|
||||
|
||||
assertEquals("swap3", manager.decide(null, new SimpleMethodInvocation(),
|
||||
attr2and3, "content-before-swapping"));
|
||||
assertThat(manager.decide(null, new SimpleMethodInvocation(),
|
||||
attr2and3, "content-before-swapping")).isEqualTo("swap3");
|
||||
}
|
||||
|
||||
public void testRejectsEmptyProvidersList() {
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,9 +41,9 @@ public class InterceptorStatusTokenTests {
|
||||
SecurityContext ctx = SecurityContextHolder.createEmptyContext();
|
||||
InterceptorStatusToken token = new InterceptorStatusToken(ctx, true, attr, mi);
|
||||
|
||||
assertTrue(token.isContextHolderRefreshRequired());
|
||||
assertEquals(attr, token.getAttributes());
|
||||
assertEquals(mi, token.getSecureObject());
|
||||
assertSame(ctx, token.getSecurityContext());
|
||||
assertThat(token.isContextHolderRefreshRequired()).isTrue();
|
||||
assertThat(token.getAttributes()).isEqualTo(attr);
|
||||
assertThat(token.getSecureObject()).isEqualTo(mi);
|
||||
assertThat(token.getSecurityContext()).isSameAs(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.access.SecurityConfig;
|
||||
@@ -35,16 +37,16 @@ public class NullRunAsManagerTests extends TestCase {
|
||||
|
||||
public void testAlwaysReturnsNull() {
|
||||
NullRunAsManager runAs = new NullRunAsManager();
|
||||
assertNull(runAs.buildRunAs(null, null, null));
|
||||
assertThat(runAs.buildRunAs(null, null, null)).isNull();
|
||||
}
|
||||
|
||||
public void testAlwaysSupportsClass() {
|
||||
NullRunAsManager runAs = new NullRunAsManager();
|
||||
assertTrue(runAs.supports(String.class));
|
||||
assertThat(runAs.supports(String.class)).isTrue();
|
||||
}
|
||||
|
||||
public void testNeverSupportsAttribute() {
|
||||
NullRunAsManager runAs = new NullRunAsManager();
|
||||
assertFalse(runAs.supports(new SecurityConfig("X")));
|
||||
assertThat(runAs.supports(new SecurityConfig("X"))).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
@@ -54,7 +54,7 @@ public class RunAsImplAuthenticationProviderTests {
|
||||
result instanceof RunAsUserToken);
|
||||
|
||||
RunAsUserToken resultCast = (RunAsUserToken) result;
|
||||
assertEquals("my_password".hashCode(), resultCast.getKeyHash());
|
||||
assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -68,14 +68,14 @@ public class RunAsImplAuthenticationProviderTests {
|
||||
public void testStartupSuccess() throws Exception {
|
||||
RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider();
|
||||
provider.setKey("hello_world");
|
||||
assertEquals("hello_world", provider.getKey());
|
||||
assertThat(provider.getKey()).isEqualTo("hello_world");
|
||||
provider.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupports() {
|
||||
RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider();
|
||||
assertTrue(provider.supports(RunAsUserToken.class));
|
||||
assertTrue(!provider.supports(TestingAuthenticationToken.class));
|
||||
assertThat(provider.supports(RunAsUserToken.class)).isTrue();
|
||||
assertThat(!provider.supports(TestingAuthenticationToken.class)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+21
-19
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -32,7 +34,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
public class RunAsManagerImplTests extends TestCase {
|
||||
public void testAlwaysSupportsClass() {
|
||||
RunAsManagerImpl runAs = new RunAsManagerImpl();
|
||||
assertTrue(runAs.supports(String.class));
|
||||
assertThat(runAs.supports(String.class)).isTrue();
|
||||
}
|
||||
|
||||
public void testDoesNotReturnAdditionalAuthoritiesIfCalledWithoutARunAsSetting()
|
||||
@@ -46,7 +48,7 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
|
||||
Authentication resultingToken = runAs.buildRunAs(inputToken, new Object(),
|
||||
SecurityConfig.createList("SOMETHING_WE_IGNORE"));
|
||||
assertEquals(null, resultingToken);
|
||||
assertThat(resultingToken).isEqualTo(null);
|
||||
}
|
||||
|
||||
public void testRespectsRolePrefix() throws Exception {
|
||||
@@ -62,17 +64,17 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
|
||||
assertTrue("Should have returned a RunAsUserToken",
|
||||
result instanceof RunAsUserToken);
|
||||
assertEquals(inputToken.getPrincipal(), result.getPrincipal());
|
||||
assertEquals(inputToken.getCredentials(), result.getCredentials());
|
||||
assertThat(result.getPrincipal()).isEqualTo(inputToken.getPrincipal());
|
||||
assertThat(result.getCredentials()).isEqualTo(inputToken.getCredentials());
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(result
|
||||
.getAuthorities());
|
||||
|
||||
assertTrue(authorities.contains("FOOBAR_RUN_AS_SOMETHING"));
|
||||
assertTrue(authorities.contains("ONE"));
|
||||
assertTrue(authorities.contains("TWO"));
|
||||
assertThat(authorities.contains("FOOBAR_RUN_AS_SOMETHING")).isTrue();
|
||||
assertThat(authorities.contains("ONE")).isTrue();
|
||||
assertThat(authorities.contains("TWO")).isTrue();
|
||||
|
||||
RunAsUserToken resultCast = (RunAsUserToken) result;
|
||||
assertEquals("my_password".hashCode(), resultCast.getKeyHash());
|
||||
assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode());
|
||||
}
|
||||
|
||||
public void testReturnsAdditionalGrantedAuthorities() throws Exception {
|
||||
@@ -90,17 +92,17 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
fail("Should have returned a RunAsUserToken");
|
||||
}
|
||||
|
||||
assertEquals(inputToken.getPrincipal(), result.getPrincipal());
|
||||
assertEquals(inputToken.getCredentials(), result.getCredentials());
|
||||
assertThat(result.getPrincipal()).isEqualTo(inputToken.getPrincipal());
|
||||
assertThat(result.getCredentials()).isEqualTo(inputToken.getCredentials());
|
||||
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(result
|
||||
.getAuthorities());
|
||||
assertTrue(authorities.contains("ROLE_RUN_AS_SOMETHING"));
|
||||
assertTrue(authorities.contains("ROLE_ONE"));
|
||||
assertTrue(authorities.contains("ROLE_TWO"));
|
||||
assertThat(authorities.contains("ROLE_RUN_AS_SOMETHING")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_ONE")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_TWO")).isTrue();
|
||||
|
||||
RunAsUserToken resultCast = (RunAsUserToken) result;
|
||||
assertEquals("my_password".hashCode(), resultCast.getKeyHash());
|
||||
assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode());
|
||||
}
|
||||
|
||||
public void testStartupDetectsMissingKey() throws Exception {
|
||||
@@ -111,7 +113,7 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,13 +121,13 @@ public class RunAsManagerImplTests extends TestCase {
|
||||
RunAsManagerImpl runAs = new RunAsManagerImpl();
|
||||
runAs.setKey("hello_world");
|
||||
runAs.afterPropertiesSet();
|
||||
assertEquals("hello_world", runAs.getKey());
|
||||
assertThat(runAs.getKey()).isEqualTo("hello_world");
|
||||
}
|
||||
|
||||
public void testSupports() throws Exception {
|
||||
RunAsManager runAs = new RunAsManagerImpl();
|
||||
assertTrue(runAs.supports(new SecurityConfig("RUN_AS_SOMETHING")));
|
||||
assertTrue(!runAs.supports(new SecurityConfig("ROLE_WHICH_IS_IGNORED")));
|
||||
assertTrue(!runAs.supports(new SecurityConfig("role_LOWER_CASE_FAILS")));
|
||||
assertThat(runAs.supports(new SecurityConfig("RUN_AS_SOMETHING"))).isTrue();
|
||||
assertThat(!runAs.supports(new SecurityConfig("ROLE_WHICH_IS_IGNORED"))).isTrue();
|
||||
assertThat(!runAs.supports(new SecurityConfig("role_LOWER_CASE_FAILS"))).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+16
-22
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept.aopalliance;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -100,11 +100,11 @@ public class MethodSecurityInterceptorTests {
|
||||
AfterInvocationManager aim = mock(AfterInvocationManager.class);
|
||||
interceptor.setRunAsManager(runAs);
|
||||
interceptor.setAfterInvocationManager(aim);
|
||||
assertEquals(adm, interceptor.getAccessDecisionManager());
|
||||
assertEquals(runAs, interceptor.getRunAsManager());
|
||||
assertEquals(authman, interceptor.getAuthenticationManager());
|
||||
assertEquals(mds, interceptor.getSecurityMetadataSource());
|
||||
assertEquals(aim, interceptor.getAfterInvocationManager());
|
||||
assertThat(interceptor.getAccessDecisionManager()).isEqualTo(adm);
|
||||
assertThat(interceptor.getRunAsManager()).isEqualTo(runAs);
|
||||
assertThat(interceptor.getAuthenticationManager()).isEqualTo(authman);
|
||||
assertThat(interceptor.getSecurityMetadataSource()).isEqualTo(mds);
|
||||
assertThat(interceptor.getAfterInvocationManager()).isEqualTo(aim);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -198,17 +198,15 @@ public class MethodSecurityInterceptorTests {
|
||||
public void callingAPublicMethodFacadeWillNotRepeatSecurityChecksWhenPassedToTheSecuredMethodItFronts() {
|
||||
mdsReturnsNull();
|
||||
String result = advisedTarget.publicMakeLowerCase("HELLO");
|
||||
assertEquals("hello Authentication empty", result);
|
||||
assertThat(result).isEqualTo("hello Authentication empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callingAPublicMethodWhenPresentingAnAuthenticationObjectDoesntChangeItsAuthenticatedProperty() {
|
||||
mdsReturnsNull();
|
||||
SecurityContextHolder.getContext().setAuthentication(token);
|
||||
assertEquals(
|
||||
"hello org.springframework.security.authentication.TestingAuthenticationToken false",
|
||||
advisedTarget.publicMakeLowerCase("HELLO"));
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(advisedTarget.publicMakeLowerCase("HELLO")).isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken false");
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@@ -235,9 +233,7 @@ public class MethodSecurityInterceptorTests {
|
||||
String result = advisedTarget.makeLowerCase("HELLO");
|
||||
|
||||
// Note we check the isAuthenticated remained true in following line
|
||||
assertEquals(
|
||||
"hello org.springframework.security.authentication.TestingAuthenticationToken true",
|
||||
result);
|
||||
assertThat(result).isEqualTo("hello org.springframework.security.authentication.TestingAuthenticationToken true");
|
||||
verify(eventPublisher).publishEvent(any(AuthorizedEvent.class));
|
||||
}
|
||||
|
||||
@@ -254,7 +250,7 @@ public class MethodSecurityInterceptorTests {
|
||||
|
||||
try {
|
||||
advisedTarget.makeUpperCase("HELLO");
|
||||
fail();
|
||||
fail("Expected Exception");
|
||||
}
|
||||
catch (AccessDeniedException expected) {
|
||||
}
|
||||
@@ -280,12 +276,10 @@ public class MethodSecurityInterceptorTests {
|
||||
.thenReturn(runAsToken);
|
||||
|
||||
String result = advisedTarget.makeUpperCase("hello");
|
||||
assertEquals(
|
||||
"HELLO org.springframework.security.access.intercept.RunAsUserToken true",
|
||||
result);
|
||||
assertThat(result).isEqualTo("HELLO org.springframework.security.access.intercept.RunAsUserToken true");
|
||||
// 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);
|
||||
}
|
||||
|
||||
// SEC-1967
|
||||
@@ -312,8 +306,8 @@ public class MethodSecurityInterceptorTests {
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationCredentialsNotFoundException.class)
|
||||
|
||||
+5
-2
@@ -15,6 +15,9 @@
|
||||
|
||||
package org.springframework.security.access.intercept.aopalliance;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -42,7 +45,7 @@ public class MethodSecurityMetadataSourceAdvisorTests extends TestCase {
|
||||
when(mds.getAttributes(method, clazz)).thenReturn(null);
|
||||
MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor(
|
||||
"", mds, "");
|
||||
assertFalse(advisor.getPointcut().getMethodMatcher().matches(method, clazz));
|
||||
assertThat(advisor.getPointcut().getMethodMatcher().matches(method, clazz)).isFalse();
|
||||
}
|
||||
|
||||
public void testAdvisorReturnsTrueWhenMethodInvocationIsDefined() throws Exception {
|
||||
@@ -54,6 +57,6 @@ public class MethodSecurityMetadataSourceAdvisorTests extends TestCase {
|
||||
SecurityConfig.createList("ROLE_A"));
|
||||
MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor(
|
||||
"", mds, "");
|
||||
assertTrue(advisor.getPointcut().getMethodMatcher().matches(method, clazz));
|
||||
assertThat(advisor.getPointcut().getMethodMatcher().matches(method, clazz)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept.aspectj;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -134,10 +134,10 @@ public class AspectJMethodSecurityInterceptorTests {
|
||||
when(joinPoint.getTarget()).thenReturn(to);
|
||||
when(joinPoint.getArgs()).thenReturn(new Object[] { "Hi" });
|
||||
MethodInvocationAdapter mia = new MethodInvocationAdapter(joinPoint);
|
||||
assertEquals("Hi", mia.getArguments()[0]);
|
||||
assertEquals(m, mia.getStaticPart());
|
||||
assertEquals(m, mia.getMethod());
|
||||
assertSame(to, mia.getThis());
|
||||
assertThat(mia.getArguments()[0]).isEqualTo("Hi");
|
||||
assertThat(mia.getStaticPart()).isEqualTo(m);
|
||||
assertThat(mia.getMethod()).isEqualTo(m);
|
||||
assertThat(mia.getThis()).isSameAs(to);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,8 +184,8 @@ public class AspectJMethodSecurityInterceptorTests {
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// SEC-1967
|
||||
@@ -211,7 +211,7 @@ public class AspectJMethodSecurityInterceptorTests {
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.intercept.method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
@@ -35,7 +35,7 @@ public class MapBasedMethodSecurityMetadataSourceTests {
|
||||
public void wildcardedMatchIsOverwrittenByMoreSpecificMatch() {
|
||||
mds.addSecureMethod(MockService.class, "some*", ROLE_A);
|
||||
mds.addSecureMethod(MockService.class, "someMethod*", ROLE_B);
|
||||
assertEquals(ROLE_B, mds.getAttributes(someMethodInteger, MockService.class));
|
||||
assertThat(mds.getAttributes(someMethodInteger, MockService.class)).isEqualTo(ROLE_B);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,8 +43,8 @@ public class MapBasedMethodSecurityMetadataSourceTests {
|
||||
mds.addSecureMethod(MockService.class, someMethodInteger, ROLE_A);
|
||||
mds.addSecureMethod(MockService.class, someMethodString, ROLE_B);
|
||||
|
||||
assertEquals(ROLE_A, mds.getAttributes(someMethodInteger, MockService.class));
|
||||
assertEquals(ROLE_B, mds.getAttributes(someMethodString, MockService.class));
|
||||
assertThat(mds.getAttributes(someMethodInteger, MockService.class)).isEqualTo(ROLE_A);
|
||||
assertThat(mds.getAttributes(someMethodString, MockService.class)).isEqualTo(ROLE_B);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept.method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -80,7 +80,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
|
||||
mipe.setSecurityInterceptor(interceptor);
|
||||
mipe.afterPropertiesSet();
|
||||
|
||||
assertTrue(mipe.isAllowed(mi, token));
|
||||
assertThat(mipe.isAllowed(mi, token)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +92,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
|
||||
mipe.setSecurityInterceptor(interceptor);
|
||||
when(mds.getAttributes(mi)).thenReturn(role);
|
||||
|
||||
assertTrue(mipe.isAllowed(mi, token));
|
||||
assertThat(mipe.isAllowed(mi, token)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +105,7 @@ public class MethodInvocationPrivilegeEvaluatorTests {
|
||||
when(mds.getAttributes(mi)).thenReturn(role);
|
||||
doThrow(new AccessDeniedException("rejected")).when(adm).decide(token, mi, role);
|
||||
|
||||
assertFalse(mipe.isAllowed(mi, token));
|
||||
assertThat(mipe.isAllowed(mi, token)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,6 +119,6 @@ public class MethodInvocationPrivilegeEvaluatorTests {
|
||||
when(mds.getAttributes(mi)).thenReturn(role);
|
||||
doThrow(new AccessDeniedException("rejected")).when(adm).decide(token, mi, role);
|
||||
|
||||
assertFalse(mipe.isAllowed(mi, token));
|
||||
assertThat(mipe.isAllowed(mi, token)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
@@ -27,13 +27,13 @@ public class DelegatingMethodSecurityMetadataSourceTests {
|
||||
.thenReturn(null);
|
||||
sources.add(delegate);
|
||||
mds = new DelegatingMethodSecurityMetadataSource(sources);
|
||||
assertSame(sources, mds.getMethodSecurityMetadataSources());
|
||||
assertTrue(mds.getAllConfigAttributes().isEmpty());
|
||||
assertThat(mds.getMethodSecurityMetadataSources()).isSameAs(sources);
|
||||
assertThat(mds.getAllConfigAttributes().isEmpty()).isTrue();
|
||||
MethodInvocation mi = new SimpleMethodInvocation(null,
|
||||
String.class.getMethod("toString"));
|
||||
assertEquals(Collections.emptyList(), mds.getAttributes(mi));
|
||||
assertThat(mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
|
||||
// Exercise the cached case
|
||||
assertEquals(Collections.emptyList(), mds.getAttributes(mi));
|
||||
assertThat(mds.getAttributes(mi)).isEqualTo(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,15 +46,14 @@ public class DelegatingMethodSecurityMetadataSourceTests {
|
||||
when(delegate.getAttributes(toString, String.class)).thenReturn(attributes);
|
||||
sources.add(delegate);
|
||||
mds = new DelegatingMethodSecurityMetadataSource(sources);
|
||||
assertSame(sources, mds.getMethodSecurityMetadataSources());
|
||||
assertTrue(mds.getAllConfigAttributes().isEmpty());
|
||||
assertThat(mds.getMethodSecurityMetadataSources()).isSameAs(sources);
|
||||
assertThat(mds.getAllConfigAttributes().isEmpty()).isTrue();
|
||||
MethodInvocation mi = new SimpleMethodInvocation("", toString);
|
||||
assertSame(attributes, mds.getAttributes(mi));
|
||||
assertThat(mds.getAttributes(mi)).isSameAs(attributes);
|
||||
// Exercise the cached case
|
||||
assertSame(attributes, mds.getAttributes(mi));
|
||||
assertTrue(mds.getAttributes(
|
||||
new SimpleMethodInvocation(null, String.class.getMethod("length")))
|
||||
.isEmpty());
|
||||
assertThat(mds.getAttributes(mi)).isSameAs(attributes);
|
||||
assertThat(mds.getAttributes(
|
||||
new SimpleMethodInvocation(null, String.class.getMethod("length")))).isEmpty();;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.prepost;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
@@ -24,17 +24,17 @@ public class PreInvocationAuthorizationAdviceVoterTests {
|
||||
|
||||
@Test
|
||||
public void supportsMethodInvocation() {
|
||||
assertTrue(voter.supports(MethodInvocation.class));
|
||||
assertThat(voter.supports(MethodInvocation.class)).isTrue();
|
||||
}
|
||||
|
||||
// SEC-2031
|
||||
@Test
|
||||
public void supportsProxyMethodInvocation() {
|
||||
assertTrue(voter.supports(ProxyMethodInvocation.class));
|
||||
assertThat(voter.supports(ProxyMethodInvocation.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMethodInvocationAdapter() {
|
||||
assertTrue(voter.supports(MethodInvocationAdapter.class));
|
||||
assertThat(voter.supports(MethodInvocationAdapter.class)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
@@ -45,9 +47,9 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
DenyAgainVoter denyVoter = new DenyAgainVoter();
|
||||
list.add(denyVoter);
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
assertTrue(!mock.isAllowIfAllAbstainDecisions()); // default
|
||||
assertThat(!mock.isAllowIfAllAbstainDecisions()).isTrue(); // default
|
||||
mock.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mock.isAllowIfAllAbstainDecisions()); // changed
|
||||
assertThat(mock.isAllowIfAllAbstainDecisions()).isTrue(); // changed
|
||||
}
|
||||
|
||||
public void testDelegatesSupportsClassRequests() throws Exception {
|
||||
@@ -57,8 +59,8 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
|
||||
assertTrue(mock.supports(String.class));
|
||||
assertTrue(!mock.supports(Integer.class));
|
||||
assertThat(mock.supports(String.class)).isTrue();
|
||||
assertThat(!mock.supports(Integer.class)).isTrue();
|
||||
}
|
||||
|
||||
public void testDelegatesSupportsRequests() throws Exception {
|
||||
@@ -71,10 +73,10 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
|
||||
ConfigAttribute attr = new SecurityConfig("DENY_AGAIN_FOR_SURE");
|
||||
assertTrue(mock.supports(attr));
|
||||
assertThat(mock.supports(attr)).isTrue();
|
||||
|
||||
ConfigAttribute badAttr = new SecurityConfig("WE_DONT_SUPPORT_THIS");
|
||||
assertTrue(!mock.supports(badAttr));
|
||||
assertThat(!mock.supports(badAttr)).isTrue();
|
||||
}
|
||||
|
||||
public void testProperlyStoresListOfVoters() throws Exception {
|
||||
@@ -84,7 +86,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
list.add(voter);
|
||||
list.add(denyVoter);
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
|
||||
assertEquals(list.size(), mock.getDecisionVoters().size());
|
||||
assertThat(mock.getDecisionVoters().size()).isEqualTo(list.size());
|
||||
}
|
||||
|
||||
public void testRejectsEmptyList() throws Exception {
|
||||
@@ -95,7 +97,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +107,13 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testRoleVoterAlwaysReturnsTrueToSupports() {
|
||||
RoleVoter rv = new RoleVoter();
|
||||
assertTrue(rv.supports(String.class));
|
||||
assertThat(rv.supports(String.class)).isTrue();
|
||||
}
|
||||
|
||||
public void testWillNotStartIfDecisionVotersNotSet() throws Exception {
|
||||
@@ -120,7 +122,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -28,8 +28,8 @@ public class AbstractAclVoterTests {
|
||||
|
||||
@Test
|
||||
public void supportsMethodInvocations() throws Exception {
|
||||
assertTrue(voter.supports(MethodInvocation.class));
|
||||
assertFalse(voter.supports(String.class));
|
||||
assertThat(voter.supports(MethodInvocation.class)).isTrue();
|
||||
assertThat(voter.supports(String.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,7 +38,7 @@ public class AbstractAclVoterTests {
|
||||
voter.setProcessDomainObjectClass(String.class);
|
||||
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
|
||||
"methodTakingAString", "The Argument");
|
||||
assertEquals("The Argument", voter.getDomainObjectInstance(mi));
|
||||
assertThat(voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +46,7 @@ public class AbstractAclVoterTests {
|
||||
voter.setProcessDomainObjectClass(String.class);
|
||||
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
|
||||
"methodTakingAListAndAString", new ArrayList<Object>(), "The Argument");
|
||||
assertEquals("The Argument", voter.getDomainObjectInstance(mi));
|
||||
assertThat(voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
+4
-3
@@ -15,7 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -97,7 +98,7 @@ public class AffirmativeBasedTests {
|
||||
public void onlyAbstainVotesDeniesAccessWithDefault() throws Exception {
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
|
||||
abstain, abstain, abstain));
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
assertThat(!mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
|
||||
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
@@ -108,7 +109,7 @@ public class AffirmativeBasedTests {
|
||||
mgr = new AffirmativeBased(Arrays.<AccessDecisionVoter<? extends Object>> asList(
|
||||
abstain, abstain, abstain));
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
assertThat(mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check changed
|
||||
|
||||
mgr.decide(user, new Object(), attrs);
|
||||
}
|
||||
|
||||
+5
-3
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -95,19 +97,19 @@ public class AuthenticatedVoterTests extends TestCase {
|
||||
fail("Expected IAE");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testSupports() {
|
||||
AuthenticatedVoter voter = new AuthenticatedVoter();
|
||||
assertTrue(voter.supports(String.class));
|
||||
assertThat(voter.supports(String.class)).isTrue();
|
||||
assertTrue(voter.supports(new SecurityConfig(
|
||||
AuthenticatedVoter.IS_AUTHENTICATED_ANONYMOUSLY)));
|
||||
assertTrue(voter.supports(new SecurityConfig(
|
||||
AuthenticatedVoter.IS_AUTHENTICATED_FULLY)));
|
||||
assertTrue(voter.supports(new SecurityConfig(
|
||||
AuthenticatedVoter.IS_AUTHENTICATED_REMEMBERED)));
|
||||
assertFalse(voter.supports(new SecurityConfig("FOO")));
|
||||
assertThat(voter.supports(new SecurityConfig("FOO"))).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
@@ -39,7 +39,7 @@ public class ConsensusBasedTests {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfEqualGrantedDeniedDecisions(false);
|
||||
assertTrue(!mgr.isAllowIfEqualGrantedDeniedDecisions()); // check changed
|
||||
assertThat(!mgr.isAllowIfEqualGrantedDeniedDecisions()).isTrue(); // check changed
|
||||
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("ROLE_1",
|
||||
"DENY_FOR_SURE");
|
||||
@@ -53,13 +53,13 @@ public class ConsensusBasedTests {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(mgr.isAllowIfEqualGrantedDeniedDecisions()); // check default
|
||||
assertThat(mgr.isAllowIfEqualGrantedDeniedDecisions()).isTrue(); // check default
|
||||
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("ROLE_1",
|
||||
"DENY_FOR_SURE");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class ConsensusBasedTests {
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("ROLE_2"));
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
@@ -85,7 +85,7 @@ public class ConsensusBasedTests {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
assertThat(!mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
|
||||
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class ConsensusBasedTests {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
ConsensusBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
assertThat(mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check changed
|
||||
|
||||
mgr.decide(auth, new Object(), SecurityConfig.createList("IGNORED_BY_ALL"));
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.SecurityConfig;
|
||||
@@ -20,7 +20,6 @@ public class RoleHierarchyVoterTests {
|
||||
"password", "ROLE_A");
|
||||
RoleHierarchyVoter voter = new RoleHierarchyVoter(roleHierarchyImpl);
|
||||
|
||||
assertEquals(RoleHierarchyVoter.ACCESS_GRANTED,
|
||||
voter.vote(auth, new Object(), SecurityConfig.createList("ROLE_B")));
|
||||
assertThat(voter.vote(auth, new Object(), SecurityConfig.createList("ROLE_B"))).isEqualTo(RoleHierarchyVoter.ACCESS_GRANTED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
@@ -20,8 +19,7 @@ public class RoleVoterTests {
|
||||
voter.setRolePrefix("");
|
||||
Authentication userAB = new TestingAuthenticationToken("user", "pass", "A", "B");
|
||||
// Vote on attribute list that has two attributes A and C (i.e. only one matching)
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
|
||||
voter.vote(userAB, this, SecurityConfig.createList("A", "C")));
|
||||
assertThat(voter.vote(userAB, this, SecurityConfig.createList("A", "C"))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
|
||||
}
|
||||
|
||||
// SEC-3128
|
||||
|
||||
+4
-9
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -84,7 +86,6 @@ public class UnanimousBasedTests extends TestCase {
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
}
|
||||
catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,6 @@ public class UnanimousBasedTests extends TestCase {
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("ROLE_2");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() throws Exception {
|
||||
@@ -109,7 +109,6 @@ public class UnanimousBasedTests extends TestCase {
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
}
|
||||
catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,14 +120,13 @@ public class UnanimousBasedTests extends TestCase {
|
||||
"FOOBAR_1", "FOOBAR_2" });
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
public void testThreeAbstainVotesDeniesAccessWithDefault() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
assertThat(!mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check default
|
||||
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("IGNORED_BY_ALL");
|
||||
|
||||
@@ -137,7 +135,6 @@ public class UnanimousBasedTests extends TestCase {
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
}
|
||||
catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,12 +142,11 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
assertThat(mgr.isAllowIfAllAbstainDecisions()).isTrue(); // check changed
|
||||
|
||||
List<ConfigAttribute> config = SecurityConfig.createList("IGNORED_BY_ALL");
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
|
||||
@@ -161,6 +157,5 @@ public class UnanimousBasedTests extends TestCase {
|
||||
"ROLE_2" });
|
||||
|
||||
mgr.decide(auth, new Object(), config);
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -49,7 +49,7 @@ public class AbstractAuthenticationTokenTests {
|
||||
authorities);
|
||||
List<GrantedAuthority> gotAuthorities = (List<GrantedAuthority>) token
|
||||
.getAuthorities();
|
||||
assertNotSame(authorities, gotAuthorities);
|
||||
assertThat(gotAuthorities).isNotSameAs(authorities);
|
||||
|
||||
gotAuthorities.set(0, new SimpleGrantedAuthority("ROLE_SUPER_USER"));
|
||||
}
|
||||
@@ -58,9 +58,9 @@ public class AbstractAuthenticationTokenTests {
|
||||
public void testGetters() throws Exception {
|
||||
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
|
||||
authorities);
|
||||
assertEquals("Test", token.getPrincipal());
|
||||
assertEquals("Password", token.getCredentials());
|
||||
assertEquals("Test", token.getName());
|
||||
assertThat(token.getPrincipal()).isEqualTo("Test");
|
||||
assertThat(token.getCredentials()).isEqualTo("Password");
|
||||
assertThat(token.getName()).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +71,12 @@ public class AbstractAuthenticationTokenTests {
|
||||
authorities);
|
||||
MockAuthenticationImpl token3 = new MockAuthenticationImpl(null, null,
|
||||
AuthorityUtils.NO_AUTHORITIES);
|
||||
assertEquals(token1.hashCode(), token2.hashCode());
|
||||
assertTrue(token1.hashCode() != token3.hashCode());
|
||||
assertThat(token2.hashCode()).isEqualTo(token1.hashCode());
|
||||
assertThat(token1.hashCode() != token3.hashCode()).isTrue();
|
||||
|
||||
token2.setAuthenticated(true);
|
||||
|
||||
assertTrue(token1.hashCode() != token2.hashCode());
|
||||
assertThat(token1.hashCode() != token2.hashCode()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,53 +85,53 @@ public class AbstractAuthenticationTokenTests {
|
||||
authorities);
|
||||
MockAuthenticationImpl token2 = new MockAuthenticationImpl("Test", "Password",
|
||||
authorities);
|
||||
assertEquals(token1, token2);
|
||||
assertThat(token2).isEqualTo(token1);
|
||||
|
||||
MockAuthenticationImpl token3 = new MockAuthenticationImpl("Test",
|
||||
"Password_Changed", authorities);
|
||||
assertTrue(!token1.equals(token3));
|
||||
assertThat(!token1.equals(token3)).isTrue();
|
||||
|
||||
MockAuthenticationImpl token4 = new MockAuthenticationImpl("Test_Changed",
|
||||
"Password", authorities);
|
||||
assertTrue(!token1.equals(token4));
|
||||
assertThat(!token1.equals(token4)).isTrue();
|
||||
|
||||
MockAuthenticationImpl token5 = new MockAuthenticationImpl("Test", "Password",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO_CHANGED"));
|
||||
assertTrue(!token1.equals(token5));
|
||||
assertThat(!token1.equals(token5)).isTrue();
|
||||
|
||||
MockAuthenticationImpl token6 = new MockAuthenticationImpl("Test", "Password",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE"));
|
||||
assertTrue(!token1.equals(token6));
|
||||
assertThat(!token1.equals(token6)).isTrue();
|
||||
|
||||
MockAuthenticationImpl token7 = new MockAuthenticationImpl("Test", "Password",
|
||||
null);
|
||||
assertTrue(!token1.equals(token7));
|
||||
assertTrue(!token7.equals(token1));
|
||||
assertThat(!token1.equals(token7)).isTrue();
|
||||
assertThat(!token7.equals(token1)).isTrue();
|
||||
|
||||
assertTrue(!token1.equals(Integer.valueOf(100)));
|
||||
assertThat(!token1.equals(Integer.valueOf(100))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAuthenticated() throws Exception {
|
||||
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
|
||||
authorities);
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
token.setAuthenticated(true);
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringWithAuthorities() {
|
||||
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
|
||||
authorities);
|
||||
assertTrue(token.toString().lastIndexOf("ROLE_TWO") != -1);
|
||||
assertThat(token.toString().lastIndexOf("ROLE_TWO") != -1).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringWithNullAuthorities() {
|
||||
MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password",
|
||||
null);
|
||||
assertTrue(token.toString().lastIndexOf("Not granted any authorities") != -1);
|
||||
assertThat(token.toString().lastIndexOf("Not granted any authorities") != -1).isTrue();
|
||||
}
|
||||
|
||||
// ~ Inner Classes
|
||||
|
||||
+4
-2
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
@@ -56,11 +58,11 @@ public class AuthenticationTrustResolverImplTests extends TestCase {
|
||||
assertEquals(AnonymousAuthenticationToken.class,
|
||||
trustResolver.getAnonymousClass());
|
||||
trustResolver.setAnonymousClass(TestingAuthenticationToken.class);
|
||||
assertEquals(TestingAuthenticationToken.class, trustResolver.getAnonymousClass());
|
||||
assertThat(trustResolver.getAnonymousClass()).isEqualTo(TestingAuthenticationToken.class);
|
||||
|
||||
assertEquals(RememberMeAuthenticationToken.class,
|
||||
trustResolver.getRememberMeClass());
|
||||
trustResolver.setRememberMeClass(TestingAuthenticationToken.class);
|
||||
assertEquals(TestingAuthenticationToken.class, trustResolver.getRememberMeClass());
|
||||
assertThat(trustResolver.getRememberMeClass()).isEqualTo(TestingAuthenticationToken.class);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -59,12 +59,12 @@ public class ProviderManagerTests {
|
||||
"Test", "Password");
|
||||
ProviderManager mgr = makeProviderManager();
|
||||
Authentication result = mgr.authenticate(token);
|
||||
assertNull(result.getCredentials());
|
||||
assertThat(result.getCredentials()).isNull();
|
||||
|
||||
mgr.setEraseCredentialsAfterAuthentication(false);
|
||||
token = new UsernamePasswordAuthenticationToken("Test", "Password");
|
||||
result = mgr.authenticate(token);
|
||||
assertNotNull(result.getCredentials());
|
||||
assertThat(result.getCredentials()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +77,7 @@ public class ProviderManagerTests {
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
|
||||
Authentication result = mgr.authenticate(a);
|
||||
assertEquals(a, result);
|
||||
assertThat(result).isEqualTo(a);
|
||||
verify(publisher).publishAuthenticationSuccess(result);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ProviderManagerTests {
|
||||
mgr.setAuthenticationEventPublisher(publisher);
|
||||
|
||||
Authentication result = mgr.authenticate(a);
|
||||
assertSame(a, result);
|
||||
assertThat(result).isSameAs(a);
|
||||
verify(publisher).publishAuthenticationSuccess(result);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ProviderManagerTests {
|
||||
request.setDetails(requestDetails);
|
||||
|
||||
Authentication result = authMgr.authenticate(request);
|
||||
assertEquals(resultDetails, result.getDetails());
|
||||
assertThat(result.getDetails()).isEqualTo(resultDetails);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,8 +137,8 @@ public class ProviderManagerTests {
|
||||
request.setDetails(details);
|
||||
|
||||
Authentication result = authMgr.authenticate(request);
|
||||
assertNotNull(result.getCredentials());
|
||||
assertSame(details, result.getDetails());
|
||||
assertThat(result.getCredentials()).isNotNull();
|
||||
assertThat(result.getDetails()).isSameAs(details);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,7 +148,7 @@ public class ProviderManagerTests {
|
||||
ProviderManager mgr = new ProviderManager(
|
||||
Arrays.asList(createProviderWhichThrows(new BadCredentialsException("",
|
||||
new Throwable())), createProviderWhichReturns(authReq)));
|
||||
assertSame(authReq, mgr.authenticate(mock(Authentication.class)));
|
||||
assertThat(mgr.authenticate(mock(Authentication.class))).isSameAs(authReq);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,7 +194,7 @@ public class ProviderManagerTests {
|
||||
when(parent.authenticate(authReq)).thenReturn(authReq);
|
||||
ProviderManager mgr = new ProviderManager(
|
||||
Arrays.asList(mock(AuthenticationProvider.class)), parent);
|
||||
assertSame(authReq, mgr.authenticate(authReq));
|
||||
assertThat(mgr.authenticate(authReq)).isSameAs(authReq);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,7 +256,7 @@ public class ProviderManagerTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (BadCredentialsException e) {
|
||||
assertSame(expected, e);
|
||||
assertThat(e).isSameAs(expected);
|
||||
}
|
||||
verify(publisher).publishAuthenticationFailure(expected, authReq);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class ProviderManagerTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (LockedException e) {
|
||||
assertSame(expected, e);
|
||||
assertThat(e).isSameAs(expected);
|
||||
}
|
||||
verify(publisher).publishAuthenticationFailure(expected, authReq);
|
||||
}
|
||||
|
||||
+8
-9
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.authentication.TestingAuthenticationProvider;
|
||||
@@ -35,20 +37,17 @@ public class TestingAuthenticationProviderTests extends TestCase {
|
||||
"Password", "ROLE_ONE", "ROLE_TWO");
|
||||
Authentication result = provider.authenticate(token);
|
||||
|
||||
assertTrue(result instanceof TestingAuthenticationToken);
|
||||
assertThat(result instanceof TestingAuthenticationToken).isTrue();
|
||||
|
||||
TestingAuthenticationToken castResult = (TestingAuthenticationToken) result;
|
||||
assertEquals("Test", castResult.getPrincipal());
|
||||
assertEquals("Password", castResult.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(castResult.getAuthorities())
|
||||
.contains("ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(castResult.getAuthorities())
|
||||
.contains("ROLE_TWO"));
|
||||
assertThat(castResult.getPrincipal()).isEqualTo("Test");
|
||||
assertThat(castResult.getCredentials()).isEqualTo("Password");
|
||||
assertThat(AuthorityUtils.authorityListToSet(castResult.getAuthorities())).contains("ROLE_ONE","ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testSupports() {
|
||||
TestingAuthenticationProvider provider = new TestingAuthenticationProvider();
|
||||
assertTrue(provider.supports(TestingAuthenticationToken.class));
|
||||
assertTrue(!provider.supports(String.class));
|
||||
assertThat(provider.supports(TestingAuthenticationToken.class)).isTrue();
|
||||
assertThat(!provider.supports(String.class)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -15,9 +15,9 @@
|
||||
|
||||
package org.springframework.security.authentication;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
@@ -40,22 +40,22 @@ public class UsernamePasswordAuthenticationTokenTests {
|
||||
|
||||
// check default given we passed some GrantedAuthorty[]s (well, we passed empty
|
||||
// list)
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
|
||||
// check explicit set to untrusted (we can safely go from trusted to untrusted,
|
||||
// but not the reverse)
|
||||
token.setAuthenticated(false);
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
|
||||
// Now let's create a UsernamePasswordAuthenticationToken without any
|
||||
// GrantedAuthorty[]s (different constructor)
|
||||
token = new UsernamePasswordAuthenticationToken("Test", "Password");
|
||||
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
|
||||
// check we're allowed to still set it to untrusted
|
||||
token.setAuthenticated(false);
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
|
||||
// check denied changing it to trusted
|
||||
try {
|
||||
@@ -71,11 +71,11 @@ public class UsernamePasswordAuthenticationTokenTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
||||
"Test", "Password", AuthorityUtils.createAuthorityList("ROLE_ONE",
|
||||
"ROLE_TWO"));
|
||||
assertEquals("Test", token.getPrincipal());
|
||||
assertEquals("Password", token.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
assertThat(token.getPrincipal()).isEqualTo("Test");
|
||||
assertThat(token.getCredentials()).isEqualTo("Password");
|
||||
assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
"ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
"ROLE_TWO"));
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication.anonymous;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationProvider;
|
||||
@@ -59,7 +59,7 @@ public class AnonymousAuthenticationProviderTests {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class AnonymousAuthenticationProviderTests {
|
||||
public void testGettersSetters() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
|
||||
"qwerty");
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
assertThat(aap.getKey()).isEqualTo("qwerty");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,10 +77,10 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("user",
|
||||
"password", "ROLE_A");
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
|
||||
|
||||
// Try it anyway
|
||||
assertNull(aap.authenticate(token));
|
||||
assertThat(aap.authenticate(token)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,14 +93,14 @@ public class AnonymousAuthenticationProviderTests {
|
||||
|
||||
Authentication result = aap.authenticate(token);
|
||||
|
||||
assertEquals(result, token);
|
||||
assertThat(token).isEqualTo(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupports() {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
|
||||
"qwerty");
|
||||
assertTrue(aap.supports(AnonymousAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
assertThat(aap.supports(AnonymousAuthenticationToken.class)).isTrue();
|
||||
assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.authentication.anonymous;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -73,21 +75,19 @@ public class AnonymousAuthenticationTokenTests extends TestCase {
|
||||
AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
|
||||
assertEquals(token1, token2);
|
||||
assertThat(token2).isEqualTo(token1);
|
||||
}
|
||||
|
||||
public void testGetters() {
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
|
||||
assertEquals("key".hashCode(), token.getKeyHash());
|
||||
assertEquals("Test", token.getPrincipal());
|
||||
assertEquals("", token.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
"ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
"ROLE_TWO"));
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.getKeyHash()).isEqualTo("key".hashCode());
|
||||
assertThat(token.getPrincipal()).isEqualTo("Test");
|
||||
assertThat(token.getCredentials()).isEqualTo("");
|
||||
assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities())).contains(
|
||||
"ROLE_ONE","ROLE_TWO");
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
public void testNoArgConstructorDoesntExist() {
|
||||
@@ -107,7 +107,7 @@ public class AnonymousAuthenticationTokenTests extends TestCase {
|
||||
AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key",
|
||||
"DIFFERENT_PRINCIPAL", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testNotEqualsDueToDifferentAuthenticationClass() {
|
||||
@@ -116,7 +116,7 @@ public class AnonymousAuthenticationTokenTests extends TestCase {
|
||||
UsernamePasswordAuthenticationToken token2 = new UsernamePasswordAuthenticationToken(
|
||||
"Test", "Password", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testNotEqualsDueToKey() {
|
||||
@@ -126,14 +126,14 @@ public class AnonymousAuthenticationTokenTests extends TestCase {
|
||||
AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken(
|
||||
"DIFFERENT_KEY", "Test", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testSetAuthenticatedIgnored() {
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
token.setAuthenticated(false);
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+41
-43
@@ -15,6 +15,8 @@
|
||||
|
||||
package org.springframework.security.authentication.dao;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -77,7 +79,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Expected BadCredenialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +113,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown AccountExpiredException");
|
||||
}
|
||||
catch (AccountExpiredException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +130,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown LockedException");
|
||||
}
|
||||
catch (LockedException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +147,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown CredentialsExpiredException");
|
||||
}
|
||||
catch (CredentialsExpiredException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
// Check that wrong password causes BadCredentialsException, rather than
|
||||
@@ -157,7 +159,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +176,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown DisabledException");
|
||||
}
|
||||
catch (DisabledException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +209,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +226,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +245,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown UsernameNotFoundException");
|
||||
}
|
||||
catch (UsernameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +254,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"INVALID_USER", "koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
assertTrue(provider.isHideUserNotFoundExceptions());
|
||||
assertThat(provider.isHideUserNotFoundExceptions()).isTrue();
|
||||
provider.setUserDetailsService(new MockAuthenticationDaoUserrod());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -261,7 +263,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +280,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown BadCredentialsException");
|
||||
}
|
||||
catch (BadCredentialsException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,13 +300,11 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
UsernamePasswordAuthenticationToken castResult = (UsernamePasswordAuthenticationToken) result;
|
||||
assertEquals(User.class, castResult.getPrincipal().getClass());
|
||||
assertEquals("koala", castResult.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(castResult.getAuthorities())
|
||||
.contains("ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(castResult.getAuthorities())
|
||||
.contains("ROLE_TWO"));
|
||||
assertEquals("192.168.0.1", castResult.getDetails());
|
||||
assertThat(castResult.getPrincipal().getClass()).isEqualTo(User.class);
|
||||
assertThat(castResult.getCredentials()).isEqualTo("koala");
|
||||
assertThat(AuthorityUtils.authorityListToSet(castResult.getAuthorities()))
|
||||
.contains("ROLE_ONE","ROLE_TWO");
|
||||
assertThat(castResult.getDetails()).isEqualTo("192.168.0.1");
|
||||
}
|
||||
|
||||
public void testAuthenticatesASecondTime() {
|
||||
@@ -328,7 +328,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have returned instance of UsernamePasswordAuthenticationToken");
|
||||
}
|
||||
|
||||
assertEquals(result.getCredentials(), result2.getCredentials());
|
||||
assertThat(result2.getCredentials()).isEqualTo(result.getCredentials());
|
||||
}
|
||||
|
||||
public void testAuthenticatesWhenASaltIsUsed() {
|
||||
@@ -349,14 +349,12 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have returned instance of UsernamePasswordAuthenticationToken");
|
||||
}
|
||||
|
||||
assertEquals(User.class, result.getPrincipal().getClass());
|
||||
assertThat(result.getPrincipal().getClass()).isEqualTo(User.class);
|
||||
|
||||
// We expect original credentials user submitted to be returned
|
||||
assertEquals("koala", result.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(result.getAuthorities()).contains(
|
||||
"ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(result.getAuthorities()).contains(
|
||||
"ROLE_TWO"));
|
||||
assertThat(result.getCredentials()).isEqualTo("koala");
|
||||
assertThat(AuthorityUtils.authorityListToSet(result.getAuthorities()))
|
||||
.contains("ROLE_ONE","ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testAuthenticatesWithForcePrincipalAsString() {
|
||||
@@ -375,8 +373,8 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
UsernamePasswordAuthenticationToken castResult = (UsernamePasswordAuthenticationToken) result;
|
||||
assertEquals(String.class, castResult.getPrincipal().getClass());
|
||||
assertEquals("rod", castResult.getPrincipal());
|
||||
assertThat(castResult.getPrincipal().getClass()).isEqualTo(String.class);
|
||||
assertThat(castResult.getPrincipal()).isEqualTo("rod");
|
||||
}
|
||||
|
||||
public void testDetectsNullBeingReturnedFromAuthenticationDao() {
|
||||
@@ -400,17 +398,17 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
public void testGettersSetters() {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setPasswordEncoder(new ShaPasswordEncoder());
|
||||
assertEquals(ShaPasswordEncoder.class, provider.getPasswordEncoder().getClass());
|
||||
assertThat(provider.getPasswordEncoder().getClass()).isEqualTo(ShaPasswordEncoder.class);
|
||||
|
||||
provider.setSaltSource(new SystemWideSaltSource());
|
||||
assertEquals(SystemWideSaltSource.class, provider.getSaltSource().getClass());
|
||||
assertThat(provider.getSaltSource().getClass()).isEqualTo(SystemWideSaltSource.class);
|
||||
|
||||
provider.setUserCache(new EhCacheBasedUserCache());
|
||||
assertEquals(EhCacheBasedUserCache.class, provider.getUserCache().getClass());
|
||||
assertThat(provider.getUserCache().getClass()).isEqualTo(EhCacheBasedUserCache.class);
|
||||
|
||||
assertFalse(provider.isForcePrincipalAsString());
|
||||
assertThat(provider.isForcePrincipalAsString()).isFalse();
|
||||
provider.setForcePrincipalAsString(true);
|
||||
assertTrue(provider.isForcePrincipalAsString());
|
||||
assertThat(provider.isForcePrincipalAsString()).isTrue();
|
||||
}
|
||||
|
||||
public void testGoesBackToAuthenticationDaoToObtainLatestPasswordIfCachedPasswordSeemsIncorrect() {
|
||||
@@ -427,7 +425,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
provider.authenticate(token);
|
||||
|
||||
// Check "rod = koala" ended up in the cache
|
||||
assertEquals("koala", cache.getUserFromCache("rod").getPassword());
|
||||
assertThat(cache.getUserFromCache("rod").getPassword()).isEqualTo("koala");
|
||||
|
||||
// Now change the password the AuthenticationDao will return
|
||||
authenticationDao.setPassword("easternLongNeckTurtle");
|
||||
@@ -438,7 +436,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
|
||||
// To get this far, the new password was accepted
|
||||
// Check the cache was updated
|
||||
assertEquals("easternLongNeckTurtle", cache.getUserFromCache("rod").getPassword());
|
||||
assertThat(cache.getUserFromCache("rod").getPassword()).isEqualTo("easternLongNeckTurtle");
|
||||
}
|
||||
|
||||
public void testStartupFailsIfNoAuthenticationDao() throws Exception {
|
||||
@@ -449,14 +447,14 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testStartupFailsIfNoUserCacheSet() throws Exception {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setUserDetailsService(new MockAuthenticationDaoUserrod());
|
||||
assertEquals(NullUserCache.class, provider.getUserCache().getClass());
|
||||
assertThat(provider.getUserCache().getClass()).isEqualTo(NullUserCache.class);
|
||||
provider.setUserCache(null);
|
||||
|
||||
try {
|
||||
@@ -464,7 +462,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,15 +471,15 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
UserDetailsService userDetailsService = new MockAuthenticationDaoUserrod();
|
||||
provider.setUserDetailsService(userDetailsService);
|
||||
provider.setUserCache(new MockUserCache());
|
||||
assertEquals(userDetailsService, provider.getUserDetailsService());
|
||||
assertThat(provider.getUserDetailsService()).isEqualTo(userDetailsService);
|
||||
provider.afterPropertiesSet();
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
public void testSupports() {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
assertTrue(provider.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertTrue(!provider.supports(TestingAuthenticationToken.class));
|
||||
assertThat(provider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
|
||||
assertThat(!provider.supports(TestingAuthenticationToken.class)).isTrue();
|
||||
}
|
||||
|
||||
// SEC-2056
|
||||
|
||||
+2
-2
@@ -55,13 +55,13 @@ public class ReflectionSaltSourceTests {
|
||||
ReflectionSaltSource saltSource = new ReflectionSaltSource();
|
||||
saltSource.setUserPropertyToUse("getUsername");
|
||||
|
||||
assertEquals("scott", saltSource.getSalt(user));
|
||||
assertThat(saltSource.getSalt(user)).isEqualTo("scott");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyNameAsPropertyToUseReturnsCorrectSaltValue() {
|
||||
ReflectionSaltSource saltSource = new ReflectionSaltSource();
|
||||
saltSource.setUserPropertyToUse("password");
|
||||
assertEquals("wombat", saltSource.getSalt(user));
|
||||
assertThat(saltSource.getSalt(user)).isEqualTo("wombat");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication.dao.salt;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.springframework.security.authentication.dao.SystemWideSaltSource;
|
||||
|
||||
@@ -57,21 +57,21 @@ public class SystemWideSaltSourceTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("A systemWideSalt must be set", expected.getMessage());
|
||||
assertThat(expected.getMessage()).isEqualTo("A systemWideSalt must be set");
|
||||
}
|
||||
}
|
||||
|
||||
public void testGettersSetters() {
|
||||
SystemWideSaltSource saltSource = new SystemWideSaltSource();
|
||||
saltSource.setSystemWideSalt("helloWorld");
|
||||
assertEquals("helloWorld", saltSource.getSystemWideSalt());
|
||||
assertThat(saltSource.getSystemWideSalt()).isEqualTo("helloWorld");
|
||||
}
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
SystemWideSaltSource saltSource = new SystemWideSaltSource();
|
||||
saltSource.setSystemWideSalt("helloWorld");
|
||||
saltSource.afterPropertiesSet();
|
||||
assertEquals("helloWorld", saltSource.getSalt(null));
|
||||
assertThat(saltSource.getSalt(null)).isEqualTo("helloWorld");
|
||||
}
|
||||
|
||||
// SEC-2173
|
||||
|
||||
+17
-17
@@ -34,14 +34,14 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
String merged = pwd.nowMergePasswordAndSalt("password", null, true);
|
||||
|
||||
String[] demerged = pwd.nowDemergePasswordAndSalt(merged);
|
||||
assertEquals("password", demerged[0]);
|
||||
assertEquals("", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("password");
|
||||
assertThat(demerged[1]).isEqualTo("");
|
||||
|
||||
merged = pwd.nowMergePasswordAndSalt("password", "", true);
|
||||
|
||||
demerged = pwd.nowDemergePasswordAndSalt(merged);
|
||||
assertEquals("password", demerged[0]);
|
||||
assertEquals("", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("password");
|
||||
assertThat(demerged[1]).isEqualTo("");
|
||||
}
|
||||
|
||||
public void testDemergeWithEmptyStringIsRejected() {
|
||||
@@ -52,7 +52,7 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Cannot pass a null or empty String", expected.getMessage());
|
||||
assertThat(expected.getMessage()).isEqualTo("Cannot pass a null or empty String");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Cannot pass a null or empty String", expected.getMessage());
|
||||
assertThat(expected.getMessage()).isEqualTo("Cannot pass a null or empty String");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,34 +72,34 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
MockPasswordEncoder pwd = new MockPasswordEncoder();
|
||||
|
||||
String merged = pwd.nowMergePasswordAndSalt("password", "foo", true);
|
||||
assertEquals("password{foo}", merged);
|
||||
assertThat(merged).isEqualTo("password{foo}");
|
||||
|
||||
String[] demerged = pwd.nowDemergePasswordAndSalt(merged);
|
||||
assertEquals("password", demerged[0]);
|
||||
assertEquals("foo", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("password");
|
||||
assertThat(demerged[1]).isEqualTo("foo");
|
||||
}
|
||||
|
||||
public void testMergeDemergeWithDelimitersInPassword() {
|
||||
MockPasswordEncoder pwd = new MockPasswordEncoder();
|
||||
|
||||
String merged = pwd.nowMergePasswordAndSalt("p{ass{w{o}rd", "foo", true);
|
||||
assertEquals("p{ass{w{o}rd{foo}", merged);
|
||||
assertThat(merged).isEqualTo("p{ass{w{o}rd{foo}");
|
||||
|
||||
String[] demerged = pwd.nowDemergePasswordAndSalt(merged);
|
||||
|
||||
assertEquals("p{ass{w{o}rd", demerged[0]);
|
||||
assertEquals("foo", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("p{ass{w{o}rd");
|
||||
assertThat(demerged[1]).isEqualTo("foo");
|
||||
}
|
||||
|
||||
public void testMergeDemergeWithNullAsPassword() {
|
||||
MockPasswordEncoder pwd = new MockPasswordEncoder();
|
||||
|
||||
String merged = pwd.nowMergePasswordAndSalt(null, "foo", true);
|
||||
assertEquals("{foo}", merged);
|
||||
assertThat(merged).isEqualTo("{foo}");
|
||||
|
||||
String[] demerged = pwd.nowDemergePasswordAndSalt(merged);
|
||||
assertEquals("", demerged[0]);
|
||||
assertEquals("foo", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("");
|
||||
assertThat(demerged[1]).isEqualTo("foo");
|
||||
}
|
||||
|
||||
public void testStrictMergeRejectsDelimitersInSalt1() {
|
||||
@@ -110,7 +110,7 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Cannot use { or } in salt.toString()", expected.getMessage());
|
||||
assertThat(expected.getMessage()).isEqualTo("Cannot use { or } in salt.toString()");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Cannot use { or } in salt.toString()", expected.getMessage());
|
||||
assertThat(expected.getMessage()).isEqualTo("Cannot use { or } in salt.toString()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -24,45 +24,45 @@ public class Md4PasswordEncoderTests extends TestCase {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", null);
|
||||
assertEquals("8zobtq72iAt0W6KNqavGwg==", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("8zobtq72iAt0W6KNqavGwg==");
|
||||
}
|
||||
|
||||
public void testEncodeSaltedPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", "Alan K Stewart");
|
||||
assertEquals("ZplT6P5Kv6Rlu6W4FIoYNA==", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("ZplT6P5Kv6Rlu6W4FIoYNA==");
|
||||
}
|
||||
|
||||
public void testEncodeNullPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword(null, null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("MdbP4NFq6TG3PFnX4MCJwA==");
|
||||
}
|
||||
|
||||
public void testEncodeEmptyPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("", null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("MdbP4NFq6TG3PFnX4MCJwA==");
|
||||
}
|
||||
|
||||
public void testNonAsciiPasswordHasCorrectHash() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
String encodedPassword = md4.encodePassword("\u4F60\u597d", null);
|
||||
assertEquals("a7f1196539fd1f85f754ffd185b16e6e", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("a7f1196539fd1f85f754ffd185b16e6e");
|
||||
}
|
||||
|
||||
public void testIsHexPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
assertTrue(md4.isPasswordValid("31d6cfe0d16ae931b73c59d7e0c089c0", "", null));
|
||||
assertThat(md4.isPasswordValid("31d6cfe0d16ae931b73c59d7e0c089c0", "", null)).isTrue();
|
||||
}
|
||||
|
||||
public void testIsPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
assertTrue(md4.isPasswordValid("8zobtq72iAt0W6KNqavGwg==", "ww_uni123", null));
|
||||
assertThat(md4.isPasswordValid("8zobtq72iAt0W6KNqavGwg==", "ww_uni123", null)).isTrue();
|
||||
}
|
||||
|
||||
public void testIsSaltedPasswordValid() {
|
||||
|
||||
+9
-9
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication.encoding;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -40,10 +40,10 @@ public class Md5PasswordEncoderTests {
|
||||
String badRaw = "abc321";
|
||||
String salt = "THIS_IS_A_SALT";
|
||||
String encoded = pe.encodePassword(raw, salt);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertEquals("a68aafd90299d0b137de28fb4bb68573", encoded);
|
||||
assertEquals("MD5", pe.getAlgorithm());
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
assertThat(encoded).isEqualTo("a68aafd90299d0b137de28fb4bb68573");
|
||||
assertThat(pe.getAlgorithm()).isEqualTo("MD5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +52,7 @@ public class Md5PasswordEncoderTests {
|
||||
// $ echo -n "你好" | md5
|
||||
// 7eca689f0d3389d9dea66ae112e5cfd7
|
||||
String encodedPassword = md5.encodePassword("\u4F60\u597d", null);
|
||||
assertEquals("7eca689f0d3389d9dea66ae112e5cfd7", encodedPassword);
|
||||
assertThat(encodedPassword).isEqualTo("7eca689f0d3389d9dea66ae112e5cfd7");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,9 +63,9 @@ public class Md5PasswordEncoderTests {
|
||||
String badRaw = "abc321";
|
||||
String salt = "THIS_IS_A_SALT";
|
||||
String encoded = pe.encodePassword(raw, salt);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertTrue(encoded.length() != 32);
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
assertThat(encoded.length() != 32).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-8
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.authentication.encoding;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,24 +11,24 @@ public class PasswordEncoderUtilsTests {
|
||||
|
||||
@Test
|
||||
public void differentLength() {
|
||||
assertFalse(PasswordEncoderUtils.equals("abc", "a"));
|
||||
assertFalse(PasswordEncoderUtils.equals("a", "abc"));
|
||||
assertThat(PasswordEncoderUtils.equals("abc", "a")).isFalse();
|
||||
assertThat(PasswordEncoderUtils.equals("a", "abc")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsNull() {
|
||||
assertFalse(PasswordEncoderUtils.equals(null, "a"));
|
||||
assertFalse(PasswordEncoderUtils.equals("a", null));
|
||||
assertTrue(PasswordEncoderUtils.equals(null, null));
|
||||
assertThat(PasswordEncoderUtils.equals(null, "a")).isFalse();
|
||||
assertThat(PasswordEncoderUtils.equals("a", null)).isFalse();
|
||||
assertThat(PasswordEncoderUtils.equals(null, null)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsCaseSensitive() {
|
||||
assertFalse(PasswordEncoderUtils.equals("aBc", "abc"));
|
||||
assertThat(PasswordEncoderUtils.equals("aBc", "abc")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsSuccess() {
|
||||
assertTrue(PasswordEncoderUtils.equals("abcdef", "abcdef"));
|
||||
assertThat(PasswordEncoderUtils.equals("abcdef", "abcdef")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -40,14 +40,14 @@ public class PlaintextPasswordEncoderTests extends TestCase {
|
||||
String salt = "THIS_IS_A_SALT";
|
||||
|
||||
String encoded = pe.encodePassword(raw, salt);
|
||||
assertEquals("abc123{THIS_IS_A_SALT}", encoded);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertThat(encoded).isEqualTo("abc123{THIS_IS_A_SALT}");
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
|
||||
// make sure default is not to ignore password case
|
||||
assertFalse(pe.isIgnorePasswordCase());
|
||||
assertThat(pe.isIgnorePasswordCase()).isFalse();
|
||||
encoded = pe.encodePassword(rawDiffCase, salt);
|
||||
assertFalse(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isFalse();
|
||||
|
||||
// now check for ignore password case
|
||||
pe = new PlaintextPasswordEncoder();
|
||||
@@ -55,8 +55,8 @@ public class PlaintextPasswordEncoderTests extends TestCase {
|
||||
|
||||
// should be able to validate even without encoding
|
||||
encoded = pe.encodePassword(rawDiffCase, salt);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
}
|
||||
|
||||
public void testMergeDemerge() {
|
||||
@@ -64,7 +64,7 @@ public class PlaintextPasswordEncoderTests extends TestCase {
|
||||
|
||||
String merged = pwd.encodePassword("password", "foo");
|
||||
String[] demerged = pwd.obtainPasswordAndSalt(merged);
|
||||
assertEquals("password", demerged[0]);
|
||||
assertEquals("foo", demerged[1]);
|
||||
assertThat(demerged[0]).isEqualTo("password");
|
||||
assertThat(demerged[1]).isEqualTo("foo");
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -38,9 +38,9 @@ public class ShaPasswordEncoderTests extends TestCase {
|
||||
String badRaw = "abc321";
|
||||
String salt = "THIS_IS_A_SALT";
|
||||
String encoded = pe.encodePassword(raw, salt);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertEquals("b2f50ffcbd3407fe9415c062d55f54731f340d32", encoded);
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
assertThat(encoded).isEqualTo("b2f50ffcbd3407fe9415c062d55f54731f340d32");
|
||||
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ public class ShaPasswordEncoderTests extends TestCase {
|
||||
String badRaw = "abc321";
|
||||
String salt = "THIS_IS_A_SALT";
|
||||
String encoded = pe.encodePassword(raw, salt);
|
||||
assertTrue(pe.isPasswordValid(encoded, raw, salt));
|
||||
assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
|
||||
assertTrue(encoded.length() != 40);
|
||||
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
|
||||
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
|
||||
assertThat(encoded.length() != 40).isTrue();
|
||||
}
|
||||
|
||||
public void test256() throws Exception {
|
||||
|
||||
+5
-5
@@ -54,7 +54,7 @@ public class AuthenticationEventTests extends TestCase {
|
||||
public void testAbstractAuthenticationEvent() {
|
||||
Authentication auth = getAuthentication();
|
||||
AbstractAuthenticationEvent event = new AuthenticationSuccessEvent(auth);
|
||||
assertEquals(auth, event.getAuthentication());
|
||||
assertThat(event.getAuthentication()).isEqualTo(auth);
|
||||
}
|
||||
|
||||
public void testAbstractAuthenticationFailureEvent() {
|
||||
@@ -62,8 +62,8 @@ public class AuthenticationEventTests extends TestCase {
|
||||
AuthenticationException exception = new DisabledException("TEST");
|
||||
AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(
|
||||
auth, exception);
|
||||
assertEquals(auth, event.getAuthentication());
|
||||
assertEquals(exception, event.getException());
|
||||
assertThat(event.getAuthentication()).isEqualTo(auth);
|
||||
assertThat(event.getException()).isEqualTo(exception);
|
||||
}
|
||||
|
||||
public void testRejectsNullAuthentication() {
|
||||
@@ -74,7 +74,7 @@ public class AuthenticationEventTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class AuthenticationEventTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -53,6 +53,6 @@ public class LoggerListenerTests extends TestCase {
|
||||
getAuthentication(), new LockedException("TEST"));
|
||||
LoggerListener listener = new LoggerListener();
|
||||
listener.onApplicationEvent(event);
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.security.authentication.jaas;
|
||||
|
||||
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 static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -101,10 +101,10 @@ public class DefaultJaasAuthenticationProviderTests {
|
||||
@Test
|
||||
public void authenticateSuccess() throws Exception {
|
||||
Authentication auth = provider.authenticate(token);
|
||||
assertEquals(token.getPrincipal(), auth.getPrincipal());
|
||||
assertEquals(token.getCredentials(), auth.getCredentials());
|
||||
assertEquals(true, auth.isAuthenticated());
|
||||
assertEquals(false, auth.getAuthorities().isEmpty());
|
||||
assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal());
|
||||
assertThat(auth.getCredentials()).isEqualTo(token.getCredentials());
|
||||
assertThat(auth.isAuthenticated()).isEqualTo(true);
|
||||
assertThat(auth.getAuthorities().isEmpty()).isEqualTo(false);
|
||||
verify(publisher).publishEvent(isA(JaasAuthenticationSuccessEvent.class));
|
||||
verifyNoMoreInteractions(publisher);
|
||||
}
|
||||
@@ -254,8 +254,8 @@ public class DefaultJaasAuthenticationProviderTests {
|
||||
try {
|
||||
provider = context.getBean(DefaultJaasAuthenticationProvider.class);
|
||||
Authentication auth = provider.authenticate(token);
|
||||
assertEquals(true, auth.isAuthenticated());
|
||||
assertEquals(token.getPrincipal(), auth.getPrincipal());
|
||||
assertThat(auth.isAuthenticated()).isEqualTo(true);
|
||||
assertThat(auth.getPrincipal()).isEqualTo(token.getPrincipal());
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
|
||||
+20
-20
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication.jaas;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.File;
|
||||
@@ -81,10 +81,10 @@ public class JaasAuthenticationProviderTests {
|
||||
catch (AuthenticationException e) {
|
||||
}
|
||||
|
||||
assertNotNull("Failure event not fired", eventCheck.failedEvent);
|
||||
assertThat(eventCheck.failedEvent).as("Failure event not fired").isNotNull();
|
||||
assertNotNull("Failure event exception was null",
|
||||
eventCheck.failedEvent.getException());
|
||||
assertNull("Success event was fired", eventCheck.successEvent);
|
||||
assertThat(eventCheck.successEvent).as("Success event was fired").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,10 +97,10 @@ public class JaasAuthenticationProviderTests {
|
||||
catch (AuthenticationException e) {
|
||||
}
|
||||
|
||||
assertNotNull("Failure event not fired", eventCheck.failedEvent);
|
||||
assertThat(eventCheck.failedEvent).as("Failure event not fired").isNotNull();
|
||||
assertNotNull("Failure event exception was null",
|
||||
eventCheck.failedEvent.getException());
|
||||
assertNull("Success event was fired", eventCheck.successEvent);
|
||||
assertThat(eventCheck.successEvent).as("Success event was fired").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,7 +127,7 @@ public class JaasAuthenticationProviderTests {
|
||||
fail("Should have thrown ApplicationContextException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage().startsWith("loginConfig must be set on"));
|
||||
assertThat(expected.getMessage().startsWith("loginConfig must be set on")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class JaasAuthenticationProviderTests {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage()
|
||||
assertThat(expected.getMessage().isTrue()
|
||||
.startsWith("loginContextName must be set on"));
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class JaasAuthenticationProviderTests {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage()
|
||||
assertThat(expected.getMessage().isTrue()
|
||||
.startsWith("loginContextName must be set on"));
|
||||
}
|
||||
}
|
||||
@@ -199,14 +199,14 @@ public class JaasAuthenticationProviderTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
||||
"user", "password", AuthorityUtils.createAuthorityList("ROLE_ONE"));
|
||||
|
||||
assertTrue(jaasProvider.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertThat(jaasProvider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
|
||||
|
||||
Authentication auth = jaasProvider.authenticate(token);
|
||||
|
||||
assertNotNull(jaasProvider.getAuthorityGranters());
|
||||
assertNotNull(jaasProvider.getCallbackHandlers());
|
||||
assertNotNull(jaasProvider.getLoginConfig());
|
||||
assertNotNull(jaasProvider.getLoginContextName());
|
||||
assertThat(jaasProvider.getAuthorityGranters()).isNotNull();
|
||||
assertThat(jaasProvider.getCallbackHandlers()).isNotNull();
|
||||
assertThat(jaasProvider.getLoginConfig()).isNotNull();
|
||||
assertThat(jaasProvider.getLoginContextName()).isNotNull();
|
||||
|
||||
Collection<? extends GrantedAuthority> list = auth.getAuthorities();
|
||||
Set<String> set = AuthorityUtils.authorityListToSet(list);
|
||||
@@ -229,22 +229,22 @@ public class JaasAuthenticationProviderTests {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Could not find a JaasGrantedAuthority", foundit);
|
||||
assertThat(foundit).as("Could not find a JaasGrantedAuthority").isTrue();
|
||||
|
||||
assertNotNull("Success event should be fired", eventCheck.successEvent);
|
||||
assertThat(eventCheck.successEvent).as("Success event should be fired").isNotNull();
|
||||
assertEquals("Auth objects should be equal", auth,
|
||||
eventCheck.successEvent.getAuthentication());
|
||||
assertNull("Failure event should not be fired", eventCheck.failedEvent);
|
||||
assertThat(eventCheck.failedEvent).as("Failure event should not be fired").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApplicationEventPublisher() throws Exception {
|
||||
assertNotNull(jaasProvider.getApplicationEventPublisher());
|
||||
assertThat(jaasProvider.getApplicationEventPublisher()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginExceptionResolver() {
|
||||
assertNotNull(jaasProvider.getLoginExceptionResolver());
|
||||
assertThat(jaasProvider.getLoginExceptionResolver()).isNotNull();
|
||||
jaasProvider.setLoginExceptionResolver(new LoginExceptionResolver() {
|
||||
public AuthenticationException resolveException(LoginException e) {
|
||||
return new LockedException("This is just a test!");
|
||||
@@ -278,7 +278,7 @@ public class JaasAuthenticationProviderTests {
|
||||
|
||||
jaasProvider.handleLogout(event);
|
||||
|
||||
assertTrue(loginContext.loggedOut);
|
||||
assertThat(loginContext.loggedOut).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,7 +286,7 @@ public class JaasAuthenticationProviderTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
|
||||
"user", "password");
|
||||
|
||||
assertTrue(jaasProvider.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertThat(jaasProvider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
|
||||
|
||||
Authentication auth = jaasProvider.authenticate(token);
|
||||
assertTrue("Only ROLE_TEST1 and ROLE_TEST2 should have been returned", auth
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class Sec760Tests {
|
||||
"ROLE_TWO"));
|
||||
|
||||
Authentication auth = p1.authenticate(token);
|
||||
Assert.assertNotNull(auth);
|
||||
Assert.assertThat(auth).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+7
-7
@@ -59,11 +59,11 @@ public class SecurityContextLoginModuleTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testAbort() throws Exception {
|
||||
assertFalse("Should return false, no auth is set", module.abort());
|
||||
assertThat(module.abort()).as("Should return false, no auth is set").isFalse();
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
module.login();
|
||||
module.commit();
|
||||
assertTrue(module.abort());
|
||||
assertThat(module.abort()).isTrue();
|
||||
}
|
||||
|
||||
public void testLoginException() throws Exception {
|
||||
@@ -77,7 +77,7 @@ public class SecurityContextLoginModuleTests extends TestCase {
|
||||
|
||||
public void testLoginSuccess() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
assertTrue("Login should succeed, there is an authentication set", module.login());
|
||||
assertThat(module.login()).as("Login should succeed, there is an authentication set").isTrue();
|
||||
assertTrue("The authentication is not null, this should return true",
|
||||
module.commit());
|
||||
assertTrue("Principals should contain the authentication", subject
|
||||
@@ -87,8 +87,8 @@ public class SecurityContextLoginModuleTests extends TestCase {
|
||||
public void testLogout() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
module.login();
|
||||
assertTrue("Should return true as it succeeds", module.logout());
|
||||
assertEquals("Authentication should be null", null, module.getAuthentication());
|
||||
assertThat(module.logout()).as("Should return true as it succeeds").isTrue();
|
||||
assertThat(module.getAuthentication()).as("Authentication should be null").isEqualTo(null);
|
||||
|
||||
assertFalse("Principals should not contain the authentication after logout",
|
||||
subject.getPrincipals().contains(auth));
|
||||
@@ -112,10 +112,10 @@ public class SecurityContextLoginModuleTests extends TestCase {
|
||||
|
||||
module.initialize(subject, null, null, options);
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
assertFalse("Should return false and ask to be ignored", module.login());
|
||||
assertThat(module.login()).as("Should return false and ask to be ignored").isFalse();
|
||||
}
|
||||
|
||||
public void testNullLogout() throws Exception {
|
||||
assertFalse(module.logout());
|
||||
assertThat(module.logout()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
package org.springframework.security.authentication.jaas.memory;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -54,7 +54,7 @@ public class InMemoryConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void constructorNullDefault() {
|
||||
assertNull(new InMemoryConfiguration((AppConfigurationEntry[]) null)
|
||||
assertThat(new InMemoryConfiguration((AppConfigurationEntry[]) null).isNull()
|
||||
.getAppConfigurationEntry("name"));
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class InMemoryConfigurationTests {
|
||||
@Test
|
||||
public void nonnullDefault() {
|
||||
InMemoryConfiguration configuration = new InMemoryConfiguration(defaultEntries);
|
||||
assertArrayEquals(defaultEntries, configuration.getAppConfigurationEntry("name"));
|
||||
assertThat(configuration.getAppConfigurationEntry("name")).isEqualTo(defaultEntries);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,6 +101,6 @@ public class InMemoryConfigurationTests {
|
||||
@Test
|
||||
public void jdk5Compatable() throws Exception {
|
||||
Method method = InMemoryConfiguration.class.getDeclaredMethod("refresh");
|
||||
assertEquals(InMemoryConfiguration.class, method.getDeclaringClass());
|
||||
assertThat(method.getDeclaringClass()).isEqualTo(InMemoryConfiguration.class);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.authentication.rcp;
|
||||
|
||||
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 RemoteAuthenticationManagerImplTests {
|
||||
|
||||
manager.setAuthenticationManager(mock(AuthenticationManager.class));
|
||||
manager.afterPropertiesSet();
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-8
@@ -44,14 +44,14 @@ public class RemoteAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown RemoteAuthenticationException");
|
||||
}
|
||||
catch (RemoteAuthenticationException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testGettersSetters() {
|
||||
RemoteAuthenticationProvider provider = new RemoteAuthenticationProvider();
|
||||
provider.setRemoteAuthenticationManager(new MockRemoteAuthenticationManager(true));
|
||||
assertNotNull(provider.getRemoteAuthenticationManager());
|
||||
assertThat(provider.getRemoteAuthenticationManager()).isNotNull();
|
||||
}
|
||||
|
||||
public void testStartupChecksAuthenticationManagerSet() throws Exception {
|
||||
@@ -62,12 +62,12 @@ public class RemoteAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
provider.setRemoteAuthenticationManager(new MockRemoteAuthenticationManager(true));
|
||||
provider.afterPropertiesSet();
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
public void testSuccessfulAuthenticationCreatesObject() {
|
||||
@@ -76,9 +76,9 @@ public class RemoteAuthenticationProviderTests extends TestCase {
|
||||
|
||||
Authentication result = provider
|
||||
.authenticate(new UsernamePasswordAuthenticationToken("rod", "password"));
|
||||
assertEquals("rod", result.getPrincipal());
|
||||
assertEquals("password", result.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(result.getAuthorities()).contains(
|
||||
assertThat(result.getPrincipal()).isEqualTo("rod");
|
||||
assertThat(result.getCredentials()).isEqualTo("password");
|
||||
assertThat(AuthorityUtils.authorityListToSet(result.getAuthorities()).isTrue().contains(
|
||||
"foo"));
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RemoteAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testSupports() {
|
||||
RemoteAuthenticationProvider provider = new RemoteAuthenticationProvider();
|
||||
assertTrue(provider.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertThat(provider.supports(UsernamePasswordAuthenticationToken.class)).isTrue();
|
||||
}
|
||||
|
||||
// ~ Inner Classes
|
||||
|
||||
+7
-7
@@ -55,7 +55,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider(
|
||||
"qwerty");
|
||||
aap.afterPropertiesSet();
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
assertThat(aap.getKey()).isEqualTo("qwerty");
|
||||
}
|
||||
|
||||
public void testIgnoresClassesItDoesNotSupport() throws Exception {
|
||||
@@ -72,10 +72,10 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("user",
|
||||
"password", "ROLE_A");
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
|
||||
|
||||
// Try it anyway
|
||||
assertNull(aap.authenticate(token));
|
||||
assertThat(aap.authenticate(token)).isNull();
|
||||
}
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
@@ -87,13 +87,13 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
Authentication result = aap.authenticate(token);
|
||||
|
||||
assertEquals(result, token);
|
||||
assertThat(token).isEqualTo(result);
|
||||
}
|
||||
|
||||
public void testSupports() {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider(
|
||||
"qwerty");
|
||||
assertTrue(aap.supports(RememberMeAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
assertThat(aap.supports(RememberMeAuthenticationToken.class)).isTrue();
|
||||
assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -43,7 +43,7 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -51,7 +51,7 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -61,7 +61,7 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,21 +71,21 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
RememberMeAuthenticationToken token2 = new RememberMeAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
|
||||
assertEquals(token1, token2);
|
||||
assertThat(token2).isEqualTo(token1);
|
||||
}
|
||||
|
||||
public void testGetters() {
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
|
||||
assertEquals("key".hashCode(), token.getKeyHash());
|
||||
assertEquals("Test", token.getPrincipal());
|
||||
assertEquals("", token.getCredentials());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
assertThat(token.getKeyHash()).isEqualTo("key".hashCode());
|
||||
assertThat(token.getPrincipal()).isEqualTo("Test");
|
||||
assertThat(token.getCredentials()).isEqualTo("");
|
||||
assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).isTrue().contains(
|
||||
"ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).isTrue().contains(
|
||||
"ROLE_TWO"));
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
}
|
||||
|
||||
public void testNotEqualsDueToAbstractParentEqualsCheck() {
|
||||
@@ -94,7 +94,7 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
RememberMeAuthenticationToken token2 = new RememberMeAuthenticationToken("key",
|
||||
"DIFFERENT_PRINCIPAL", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testNotEqualsDueToDifferentAuthenticationClass() {
|
||||
@@ -103,7 +103,7 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
UsernamePasswordAuthenticationToken token2 = new UsernamePasswordAuthenticationToken(
|
||||
"Test", "Password", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testNotEqualsDueToKey() {
|
||||
@@ -112,14 +112,14 @@ public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
RememberMeAuthenticationToken token2 = new RememberMeAuthenticationToken(
|
||||
"DIFFERENT_KEY", "Test", ROLES_12);
|
||||
|
||||
assertFalse(token1.equals(token2));
|
||||
assertThat(token1.equals(token2)).isFalse();
|
||||
}
|
||||
|
||||
public void testSetAuthenticatedIgnored() {
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("key",
|
||||
"Test", ROLES_12);
|
||||
assertTrue(token.isAuthenticated());
|
||||
assertThat(token.isAuthenticated()).isTrue();
|
||||
token.setAuthenticated(false);
|
||||
assertTrue(!token.isAuthenticated());
|
||||
assertThat(!token.isAuthenticated()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.concurrent;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.concurrent;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.concurrent;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.concurrent;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.concurrent;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.SmartApplicationListener;
|
||||
import org.springframework.security.core.session.SessionDestroyedEvent;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -70,4 +70,4 @@ public class DelegatingApplicationListenerTests {
|
||||
listener.addListener(null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.core;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.core;
|
||||
|
||||
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.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -64,7 +64,7 @@ public class SpringSecurityCoreVersionTests {
|
||||
// Property is set by the build script
|
||||
String springVersion = System.getProperty("springVersion");
|
||||
|
||||
assertEquals(springVersion, SpringSecurityCoreVersion.MIN_SPRING_VERSION);
|
||||
assertThat(SpringSecurityCoreVersion.MIN_SPRING_VERSION).isEqualTo(springVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,8 +75,8 @@ public class SpringSecurityCoreVersionTests {
|
||||
String serialVersion = String.valueOf(
|
||||
SpringSecurityCoreVersion.SERIAL_VERSION_UID).substring(0, 2);
|
||||
|
||||
assertEquals(version.charAt(0), serialVersion.charAt(0));
|
||||
assertEquals(version.charAt(2), serialVersion.charAt(1));
|
||||
assertThat(serialVersion.charAt(0)).isEqualTo(version.charAt(0));
|
||||
assertThat(serialVersion.charAt(1)).isEqualTo(version.charAt(2));
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -21,10 +21,10 @@ public class AuthorityUtilsTests {
|
||||
|
||||
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"));
|
||||
assertThat(authorities.contains("B")).isTrue();
|
||||
assertThat(authorities.contains("C")).isTrue();
|
||||
assertThat(authorities.contains("E")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_A")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_D")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.core.authority;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.*;
|
||||
@@ -31,23 +31,23 @@ public class SimpleGrantedAuthorityTests {
|
||||
@Test
|
||||
public void equalsBehavesAsExpected() throws Exception {
|
||||
SimpleGrantedAuthority auth1 = new SimpleGrantedAuthority("TEST");
|
||||
assertEquals(auth1, auth1);
|
||||
assertEquals(auth1, new SimpleGrantedAuthority("TEST"));
|
||||
assertThat(auth1).isEqualTo(auth1);
|
||||
assertThat(new SimpleGrantedAuthority("TEST")).isEqualTo(auth1);
|
||||
|
||||
assertFalse(auth1.equals("TEST"));
|
||||
assertThat(auth1.equals("TEST")).isFalse();
|
||||
|
||||
SimpleGrantedAuthority auth3 = new SimpleGrantedAuthority("NOT_EQUAL");
|
||||
assertTrue(!auth1.equals(auth3));
|
||||
assertThat(!auth1.equals(auth3)).isTrue();
|
||||
|
||||
assertFalse(auth1.equals(mock(GrantedAuthority.class)));
|
||||
assertThat(auth1.equals(mock(GrantedAuthority.class))).isFalse();
|
||||
|
||||
assertFalse(auth1.equals(Integer.valueOf(222)));
|
||||
assertThat(auth1.equals(Integer.valueOf(222))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringReturnsAuthorityValue() {
|
||||
SimpleGrantedAuthority auth = new SimpleGrantedAuthority("TEST");
|
||||
assertEquals("TEST", auth.toString());
|
||||
assertThat(auth.toString()).isEqualTo("TEST");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Executable → Regular
+15
-15
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.core.authority.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -26,8 +26,8 @@ public class SimpleAuthoritiesMapperTests {
|
||||
SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
|
||||
Set<String> mapped = AuthorityUtils.authorityListToSet(mapper
|
||||
.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "ROLE_bbb")));
|
||||
assertTrue(mapped.contains("ROLE_AaA"));
|
||||
assertTrue(mapped.contains("ROLE_bbb"));
|
||||
assertThat(mapped.contains("ROLE_AaA")).isTrue();
|
||||
assertThat(mapped.contains("ROLE_bbb")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -37,22 +37,22 @@ public class SimpleAuthoritiesMapperTests {
|
||||
List<GrantedAuthority> toMap = AuthorityUtils.createAuthorityList("AaA", "Bbb");
|
||||
Set<String> mapped = AuthorityUtils.authorityListToSet(mapper
|
||||
.mapAuthorities(toMap));
|
||||
assertEquals(2, mapped.size());
|
||||
assertTrue(mapped.contains("AaA"));
|
||||
assertTrue(mapped.contains("Bbb"));
|
||||
assertThat(mapped).hasSize(2);
|
||||
assertThat(mapped.contains("AaA")).isTrue();
|
||||
assertThat(mapped.contains("Bbb")).isTrue();
|
||||
|
||||
mapper.setConvertToLowerCase(true);
|
||||
mapped = AuthorityUtils.authorityListToSet(mapper.mapAuthorities(toMap));
|
||||
assertEquals(2, mapped.size());
|
||||
assertTrue(mapped.contains("aaa"));
|
||||
assertTrue(mapped.contains("bbb"));
|
||||
assertThat(mapped).hasSize(2);
|
||||
assertThat(mapped.contains("aaa")).isTrue();
|
||||
assertThat(mapped.contains("bbb")).isTrue();
|
||||
|
||||
mapper.setConvertToLowerCase(false);
|
||||
mapper.setConvertToUpperCase(true);
|
||||
mapped = AuthorityUtils.authorityListToSet(mapper.mapAuthorities(toMap));
|
||||
assertEquals(2, mapped.size());
|
||||
assertTrue(mapped.contains("AAA"));
|
||||
assertTrue(mapped.contains("BBB"));
|
||||
assertThat(mapped).hasSize(2);
|
||||
assertThat(mapped.contains("AAA")).isTrue();
|
||||
assertThat(mapped.contains("BBB")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +62,7 @@ public class SimpleAuthoritiesMapperTests {
|
||||
|
||||
Set<String> mapped = AuthorityUtils.authorityListToSet(mapper
|
||||
.mapAuthorities(AuthorityUtils.createAuthorityList("AaA", "AAA")));
|
||||
assertEquals(1, mapped.size());
|
||||
assertThat(mapped).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +71,7 @@ public class SimpleAuthoritiesMapperTests {
|
||||
mapper.setDefaultAuthority("ROLE_USER");
|
||||
Set<String> mapped = AuthorityUtils.authorityListToSet(mapper
|
||||
.mapAuthorities(AuthorityUtils.NO_AUTHORITIES));
|
||||
assertEquals(1, mapped.size());
|
||||
assertTrue(mapped.contains("ROLE_USER"));
|
||||
assertThat(mapped).hasSize(1);
|
||||
assertThat(mapped.contains("ROLE_USER")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
Executable → Regular
+4
-4
@@ -39,14 +39,14 @@ public class SecurityContextHolderTests extends TestCase {
|
||||
SecurityContext sc = new SecurityContextImpl();
|
||||
sc.setAuthentication(new UsernamePasswordAuthenticationToken("Foobar", "pass"));
|
||||
SecurityContextHolder.setContext(sc);
|
||||
assertEquals(sc, SecurityContextHolder.getContext());
|
||||
assertThat(SecurityContextHolder.getContext()).isEqualTo(sc);
|
||||
SecurityContextHolder.clearContext();
|
||||
assertNotSame(sc, SecurityContextHolder.getContext());
|
||||
assertThat(SecurityContextHolder.getContext()).isNotSameAs(sc);
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testNeverReturnsNull() {
|
||||
assertNotNull(SecurityContextHolder.getContext());
|
||||
assertThat(SecurityContextHolder.getContext()).isNotNull();
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SecurityContextHolderTests extends TestCase {
|
||||
fail("Should have rejected null");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -44,14 +44,14 @@ public class SecurityContextImplTests extends TestCase {
|
||||
public void testEmptyObjectsAreEquals() {
|
||||
SecurityContextImpl obj1 = new SecurityContextImpl();
|
||||
SecurityContextImpl obj2 = new SecurityContextImpl();
|
||||
assertTrue(obj1.equals(obj2));
|
||||
assertThat(obj1.equals(obj2)).isTrue();
|
||||
}
|
||||
|
||||
public void testSecurityContextCorrectOperation() {
|
||||
SecurityContext context = new SecurityContextImpl();
|
||||
Authentication auth = new UsernamePasswordAuthenticationToken("rod", "koala");
|
||||
context.setAuthentication(auth);
|
||||
assertEquals(auth, context.getAuthentication());
|
||||
assertTrue(context.toString().lastIndexOf("rod") != -1);
|
||||
assertThat(context.getAuthentication()).isEqualTo(auth);
|
||||
assertThat(context.toString().lastIndexOf("rod") != -1).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.core.parameters;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.core.parameters;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
+4
-4
@@ -37,14 +37,14 @@ public class SessionInformationTests extends TestCase {
|
||||
|
||||
SessionInformation info = new SessionInformation(principal, sessionId,
|
||||
currentDate);
|
||||
assertEquals(principal, info.getPrincipal());
|
||||
assertEquals(sessionId, info.getSessionId());
|
||||
assertEquals(currentDate, info.getLastRequest());
|
||||
assertThat(info.getPrincipal()).isEqualTo(principal);
|
||||
assertThat(info.getSessionId()).isEqualTo(sessionId);
|
||||
assertThat(info.getLastRequest()).isEqualTo(currentDate);
|
||||
|
||||
Thread.sleep(10);
|
||||
|
||||
info.refreshLastRequest();
|
||||
|
||||
assertTrue(info.getLastRequest().after(currentDate));
|
||||
assertThat(info.getLastRequest().after(currentDate)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.core.session;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -65,7 +65,7 @@ public class SessionRegistryImplTests {
|
||||
});
|
||||
|
||||
// Check attempts to retrieve cleared session return null
|
||||
assertNull(sessionRegistry.getSessionInformation(sessionId));
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,9 +80,9 @@ public class SessionRegistryImplTests {
|
||||
sessionRegistry.registerNewSession(sessionId2, principal1);
|
||||
sessionRegistry.registerNewSession(sessionId3, principal2);
|
||||
|
||||
assertEquals(2, sessionRegistry.getAllPrincipals().size());
|
||||
assertTrue(sessionRegistry.getAllPrincipals().contains(principal1));
|
||||
assertTrue(sessionRegistry.getAllPrincipals().contains(principal2));
|
||||
assertThat(sessionRegistry.getAllPrincipals()).hasSize(2);
|
||||
assertThat(sessionRegistry.getAllPrincipals().contains(principal1)).isTrue();
|
||||
assertThat(sessionRegistry.getAllPrincipals().contains(principal2)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,14 +95,14 @@ public class SessionRegistryImplTests {
|
||||
// Retrieve existing session by session ID
|
||||
Date currentDateTime = sessionRegistry.getSessionInformation(sessionId)
|
||||
.getLastRequest();
|
||||
assertEquals(principal, sessionRegistry.getSessionInformation(sessionId)
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId).isEqualTo(principal)
|
||||
.getPrincipal());
|
||||
assertEquals(sessionId, sessionRegistry.getSessionInformation(sessionId)
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId).isEqualTo(sessionId)
|
||||
.getSessionId());
|
||||
assertNotNull(sessionRegistry.getSessionInformation(sessionId).getLastRequest());
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId).getLastRequest()).isNotNull();
|
||||
|
||||
// Retrieve existing session by principal
|
||||
assertEquals(1, sessionRegistry.getAllSessions(principal, false).size());
|
||||
assertThat(sessionRegistry.getAllSessions(principal, false)).hasSize(1);
|
||||
|
||||
// Sleep to ensure SessionRegistryImpl will update time
|
||||
Thread.sleep(1000);
|
||||
@@ -112,18 +112,18 @@ public class SessionRegistryImplTests {
|
||||
|
||||
Date retrieved = sessionRegistry.getSessionInformation(sessionId)
|
||||
.getLastRequest();
|
||||
assertTrue(retrieved.after(currentDateTime));
|
||||
assertThat(retrieved.after(currentDateTime)).isTrue();
|
||||
|
||||
// Check it retrieves correctly when looked up via principal
|
||||
assertEquals(retrieved, sessionRegistry.getAllSessions(principal, false).get(0)
|
||||
assertThat(sessionRegistry.getAllSessions(principal).isCloseTo(retrieved, within(false).get(0))
|
||||
.getLastRequest());
|
||||
|
||||
// Clear session information
|
||||
sessionRegistry.removeSessionInformation(sessionId);
|
||||
|
||||
// Check attempts to retrieve cleared session return null
|
||||
assertNull(sessionRegistry.getSessionInformation(sessionId));
|
||||
assertEquals(0, sessionRegistry.getAllSessions(principal, false).size());
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId)).isNull();
|
||||
assertThat(sessionRegistry.getAllSessions(principal, false)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,21 +135,21 @@ public class SessionRegistryImplTests {
|
||||
sessionRegistry.registerNewSession(sessionId1, principal);
|
||||
List<SessionInformation> sessions = sessionRegistry.getAllSessions(principal,
|
||||
false);
|
||||
assertEquals(1, sessions.size());
|
||||
assertTrue(contains(sessionId1, principal));
|
||||
assertThat(sessions).hasSize(1);
|
||||
assertThat(contains(sessionId1, principal)).isTrue();
|
||||
|
||||
sessionRegistry.registerNewSession(sessionId2, principal);
|
||||
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||
assertEquals(2, sessions.size());
|
||||
assertTrue(contains(sessionId2, principal));
|
||||
assertThat(sessions).hasSize(2);
|
||||
assertThat(contains(sessionId2, principal)).isTrue();
|
||||
|
||||
// Expire one session
|
||||
SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
|
||||
session.expireNow();
|
||||
|
||||
// Check retrieval still correct
|
||||
assertTrue(sessionRegistry.getSessionInformation(sessionId2).isExpired());
|
||||
assertFalse(sessionRegistry.getSessionInformation(sessionId1).isExpired());
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId2).isExpired()).isTrue();
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId1).isExpired()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,22 +161,22 @@ public class SessionRegistryImplTests {
|
||||
sessionRegistry.registerNewSession(sessionId1, principal);
|
||||
List<SessionInformation> sessions = sessionRegistry.getAllSessions(principal,
|
||||
false);
|
||||
assertEquals(1, sessions.size());
|
||||
assertTrue(contains(sessionId1, principal));
|
||||
assertThat(sessions).hasSize(1);
|
||||
assertThat(contains(sessionId1, principal)).isTrue();
|
||||
|
||||
sessionRegistry.registerNewSession(sessionId2, principal);
|
||||
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||
assertEquals(2, sessions.size());
|
||||
assertTrue(contains(sessionId2, principal));
|
||||
assertThat(sessions).hasSize(2);
|
||||
assertThat(contains(sessionId2, principal)).isTrue();
|
||||
|
||||
sessionRegistry.removeSessionInformation(sessionId1);
|
||||
sessions = sessionRegistry.getAllSessions(principal, false);
|
||||
assertEquals(1, sessions.size());
|
||||
assertTrue(contains(sessionId2, principal));
|
||||
assertThat(sessions).hasSize(1);
|
||||
assertThat(contains(sessionId2, principal)).isTrue();
|
||||
|
||||
sessionRegistry.removeSessionInformation(sessionId2);
|
||||
assertNull(sessionRegistry.getSessionInformation(sessionId2));
|
||||
assertEquals(0, sessionRegistry.getAllSessions(principal, false).size());
|
||||
assertThat(sessionRegistry.getSessionInformation(sessionId2)).isNull();
|
||||
assertThat(sessionRegistry.getAllSessions(principal, false)).isEmpty();
|
||||
}
|
||||
|
||||
private boolean contains(String sessionId, Object principal) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DefaultTokenTests {
|
||||
|
||||
DefaultToken t1 = new DefaultToken(key, created, extendedInformation);
|
||||
DefaultToken t2 = new DefaultToken(key, created, extendedInformation);
|
||||
Assert.assertEquals(t1, t2);
|
||||
Assert.assertThat(t2).isEqualTo(t1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -39,6 +39,6 @@ public class DefaultTokenTests {
|
||||
|
||||
DefaultToken t1 = new DefaultToken(key, created, "length1");
|
||||
DefaultToken t2 = new DefaultToken(key, created, "longerLength2");
|
||||
Assert.assertFalse(t1.equals(t2));
|
||||
Assert.assertThat(t1.equals(t2)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -40,7 +40,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
Token token = service.allocateToken("Hello world");
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
Assert.assertThat(result).isEqualTo(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,7 +48,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
Token token = service.allocateToken("Hello:world:::");
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
Assert.assertThat(result).isEqualTo(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +57,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
service.setPseudoRandomNumberBytes(0);
|
||||
Token token = service.allocateToken("Hello:world:::");
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
Assert.assertThat(result).isEqualTo(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +65,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
Token token = service.allocateToken("");
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
Assert.assertThat(result).isEqualTo(token);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
+7
-7
@@ -19,22 +19,22 @@ public class SecureRandomFactoryBeanTests {
|
||||
@Test
|
||||
public void testObjectType() {
|
||||
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
|
||||
Assert.assertEquals(SecureRandom.class, factory.getObjectType());
|
||||
Assert.assertThat(factory.getObjectType()).isEqualTo(SecureRandom.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSingleton() {
|
||||
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
|
||||
Assert.assertFalse(factory.isSingleton());
|
||||
Assert.assertThat(factory.isSingleton()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatesUsingDefaults() throws Exception {
|
||||
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
|
||||
Object result = factory.getObject();
|
||||
Assert.assertTrue(result instanceof SecureRandom);
|
||||
Assert.assertThat(result instanceof SecureRandom).isTrue();
|
||||
int rnd = ((SecureRandom) result).nextInt();
|
||||
Assert.assertTrue(rnd != 0);
|
||||
Assert.assertThat(rnd != 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,12 +42,12 @@ public class SecureRandomFactoryBeanTests {
|
||||
SecureRandomFactoryBean factory = new SecureRandomFactoryBean();
|
||||
Resource resource = new ClassPathResource(
|
||||
"org/springframework/security/core/token/SecureRandomFactoryBeanTests.class");
|
||||
Assert.assertNotNull(resource);
|
||||
Assert.assertThat(resource).isNotNull();
|
||||
factory.setSeed(resource);
|
||||
Object result = factory.getObject();
|
||||
Assert.assertTrue(result instanceof SecureRandom);
|
||||
Assert.assertThat(result instanceof SecureRandom).isTrue();
|
||||
int rnd = ((SecureRandom) result).nextInt();
|
||||
Assert.assertTrue(rnd != 0);
|
||||
Assert.assertThat(rnd != 0).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Executable → Regular
+2
-2
@@ -43,10 +43,10 @@ public class UserDetailsByNameServiceWrapperTests extends TestCase {
|
||||
svc.afterPropertiesSet();
|
||||
UserDetails result1 = svc.loadUserDetails(new TestingAuthenticationToken("dummy",
|
||||
"dummy"));
|
||||
assertEquals("Result doesn't match original user", user, result1);
|
||||
assertThat(result1).as("Result doesn't match original user").isEqualTo(user);
|
||||
UserDetails result2 = svc.loadUserDetails(new TestingAuthenticationToken(
|
||||
"dummy2", "dummy"));
|
||||
assertNull("Result should have been null", result2);
|
||||
assertThat(result2).as("Result should have been null").isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.core.userdetails;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
@@ -44,9 +44,9 @@ public class UserTests {
|
||||
public void equalsReturnsTrueIfUsernamesAreTheSame() {
|
||||
User user1 = new User("rod", "koala", true, true, true, true, ROLE_12);
|
||||
|
||||
assertFalse(user1.equals(null));
|
||||
assertFalse(user1.equals("A STRING"));
|
||||
assertTrue(user1.equals(user1));
|
||||
assertThat(user1.equals(null)).isFalse();
|
||||
assertThat(user1.equals("A STRING")).isFalse();
|
||||
assertThat(user1.equals(user1)).isTrue();
|
||||
assertTrue(user1.equals(new User("rod", "notthesame", true, true, true, true,
|
||||
ROLE_12)));
|
||||
}
|
||||
@@ -120,20 +120,20 @@ public class UserTests {
|
||||
public void testUserGettersSetter() throws Exception {
|
||||
UserDetails user = new User("rod", "koala", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_TWO", "ROLE_ONE"));
|
||||
assertEquals("rod", user.getUsername());
|
||||
assertEquals("koala", user.getPassword());
|
||||
assertTrue(user.isEnabled());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(user.getUsername()).isEqualTo("rod");
|
||||
assertThat(user.getPassword()).isEqualTo("koala");
|
||||
assertThat(user.isEnabled()).isTrue();
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_ONE"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_TWO"));
|
||||
assertTrue(user.toString().indexOf("rod") != -1);
|
||||
assertThat(user.toString().indexOf("rod") != -1).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledFlagIsFalseForDisabledAccount() throws Exception {
|
||||
UserDetails user = new User("rod", "koala", false, true, true, true, ROLE_12);
|
||||
assertFalse(user.isEnabled());
|
||||
assertThat(user.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.core.userdetails.cache;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
@@ -75,11 +75,11 @@ public class EhCacheBasedUserCacheTests {
|
||||
|
||||
// Check it gets removed from the cache
|
||||
cache.removeUserFromCache(getUser());
|
||||
assertNull(cache.getUserFromCache(getUser().getUsername()));
|
||||
assertThat(cache.getUserFromCache(getUser().getUsername())).isNull();
|
||||
|
||||
// Check it doesn't return values for null or unknown users
|
||||
assertNull(cache.getUserFromCache(null));
|
||||
assertNull(cache.getUserFromCache("UNKNOWN_USER"));
|
||||
assertThat(cache.getUserFromCache(null)).isNull();
|
||||
assertThat(cache.getUserFromCache("UNKNOWN_USER")).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -91,6 +91,6 @@ public class EhCacheBasedUserCacheTests {
|
||||
|
||||
Ehcache myCache = getCache();
|
||||
cache.setCache(myCache);
|
||||
assertEquals(myCache, cache.getCache());
|
||||
assertThat(cache.getCache()).isEqualTo(myCache);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -39,7 +39,7 @@ public class NullUserCacheTests extends TestCase {
|
||||
public void testCacheOperation() throws Exception {
|
||||
NullUserCache cache = new NullUserCache();
|
||||
cache.putUserInCache(getUser());
|
||||
assertNull(cache.getUserFromCache(null));
|
||||
assertThat(cache.getUserFromCache(null)).isNull();
|
||||
cache.removeUserFromCache(null);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests
|
||||
@@ -71,11 +71,11 @@ public class SpringCacheBasedUserCacheTests {
|
||||
|
||||
// Check it gets removed from the cache
|
||||
cache.removeUserFromCache(getUser());
|
||||
assertNull(cache.getUserFromCache(getUser().getUsername()));
|
||||
assertThat(cache.getUserFromCache(getUser().getUsername())).isNull();
|
||||
|
||||
// Check it doesn't return values for null or unknown users
|
||||
assertNull(cache.getUserFromCache(null));
|
||||
assertNull(cache.getUserFromCache("UNKNOWN_USER"));
|
||||
assertThat(cache.getUserFromCache(null)).isNull();
|
||||
assertThat(cache.getUserFromCache("UNKNOWN_USER")).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
+22
-22
@@ -52,37 +52,37 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
public void testCheckDaoAccessUserSuccess() throws Exception {
|
||||
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
||||
UserDetails user = dao.loadUserByUsername("rod");
|
||||
assertEquals("rod", user.getUsername());
|
||||
assertEquals("koala", user.getPassword());
|
||||
assertTrue(user.isEnabled());
|
||||
assertThat(user.getUsername()).isEqualTo("rod");
|
||||
assertThat(user.getPassword()).isEqualTo("koala");
|
||||
assertThat(user.isEnabled()).isTrue();
|
||||
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_TELLER"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_SUPERVISOR"));
|
||||
}
|
||||
|
||||
public void testCheckDaoOnlyReturnsGrantedAuthoritiesGrantedToUser() throws Exception {
|
||||
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
||||
UserDetails user = dao.loadUserByUsername("scott");
|
||||
assertEquals(1, user.getAuthorities().size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ROLE_TELLER"));
|
||||
}
|
||||
|
||||
public void testCheckDaoReturnsCorrectDisabledProperty() throws Exception {
|
||||
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
||||
UserDetails user = dao.loadUserByUsername("peter");
|
||||
assertTrue(!user.isEnabled());
|
||||
assertThat(!user.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
public void testGettersSetters() {
|
||||
JdbcDaoImpl dao = new JdbcDaoImpl();
|
||||
dao.setAuthoritiesByUsernameQuery("SELECT * FROM FOO");
|
||||
assertEquals("SELECT * FROM FOO", dao.getAuthoritiesByUsernameQuery());
|
||||
assertThat(dao.getAuthoritiesByUsernameQuery()).isEqualTo("SELECT * FROM FOO");
|
||||
|
||||
dao.setUsersByUsernameQuery("SELECT USERS FROM FOO");
|
||||
assertEquals("SELECT USERS FROM FOO", dao.getUsersByUsernameQuery());
|
||||
assertThat(dao.getUsersByUsernameQuery()).isEqualTo("SELECT USERS FROM FOO");
|
||||
}
|
||||
|
||||
public void testLookupFailsIfUserHasNoGrantedAuthorities() throws Exception {
|
||||
@@ -104,27 +104,27 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
fail("Should have thrown UsernameNotFoundException");
|
||||
}
|
||||
catch (UsernameNotFoundException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testLookupSuccessWithMixedCase() throws Exception {
|
||||
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
||||
assertEquals("koala", dao.loadUserByUsername("rod").getPassword());
|
||||
assertEquals("wombat", dao.loadUserByUsername("ScOTt").getPassword());
|
||||
assertThat(dao.loadUserByUsername("rod").getPassword()).isEqualTo("koala");
|
||||
assertThat(dao.loadUserByUsername("ScOTt").getPassword()).isEqualTo("wombat");
|
||||
}
|
||||
|
||||
public void testRolePrefixWorks() throws Exception {
|
||||
JdbcDaoImpl dao = makePopulatedJdbcDaoWithRolePrefix();
|
||||
assertEquals("ARBITRARY_PREFIX_", dao.getRolePrefix());
|
||||
assertThat(dao.getRolePrefix()).isEqualTo("ARBITRARY_PREFIX_");
|
||||
|
||||
UserDetails user = dao.loadUserByUsername("rod");
|
||||
assertEquals("rod", user.getUsername());
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertThat(user.getUsername()).isEqualTo("rod");
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ARBITRARY_PREFIX_ROLE_TELLER"));
|
||||
assertTrue(AuthorityUtils.authorityListToSet(user.getAuthorities()).contains(
|
||||
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities()).isTrue().contains(
|
||||
"ARBITRARY_PREFIX_ROLE_SUPERVISOR"));
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
dao.setEnableGroups(true);
|
||||
|
||||
UserDetails jerry = dao.loadUserByUsername("jerry");
|
||||
assertEquals(3, jerry.getAuthorities().size());
|
||||
assertThat(jerry.getAuthorities()).hasSize(3);
|
||||
}
|
||||
|
||||
public void testDuplicateGroupAuthoritiesAreRemoved() throws Exception {
|
||||
@@ -143,7 +143,7 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
dao.setEnableGroups(true);
|
||||
// Tom has roles A, B, C and B, C duplicates
|
||||
UserDetails tom = dao.loadUserByUsername("tom");
|
||||
assertEquals(3, tom.getAuthorities().size());
|
||||
assertThat(tom.getAuthorities()).hasSize(3);
|
||||
}
|
||||
|
||||
public void testStartupFailsIfDataSourceNotSet() throws Exception {
|
||||
@@ -154,7 +154,7 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class JdbcDaoImplTests extends TestCase {
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -32,10 +32,10 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("password ,ROLE_ONE,ROLE_TWO ");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertEquals("password", user.getPassword());
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertEquals("ROLE_ONE", user.getAuthorities().get(0).getAuthority());
|
||||
assertEquals("ROLE_TWO", user.getAuthorities().get(1).getAuthority());
|
||||
assertThat(user.getPassword()).isEqualTo("password");
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
assertThat(user.getAuthorities().get(0).getAuthority()).isEqualTo("ROLE_ONE");
|
||||
assertThat(user.getAuthorities().get(1).getAuthority()).isEqualTo("ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testCorrectOperationWithoutEnabledDisabledKeyword() {
|
||||
@@ -43,12 +43,12 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("password,ROLE_ONE,ROLE_TWO");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user.isValid());
|
||||
assertTrue(user.isEnabled()); // default
|
||||
assertEquals("password", user.getPassword());
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertEquals("ROLE_ONE", user.getAuthorities().get(0).getAuthority());
|
||||
assertEquals("ROLE_TWO", user.getAuthorities().get(1).getAuthority());
|
||||
assertThat(user.isValid()).isTrue();
|
||||
assertThat(user.isEnabled()).isTrue(); // default
|
||||
assertThat(user.getPassword()).isEqualTo("password");
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
assertThat(user.getAuthorities().get(0).getAuthority()).isEqualTo("ROLE_ONE");
|
||||
assertThat(user.getAuthorities().get(1).getAuthority()).isEqualTo("ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testDisabledKeyword() {
|
||||
@@ -56,12 +56,12 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("password,disabled,ROLE_ONE,ROLE_TWO");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user.isValid());
|
||||
assertTrue(!user.isEnabled());
|
||||
assertEquals("password", user.getPassword());
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertEquals("ROLE_ONE", user.getAuthorities().get(0).getAuthority());
|
||||
assertEquals("ROLE_TWO", user.getAuthorities().get(1).getAuthority());
|
||||
assertThat(user.isValid()).isTrue();
|
||||
assertThat(!user.isEnabled()).isTrue();
|
||||
assertThat(user.getPassword()).isEqualTo("password");
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
assertThat(user.getAuthorities().get(0).getAuthority()).isEqualTo("ROLE_ONE");
|
||||
assertThat(user.getAuthorities().get(1).getAuthority()).isEqualTo("ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testEmptyStringReturnsNull() {
|
||||
@@ -69,7 +69,7 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user == null);
|
||||
assertThat(user == null).isTrue();
|
||||
}
|
||||
|
||||
public void testEnabledKeyword() {
|
||||
@@ -77,12 +77,12 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("password,ROLE_ONE,enabled,ROLE_TWO");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user.isValid());
|
||||
assertTrue(user.isEnabled());
|
||||
assertEquals("password", user.getPassword());
|
||||
assertEquals(2, user.getAuthorities().size());
|
||||
assertEquals("ROLE_ONE", user.getAuthorities().get(0).getAuthority());
|
||||
assertEquals("ROLE_TWO", user.getAuthorities().get(1).getAuthority());
|
||||
assertThat(user.isValid()).isTrue();
|
||||
assertThat(user.isEnabled()).isTrue();
|
||||
assertThat(user.getPassword()).isEqualTo("password");
|
||||
assertThat(user.getAuthorities()).hasSize(2);
|
||||
assertThat(user.getAuthorities().get(0).getAuthority()).isEqualTo("ROLE_ONE");
|
||||
assertThat(user.getAuthorities().get(1).getAuthority()).isEqualTo("ROLE_TWO");
|
||||
}
|
||||
|
||||
public void testMalformedStringReturnsNull() {
|
||||
@@ -90,7 +90,7 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("MALFORMED_STRING");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user == null);
|
||||
assertThat(user == null).isTrue();
|
||||
}
|
||||
|
||||
public void testNoPasswordOrRolesReturnsNull() {
|
||||
@@ -98,7 +98,7 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("disabled");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user == null);
|
||||
assertThat(user == null).isTrue();
|
||||
}
|
||||
|
||||
public void testNoRolesReturnsNull() {
|
||||
@@ -106,7 +106,7 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText("password,enabled");
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user == null);
|
||||
assertThat(user == null).isTrue();
|
||||
}
|
||||
|
||||
public void testNullReturnsNull() {
|
||||
@@ -114,6 +114,6 @@ public class UserAttributeEditorTests extends TestCase {
|
||||
editor.setAsText(null);
|
||||
|
||||
UserAttribute user = (UserAttribute) editor.getValue();
|
||||
assertTrue(user == null);
|
||||
assertThat(user == null).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -1,8 +1,8 @@
|
||||
package org.springframework.security.provisioning;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -98,7 +98,7 @@ public class JdbcUserDetailsManagerTests {
|
||||
|
||||
UserDetails joe2 = manager.loadUserByUsername("joe");
|
||||
|
||||
assertEquals(joe, joe2);
|
||||
assertThat(joe2).isEqualTo(joe);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,9 +106,9 @@ public class JdbcUserDetailsManagerTests {
|
||||
insertJoe();
|
||||
manager.deleteUser("joe");
|
||||
|
||||
assertEquals(0, template.queryForList(SELECT_JOE_SQL).size());
|
||||
assertEquals(0, template.queryForList(SELECT_JOE_AUTHORITIES_SQL).size());
|
||||
assertFalse(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(template.queryForList(SELECT_JOE_SQL)).isEmpty();
|
||||
assertThat(template.queryForList(SELECT_JOE_AUTHORITIES_SQL)).isEmpty();
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,20 +121,20 @@ public class JdbcUserDetailsManagerTests {
|
||||
|
||||
UserDetails joe = manager.loadUserByUsername("joe");
|
||||
|
||||
assertEquals(newJoe, joe);
|
||||
assertFalse(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(joe).isEqualTo(newJoe);
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userExistsReturnsFalseForNonExistentUsername() {
|
||||
assertFalse(manager.userExists("joe"));
|
||||
assertThat(manager.userExists("joe")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userExistsReturnsTrueForExistingUsername() {
|
||||
insertJoe();
|
||||
assertTrue(manager.userExists("joe"));
|
||||
assertTrue(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(manager.userExists("joe")).isTrue();
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
@@ -149,8 +149,8 @@ public class JdbcUserDetailsManagerTests {
|
||||
manager.changePassword("wrongpassword", "newPassword");
|
||||
UserDetails newJoe = manager.loadUserByUsername("joe");
|
||||
|
||||
assertEquals("newPassword", newJoe.getPassword());
|
||||
assertFalse(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(newJoe.getPassword()).isEqualTo("newPassword");
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,13 +164,13 @@ public class JdbcUserDetailsManagerTests {
|
||||
manager.changePassword("password", "newPassword");
|
||||
UserDetails newJoe = manager.loadUserByUsername("joe");
|
||||
|
||||
assertEquals("newPassword", newJoe.getPassword());
|
||||
assertThat(newJoe.getPassword()).isEqualTo("newPassword");
|
||||
// The password in the context should also be altered
|
||||
Authentication newAuth = SecurityContextHolder.getContext().getAuthentication();
|
||||
assertEquals("joe", newAuth.getName());
|
||||
assertEquals(currentAuth.getDetails(), newAuth.getDetails());
|
||||
assertThat(newAuth.getName()).isEqualTo("joe");
|
||||
assertThat(newAuth.getDetails()).isEqualTo(currentAuth.getDetails());
|
||||
assertThat(newAuth.getCredentials()).isNull();
|
||||
assertFalse(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,31 +192,31 @@ public class JdbcUserDetailsManagerTests {
|
||||
|
||||
// Check password hasn't changed.
|
||||
UserDetails newJoe = manager.loadUserByUsername("joe");
|
||||
assertEquals("password", newJoe.getPassword());
|
||||
assertEquals("password", SecurityContextHolder.getContext().getAuthentication()
|
||||
assertThat(newJoe.getPassword()).isEqualTo("password");
|
||||
assertThat(SecurityContextHolder.getContext().getAuthentication().isEqualTo("password")
|
||||
.getCredentials());
|
||||
assertTrue(cache.getUserMap().containsKey("joe"));
|
||||
assertThat(cache.getUserMap().containsKey("joe")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllGroupsReturnsExpectedGroupNames() {
|
||||
List<String> groups = manager.findAllGroups();
|
||||
assertEquals(4, groups.size());
|
||||
assertThat(groups).hasSize(4);
|
||||
|
||||
Collections.sort(groups);
|
||||
assertEquals("GROUP_0", groups.get(0));
|
||||
assertEquals("GROUP_1", groups.get(1));
|
||||
assertEquals("GROUP_2", groups.get(2));
|
||||
assertEquals("GROUP_3", groups.get(3));
|
||||
assertThat(groups.get(0)).isEqualTo("GROUP_0");
|
||||
assertThat(groups.get(1)).isEqualTo("GROUP_1");
|
||||
assertThat(groups.get(2)).isEqualTo("GROUP_2");
|
||||
assertThat(groups.get(3)).isEqualTo("GROUP_3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findGroupMembersReturnsCorrectData() {
|
||||
List<String> groupMembers = manager.findUsersInGroup("GROUP_0");
|
||||
assertEquals(1, groupMembers.size());
|
||||
assertEquals("jerry", groupMembers.get(0));
|
||||
assertThat(groupMembers).hasSize(1);
|
||||
assertThat(groupMembers.get(0)).isEqualTo("jerry");
|
||||
groupMembers = manager.findUsersInGroup("GROUP_1");
|
||||
assertEquals(2, groupMembers.size());
|
||||
assertThat(groupMembers).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +229,7 @@ public class JdbcUserDetailsManagerTests {
|
||||
.queryForList("select ga.authority from groups g, group_authorities ga "
|
||||
+ "where ga.group_id = g.id " + "and g.group_name = 'TEST_GROUP'");
|
||||
|
||||
assertEquals(2, roles.size());
|
||||
assertThat(roles).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,9 +239,9 @@ public class JdbcUserDetailsManagerTests {
|
||||
manager.deleteGroup("GROUP_2");
|
||||
manager.deleteGroup("GROUP_3");
|
||||
|
||||
assertEquals(0, template.queryForList("select * from group_authorities").size());
|
||||
assertEquals(0, template.queryForList("select * from group_members").size());
|
||||
assertEquals(0, template.queryForList("select id from groups").size());
|
||||
assertThat(template.queryForList("select * from group_authorities")).isEmpty();
|
||||
assertThat(template.queryForList("select * from group_members")).isEmpty();
|
||||
assertThat(template.queryForList("select id from groups")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,7 +315,7 @@ public class JdbcUserDetailsManagerTests {
|
||||
throws Exception {
|
||||
manager.setEnableAuthorities(false);
|
||||
manager.createUser(joe);
|
||||
assertEquals(0, template.queryForList(SELECT_JOE_AUTHORITIES_SQL).size());
|
||||
assertThat(template.queryForList(SELECT_JOE_AUTHORITIES_SQL)).isEmpty();
|
||||
}
|
||||
|
||||
// SEC-1156
|
||||
@@ -326,7 +326,7 @@ public class JdbcUserDetailsManagerTests {
|
||||
insertJoe();
|
||||
template.execute("delete from authorities where username='joe'");
|
||||
manager.updateUser(joe);
|
||||
assertEquals(0, template.queryForList(SELECT_JOE_AUTHORITIES_SQL).size());
|
||||
assertThat(template.queryForList(SELECT_JOE_AUTHORITIES_SQL)).isEmpty();
|
||||
}
|
||||
|
||||
// SEC-2166
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.security.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
@@ -15,10 +16,10 @@ public class FieldUtilsTests {
|
||||
|
||||
Object tc = new TestClass();
|
||||
|
||||
assertEquals("x", FieldUtils.getProtectedFieldValue("protectedField", tc));
|
||||
assertEquals("z", FieldUtils.getFieldValue(tc, "nested.protectedField"));
|
||||
assertThat(FieldUtils.getProtectedFieldValue("protectedField", tc)).isEqualTo("x");
|
||||
assertThat(FieldUtils.getFieldValue(tc, "nested.protectedField")).isEqualTo("z");
|
||||
FieldUtils.setProtectedFieldValue("protectedField", tc, "y");
|
||||
assertEquals("y", FieldUtils.getProtectedFieldValue("protectedField", tc));
|
||||
assertThat(FieldUtils.getProtectedFieldValue("protectedField", tc)).isEqualTo("y");
|
||||
|
||||
try {
|
||||
FieldUtils.getProtectedFieldValue("nonExistentField", tc);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
@@ -12,15 +12,15 @@ public class InMemoryResourceTests {
|
||||
@Test
|
||||
public void resourceContainsExpectedData() throws Exception {
|
||||
InMemoryResource resource = new InMemoryResource("blah");
|
||||
assertNull(resource.getDescription());
|
||||
assertEquals(1, resource.hashCode());
|
||||
assertNotNull(resource.getInputStream());
|
||||
assertThat(resource.getDescription()).isNull();
|
||||
assertThat(resource.hashCode()).isEqualTo(1);
|
||||
assertThat(resource.getInputStream()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceIsEqualToOneWithSameContent() throws Exception {
|
||||
assertEquals(new InMemoryResource("xxx"), new InMemoryResource("xxx"));
|
||||
assertFalse(new InMemoryResource("xxx").equals(new InMemoryResource("xxxx")));
|
||||
assertFalse(new InMemoryResource("xxx").equals(new Object()));
|
||||
assertThat(new InMemoryResource("xxx")).isEqualTo(new InMemoryResource("xxx"));
|
||||
assertThat(new InMemoryResource("xxx").equals(new InMemoryResource("xxxx"))).isFalse();
|
||||
assertThat(new InMemoryResource("xxx").equals(new Object())).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.*;
|
||||
@@ -21,14 +21,14 @@ public class MethodInvocationUtilsTests {
|
||||
|
||||
MethodInvocation mi = MethodInvocationUtils.createFromClass(String.class,
|
||||
"length");
|
||||
assertNotNull(mi);
|
||||
assertThat(mi).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique() {
|
||||
MethodInvocation mi = MethodInvocationUtils.createFromClass(
|
||||
BusinessServiceImpl.class, "methodReturningAnArray");
|
||||
assertNotNull(mi);
|
||||
assertThat(mi).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -41,7 +41,7 @@ public class MethodInvocationUtilsTests {
|
||||
public void createFromClassReturnsMethodIfGivenArgInfoForMethodWithArgs() {
|
||||
MethodInvocation mi = MethodInvocationUtils.createFromClass(null, String.class,
|
||||
"compareTo", new Class<?>[] { String.class }, new Object[] { "" });
|
||||
assertNotNull(mi);
|
||||
assertThat(mi).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,13 +52,13 @@ public class MethodInvocationUtilsTests {
|
||||
Blah.class });
|
||||
|
||||
MethodInvocation mi = MethodInvocationUtils.create(t, "blah");
|
||||
assertNotNull(mi);
|
||||
assertThat(mi).isNotNull();
|
||||
|
||||
t.setProxyTargetClass(true);
|
||||
mi = MethodInvocationUtils.create(t, "blah");
|
||||
assertNotNull(mi);
|
||||
assertThat(mi).isNotNull();
|
||||
|
||||
assertNull(MethodInvocationUtils.create(t, "blah", "non-existent arg"));
|
||||
assertThat(MethodInvocationUtils.create(t, "blah", "non-existent arg")).isNull();
|
||||
}
|
||||
|
||||
interface Blah {
|
||||
|
||||
Reference in New Issue
Block a user