* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.callhome.protocol;
import static org.junit.Assert.assertFalse;
import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;
-import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.io.IoAcceptor;
-import org.apache.sshd.common.io.IoHandler;
-import org.apache.sshd.common.io.IoServiceFactory;
-import org.apache.sshd.common.session.Session;
-import org.apache.sshd.common.session.SessionListener;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.netconf.shaded.sshd.client.SshClient;
+import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
+import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
+import org.opendaylight.netconf.shaded.sshd.client.session.ClientSessionImpl;
+import org.opendaylight.netconf.shaded.sshd.common.future.SshFutureListener;
+import org.opendaylight.netconf.shaded.sshd.common.io.IoAcceptor;
+import org.opendaylight.netconf.shaded.sshd.common.io.IoHandler;
+import org.opendaylight.netconf.shaded.sshd.common.io.IoServiceFactory;
+import org.opendaylight.netconf.shaded.sshd.common.session.Session;
+import org.opendaylight.netconf.shaded.sshd.common.session.SessionListener;
@RunWith(MockitoJUnitRunner.class)
public class NetconfCallHomeServerTest {
CallHomeSessionContext mockContext = mock(CallHomeSessionContext.class);
doNothing().when(mockContext).openNetconfChannel();
doReturn(mockContext).when(mockSession).getAttribute(any(Session.AttributeKey.class));
- SessionListener listener = instance.createSessionListener();
+
+ final PublicKey serverKey = mock(PublicKey.class);
+ doReturn(serverKey).when(mockSession).getServerKey();
+
+ final SessionListener listener = instance.createSessionListener();
doReturn(mockAuthFuture).when(mockContext).authorize();
+ doReturn(false).when(mockSession).isAuthenticated();
// when
listener.sessionEvent(mockSession, evt[pass]);
// then
@Test
public void verificationOfTheServerKeyShouldBeSuccessfulForServerIsAllowed() {
// given
-
ClientSessionImpl mockClientSession = mock(ClientSessionImpl.class);
- Mockito.doReturn("test").when(mockClientSession).toString();
+ doReturn("test").when(mockClientSession).toString();
SocketAddress mockSocketAddr = mock(SocketAddress.class);
PublicKey mockPublicKey = mock(PublicKey.class);
- Mockito.doReturn(true).when(mockAuth).isServerAllowed();
- Mockito.doReturn("some-session-name").when(mockAuth).getSessionName();
-
- Mockito.doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
-
- Mockito.doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth, mockSocketAddr);
+ doReturn(true).when(mockAuth).isServerAllowed();
+ doReturn("some-session-name").when(mockAuth).getSessionName();
+ doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
+ doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth);
// expect
- instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey);
+ assertFalse(instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey));
}
@Test
SocketAddress mockSocketAddr = mock(SocketAddress.class);
PublicKey mockPublicKey = mock(PublicKey.class);
- Mockito.doReturn(false).when(mockAuth).isServerAllowed();
- Mockito.doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
- Mockito.doReturn("").when(mockClientSession).toString();
+ doReturn(false).when(mockAuth).isServerAllowed();
+ doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
+ doReturn("").when(mockClientSession).toString();
// expect
assertFalse(instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey));
IoAcceptor mockAcceptor = mock(IoAcceptor.class);
IoServiceFactory mockMinaFactory = mock(IoServiceFactory.class);
- Mockito.doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class));
- Mockito.doNothing().when(mockAcceptor).bind(any(SocketAddress.class));
+ doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class));
+ doNothing().when(mockAcceptor).bind(any(SocketAddress.class));
instance = new NetconfCallHomeServer(
mockSshClient, mockCallHomeAuthProv, mockFactory, MOCK_ADDRESS, mockStatusRecorder, mockMinaFactory);
// when