use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler in project netconf by opendaylight.
the class CallHomeMountDispatcherTest method someConfiguration.
NetconfClientConfiguration someConfiguration(final InetSocketAddress address) {
// NetconfClientConfiguration has mostly final methods, making it un-mock-able
final NetconfClientConfiguration.NetconfClientProtocol protocol = NetconfClientConfiguration.NetconfClientProtocol.SSH;
final NetconfHelloMessageAdditionalHeader additionalHeader = mock(NetconfHelloMessageAdditionalHeader.class);
final NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
final ReconnectStrategy reconnectStrategy = mock(ReconnectStrategy.class);
final AuthenticationHandler authHandler = mock(AuthenticationHandler.class);
return NetconfClientConfigurationBuilder.create().withProtocol(protocol).withAddress(address).withConnectionTimeoutMillis(0).withAdditionalHeader(additionalHeader).withSessionListener(sessionListener).withReconnectStrategy(reconnectStrategy).withAuthHandler(authHandler).build();
}
use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler in project netconf by opendaylight.
the class NetconfClientDispatcherImplTest method testNetconfClientDispatcherImpl.
@Test
public void testNetconfClientDispatcherImpl() throws Exception {
EventLoopGroup bossGroup = Mockito.mock(EventLoopGroup.class);
EventLoopGroup workerGroup = Mockito.mock(EventLoopGroup.class);
Timer timer = new HashedWheelTimer();
ChannelFuture chf = Mockito.mock(ChannelFuture.class);
Channel ch = Mockito.mock(Channel.class);
doReturn(ch).when(chf).channel();
Throwable thr = Mockito.mock(Throwable.class);
doReturn(chf).when(workerGroup).register(any(Channel.class));
ChannelPromise promise = Mockito.mock(ChannelPromise.class);
doReturn(promise).when(chf).addListener(any(GenericFutureListener.class));
doReturn(thr).when(chf).cause();
doReturn(true).when(chf).isDone();
doReturn(false).when(chf).isSuccess();
Long timeout = 200L;
NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategyFactory reconnectStrategyFactory = Mockito.mock(ReconnectStrategyFactory.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class);
doReturn(5).when(reconnect).getConnectTimeout();
doReturn("").when(reconnect).toString();
doReturn("").when(handler).toString();
doReturn("").when(reconnectStrategyFactory).toString();
doReturn(reconnect).when(reconnectStrategyFactory).createReconnectStrategy();
NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header).withSessionListener(listener).withConnectStrategyFactory(reconnectStrategyFactory).withAuthHandler(handler).build();
NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header).withSessionListener(listener).withConnectStrategyFactory(reconnectStrategyFactory).withAuthHandler(handler).build();
NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(bossGroup, workerGroup, timer);
Future<NetconfClientSession> sshSession = dispatcher.createClient(cfg);
Future<NetconfClientSession> tcpSession = dispatcher.createClient(cfg2);
ReconnectFuture sshReconn = dispatcher.createReconnectingClient(cfg);
final ReconnectFuture tcpReconn = dispatcher.createReconnectingClient(cfg2);
assertNotNull(sshSession);
assertNotNull(tcpSession);
assertNotNull(sshReconn);
assertNotNull(tcpReconn);
SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
NetconfReconnectingClientConfiguration cfg3 = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header).withSessionListener(listener).withConnectStrategyFactory(reconnectStrategyFactory).withSslHandlerFactory(sslHandlerFactory).build();
Future<NetconfClientSession> tlsSession = dispatcher.createClient(cfg3);
ReconnectFuture tlsReconn = dispatcher.createReconnectingClient(cfg3);
assertNotNull(tlsSession);
assertNotNull(tlsReconn);
}
use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler in project netconf by opendaylight.
the class NetconfReconnectingClientConfigurationTest method testNetconfReconnectingClientConfiguration.
@Test
public void testNetconfReconnectingClientConfiguration() throws Exception {
Long timeout = 200L;
NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategyFactory strategy = Mockito.mock(ReconnectStrategyFactory.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class);
NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header).withSessionListener(listener).withConnectStrategyFactory(strategy).withAuthHandler(handler).build();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg.getAdditionalHeader());
Assert.assertEquals(listener, cfg.getSessionListener());
Assert.assertEquals(handler, cfg.getAuthHandler());
Assert.assertEquals(strategy, cfg.getConnectStrategyFactory());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
Assert.assertEquals(address, cfg.getAddress());
Assert.assertEquals(reconnect, cfg.getReconnectStrategy());
SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header).withSessionListener(listener).withConnectStrategyFactory(strategy).withSslHandlerFactory(sslHandlerFactory).build();
Assert.assertEquals(timeout, cfg2.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg2.getAdditionalHeader());
Assert.assertEquals(listener, cfg2.getSessionListener());
Assert.assertEquals(sslHandlerFactory, cfg2.getSslHandlerFactory());
Assert.assertEquals(strategy, cfg2.getConnectStrategyFactory());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, cfg2.getProtocol());
Assert.assertEquals(address, cfg2.getAddress());
Assert.assertEquals(reconnect, cfg2.getReconnectStrategy());
}
use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler in project netconf by opendaylight.
the class SshClientChannelInitializerTest method test.
@Test
public void test() throws Exception {
AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class);
doReturn("").when(sessionNegotiator).toString();
doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class));
ChannelPipeline pipeline = mock(ChannelPipeline.class);
doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
Channel channel = mock(Channel.class);
doReturn(pipeline).when(channel).pipeline();
doReturn("").when(channel).toString();
doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class));
doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
ChannelConfig channelConfig = mock(ChannelConfig.class);
doReturn(channelConfig).when(channel).config();
doReturn(1L).when(negotiatorFactory).getConnectionTimeoutMillis();
doReturn(channelConfig).when(channelConfig).setConnectTimeoutMillis(1);
Promise<NetconfClientSession> promise = mock(Promise.class);
doReturn("").when(promise).toString();
SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler, negotiatorFactory, sessionListener);
initializer.initialize(channel, promise);
verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));
}
use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler in project netconf by opendaylight.
the class NetconfClientConfigurationTest method testNetconfClientConfiguration.
@Test
public void testNetconfClientConfiguration() throws Exception {
Long timeout = 200L;
NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withAuthHandler(handler).build();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg.getAdditionalHeader());
Assert.assertEquals(listener, cfg.getSessionListener());
Assert.assertEquals(handler, cfg.getAuthHandler());
Assert.assertEquals(strategy, cfg.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
Assert.assertEquals(address, cfg.getAddress());
SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
NetconfClientConfiguration cfg2 = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withSslHandlerFactory(sslHandlerFactory).build();
Assert.assertEquals(timeout, cfg2.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg2.getAdditionalHeader());
Assert.assertEquals(listener, cfg2.getSessionListener());
Assert.assertEquals(sslHandlerFactory, cfg2.getSslHandlerFactory());
Assert.assertEquals(strategy, cfg2.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, cfg2.getProtocol());
Assert.assertEquals(address, cfg2.getAddress());
}
Aggregations