Simplify test setup in Netty 4 transport tests
This commit collapes some duplicated setup code in every test in the Netty 4 security transport tests to a common method. Original commit: elastic/x-pack-elasticsearch@0a088db78d
This commit is contained in:
parent
b3f8495a03
commit
832cb4fff2
|
@ -48,19 +48,30 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
clientSSLService = new ClientSSLService(settings, env, globalSSLConfiguration);
|
clientSSLService = new ClientSSLService(settings, env, globalSSLConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SecurityNetty4Transport createTransport(boolean sslEnabled) {
|
||||||
|
return createTransport(sslEnabled, Settings.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SecurityNetty4Transport createTransport(boolean sslEnabled, Settings additionalSettings) {
|
||||||
|
final Settings settings =
|
||||||
|
Settings.builder()
|
||||||
|
.put(SecurityNetty4Transport.SSL_SETTING.getKey(), sslEnabled)
|
||||||
|
.put(additionalSettings)
|
||||||
|
.build();
|
||||||
|
return new SecurityNetty4Transport(
|
||||||
|
settings,
|
||||||
|
mock(ThreadPool.class),
|
||||||
|
mock(NetworkService.class),
|
||||||
|
mock(BigArrays.class),
|
||||||
|
mock(NamedWriteableRegistry.class),
|
||||||
|
mock(CircuitBreakerService.class),
|
||||||
|
null,
|
||||||
|
serverSSLService,
|
||||||
|
clientSSLService);
|
||||||
|
}
|
||||||
|
|
||||||
public void testThatSSLCanBeDisabledByProfile() throws Exception {
|
public void testThatSSLCanBeDisabledByProfile() throws Exception {
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
||||||
Settings.builder().put("xpack.security.ssl", false).build());
|
Settings.builder().put("xpack.security.ssl", false).build());
|
||||||
|
@ -69,18 +80,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThatSSLCanBeEnabledByProfile() throws Exception {
|
public void testThatSSLCanBeEnabledByProfile() throws Exception {
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), false).build();
|
SecurityNetty4Transport transport = createTransport(false);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
||||||
Settings.builder().put("xpack.security.ssl", true).build());
|
Settings.builder().put("xpack.security.ssl", true).build());
|
||||||
|
@ -89,18 +89,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThatProfileTakesDefaultSSLSetting() throws Exception {
|
public void testThatProfileTakesDefaultSSLSetting() throws Exception {
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
||||||
|
@ -108,18 +97,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultClientAuth() throws Exception {
|
public void testDefaultClientAuth() throws Exception {
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
||||||
|
@ -129,20 +107,8 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testRequiredClientAuth() throws Exception {
|
public void testRequiredClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true");
|
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true");
|
||||||
Settings settings = Settings.builder()
|
|
||||||
.put(SecurityNetty4Transport.SSL_SETTING.getKey(), true)
|
|
||||||
.put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build();
|
|
||||||
SecurityNetty4Transport transport =
|
SecurityNetty4Transport transport =
|
||||||
new SecurityNetty4Transport(
|
createTransport(true, Settings.builder().put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build());
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
||||||
|
@ -152,20 +118,8 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testNoClientAuth() throws Exception {
|
public void testNoClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
|
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
|
||||||
Settings settings = Settings.builder()
|
|
||||||
.put(SecurityNetty4Transport.SSL_SETTING.getKey(), true)
|
|
||||||
.put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build();
|
|
||||||
SecurityNetty4Transport transport =
|
SecurityNetty4Transport transport =
|
||||||
new SecurityNetty4Transport(
|
createTransport(true, Settings.builder().put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build());
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
||||||
|
@ -175,20 +129,8 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testOptionalClientAuth() throws Exception {
|
public void testOptionalClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
|
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
|
||||||
Settings settings = Settings.builder()
|
|
||||||
.put(SecurityNetty4Transport.SSL_SETTING.getKey(), true)
|
|
||||||
.put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build();
|
|
||||||
SecurityNetty4Transport transport =
|
SecurityNetty4Transport transport =
|
||||||
new SecurityNetty4Transport(
|
createTransport(true, Settings.builder().put(SecurityNetty4Transport.CLIENT_AUTH_SETTING.getKey(), value).build());
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
ChannelHandler handler = transport.getServerChannelInitializer("client", Settings.EMPTY);
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
final EmbeddedChannel ch = new EmbeddedChannel(handler);
|
||||||
|
@ -198,18 +140,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testProfileRequiredClientAuth() throws Exception {
|
public void testProfileRequiredClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true", "TRUE");
|
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true", "TRUE");
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
||||||
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING, value).build());
|
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING, value).build());
|
||||||
|
@ -220,18 +151,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testProfileNoClientAuth() throws Exception {
|
public void testProfileNoClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
|
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
ChannelHandler handler = transport.getServerChannelInitializer("client",
|
||||||
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING.getKey(), value).build());
|
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING.getKey(), value).build());
|
||||||
|
@ -242,18 +162,7 @@ public class SecurityNetty4TransportTests extends ESTestCase {
|
||||||
|
|
||||||
public void testProfileOptionalClientAuth() throws Exception {
|
public void testProfileOptionalClientAuth() throws Exception {
|
||||||
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
|
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
|
||||||
Settings settings = Settings.builder().put(SecurityNetty4Transport.SSL_SETTING.getKey(), true).build();
|
SecurityNetty4Transport transport = createTransport(true);
|
||||||
SecurityNetty4Transport transport =
|
|
||||||
new SecurityNetty4Transport(
|
|
||||||
settings,
|
|
||||||
mock(ThreadPool.class),
|
|
||||||
mock(NetworkService.class),
|
|
||||||
mock(BigArrays.class),
|
|
||||||
mock(NamedWriteableRegistry.class),
|
|
||||||
mock(CircuitBreakerService.class),
|
|
||||||
null,
|
|
||||||
serverSSLService,
|
|
||||||
clientSSLService);
|
|
||||||
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
Netty4MockUtil.setOpenChannelsHandlerToMock(transport);
|
||||||
final ChannelHandler handler = transport.getServerChannelInitializer("client",
|
final ChannelHandler handler = transport.getServerChannelInitializer("client",
|
||||||
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING.getKey(), value).build());
|
Settings.builder().put(SecurityNetty4Transport.PROFILE_CLIENT_AUTH_SETTING.getKey(), value).build());
|
||||||
|
|
Loading…
Reference in New Issue