Reformat code using spring-javaformat
Run `./gradlew format` to reformat all java files. Issue gh-8945
This commit is contained in:
@@ -30,14 +30,15 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mike Wiesner
|
||||
* @since 3.0
|
||||
*/
|
||||
public class JndiDnsResolverTests {
|
||||
|
||||
private JndiDnsResolver dnsResolver;
|
||||
|
||||
private InitialContextFactory contextFactory;
|
||||
|
||||
private DirContext context;
|
||||
|
||||
@Before
|
||||
@@ -53,8 +54,7 @@ public class JndiDnsResolverTests {
|
||||
public void testResolveIpAddress() throws Exception {
|
||||
Attributes records = new BasicAttributes("A", "63.246.7.80");
|
||||
|
||||
when(context.getAttributes("www.springsource.com", new String[] { "A" }))
|
||||
.thenReturn(records);
|
||||
when(context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
|
||||
|
||||
String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
@@ -62,8 +62,8 @@ public class JndiDnsResolverTests {
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveIpAddressNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(
|
||||
new NameNotFoundException("not found"));
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
|
||||
}
|
||||
@@ -72,8 +72,7 @@ public class JndiDnsResolverTests {
|
||||
public void testResolveServiceEntry() throws Exception {
|
||||
BasicAttributes records = createSrvRecords();
|
||||
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" }))
|
||||
.thenReturn(records);
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(records);
|
||||
|
||||
String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com");
|
||||
assertThat(hostname).isEqualTo("kdc.springsource.com");
|
||||
@@ -81,8 +80,8 @@ public class JndiDnsResolverTests {
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveServiceEntryNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(
|
||||
new NameNotFoundException("not found"));
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveServiceEntry("wrong", "secpod.de");
|
||||
}
|
||||
@@ -91,20 +90,16 @@ public class JndiDnsResolverTests {
|
||||
public void testResolveServiceIpAddress() throws Exception {
|
||||
BasicAttributes srvRecords = createSrvRecords();
|
||||
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" }))
|
||||
.thenReturn(srvRecords);
|
||||
when(context.getAttributes("kdc.springsource.com", new String[] { "A" }))
|
||||
.thenReturn(aRecords);
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(srvRecords);
|
||||
when(context.getAttributes("kdc.springsource.com", new String[] { "A" })).thenReturn(aRecords);
|
||||
|
||||
String ipAddress = dnsResolver
|
||||
.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
String ipAddress = dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
}
|
||||
|
||||
@Test(expected = DnsLookupException.class)
|
||||
public void testUnknowError() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(
|
||||
new NamingException("error"));
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NamingException("error"));
|
||||
dnsResolver.resolveIpAddress("");
|
||||
}
|
||||
|
||||
@@ -121,4 +116,5 @@ public class JndiDnsResolverTests {
|
||||
records.put(record);
|
||||
return records;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
// Setup client-side context
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
"Aladdin", "open sesame");
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("Aladdin", "open sesame");
|
||||
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||
|
||||
// Create a connection and ensure our executor sets its
|
||||
@@ -62,8 +61,7 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
// Check connection properties
|
||||
// See https://tools.ietf.org/html/rfc1945 section 11.1 for example
|
||||
// we are comparing against
|
||||
assertThat(conn.getRequestProperty("Authorization")).isEqualTo(
|
||||
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
assertThat(conn.getRequestProperty("Authorization")).isEqualTo("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +81,8 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
// SEC-1975
|
||||
@Test
|
||||
public void testNullContextHolderWhenAnonymous() throws Exception {
|
||||
AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key",
|
||||
"principal", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
|
||||
AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key", "principal",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
|
||||
SecurityContextHolder.getContext().setAuthentication(anonymous);
|
||||
|
||||
// Create a connection and ensure our executor sets its
|
||||
@@ -127,5 +125,7 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
public boolean usingProxy() {
|
||||
throw new UnsupportedOperationException("mock not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ public class ContextPropagatingRemoteInvocationTests {
|
||||
private ContextPropagatingRemoteInvocation getRemoteInvocation() throws Exception {
|
||||
Class<TargetObject> clazz = TargetObject.class;
|
||||
Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method,
|
||||
"SOME_STRING");
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method, "SOME_STRING");
|
||||
|
||||
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
|
||||
|
||||
@@ -60,8 +59,7 @@ public class ContextPropagatingRemoteInvocationTests {
|
||||
@Test
|
||||
public void testContextIsResetEvenIfExceptionOccurs() throws Exception {
|
||||
// Setup client-side context
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
"rod", "koala");
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
|
||||
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||
|
||||
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
|
||||
@@ -76,16 +74,14 @@ public class ContextPropagatingRemoteInvocationTests {
|
||||
// expected
|
||||
}
|
||||
|
||||
assertThat(
|
||||
SecurityContextHolder.getContext().getAuthentication()).withFailMessage(
|
||||
"Authentication must be null").isNull();
|
||||
assertThat(SecurityContextHolder.getContext().getAuthentication())
|
||||
.withFailMessage("Authentication must be null").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
// Setup client-side context
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
"rod", "koala");
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
|
||||
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||
|
||||
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
|
||||
@@ -109,19 +105,17 @@ public class ContextPropagatingRemoteInvocationTests {
|
||||
SecurityContextHolder.clearContext(); // unnecessary, but for
|
||||
// explicitness
|
||||
|
||||
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo(
|
||||
"some_string Authentication empty");
|
||||
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo("some_string Authentication empty");
|
||||
}
|
||||
|
||||
// SEC-1867
|
||||
@Test
|
||||
public void testNullCredentials() throws Exception {
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken(
|
||||
"rod", null);
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", null);
|
||||
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||
|
||||
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
|
||||
assertThat(
|
||||
ReflectionTestUtils.getField(remoteInvocation, "credentials")).isNull();
|
||||
assertThat(ReflectionTestUtils.getField(remoteInvocation, "credentials")).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user