Search in sources :

Example 1 with SshKrbAuthenticator

use of com.gitblit.transport.ssh.SshKrbAuthenticator in project gitblit by gitblit.

the class SshKerberosAuthenticationTest method testUserManager.

@Test
public void testUserManager() {
    IRuntimeManager rm = Mockito.mock(IRuntimeManager.class);
    // Build an UserManager that can build a UserModel
    IUserManager im = Mockito.mock(IUserManager.class);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            String user = (String) args[0];
            return new UserModel(user);
        }
    }).when(im).getUserModel(Mockito.anyString());
    AuthenticationManager am = new AuthenticationManager(rm, im);
    GSSAuthenticator gssAuthenticator = new SshKrbAuthenticator(new MemorySettings(), am);
    ServerSession session = Mockito.mock(ServerSession.class);
    // Build an SshDaemonClient that can set and get the UserModel
    final UserModelWrapper umw = new UserModelWrapper();
    SshDaemonClient client = Mockito.mock(SshDaemonClient.class);
    Mockito.when(client.getUser()).thenReturn(umw.um);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            UserModel um = (UserModel) args[0];
            umw.um = um;
            return null;
        }
    }).when(client).setUser(Mockito.any(UserModel.class));
    Mockito.when(session.getAttribute(SshDaemonClient.KEY)).thenReturn(client);
    Assert.assertTrue(gssAuthenticator.validateIdentity(session, "jhappy"));
}
Also used : GSSAuthenticator(org.apache.sshd.server.auth.gss.GSSAuthenticator) ServerSession(org.apache.sshd.server.session.ServerSession) IUserManager(com.gitblit.manager.IUserManager) SshDaemonClient(com.gitblit.transport.ssh.SshDaemonClient) SshKrbAuthenticator(com.gitblit.transport.ssh.SshKrbAuthenticator) IRuntimeManager(com.gitblit.manager.IRuntimeManager) UserModel(com.gitblit.models.UserModel) AuthenticationManager(com.gitblit.manager.AuthenticationManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MemorySettings(com.gitblit.tests.mock.MemorySettings) Test(org.junit.Test)

Aggregations

AuthenticationManager (com.gitblit.manager.AuthenticationManager)1 IRuntimeManager (com.gitblit.manager.IRuntimeManager)1 IUserManager (com.gitblit.manager.IUserManager)1 UserModel (com.gitblit.models.UserModel)1 MemorySettings (com.gitblit.tests.mock.MemorySettings)1 SshDaemonClient (com.gitblit.transport.ssh.SshDaemonClient)1 SshKrbAuthenticator (com.gitblit.transport.ssh.SshKrbAuthenticator)1 GSSAuthenticator (org.apache.sshd.server.auth.gss.GSSAuthenticator)1 ServerSession (org.apache.sshd.server.session.ServerSession)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1