Search in sources :

Example 6 with MemorySettings

use of com.gitblit.tests.mock.MemorySettings in project gitblit by gitblit.

the class LdapAuthenticationTest method testDisplayName.

@Test
public void testDisplayName() {
    UserModel userOneModel = ldap.authenticate("UserOne", "userOnePassword".toCharArray());
    assertNotNull(userOneModel);
    assertEquals("User One", userOneModel.displayName);
    // Test more complicated scenarios - concat
    MemorySettings ms = getSettings();
    ms.put("realm.ldap.displayName", "${personalTitle}. ${givenName} ${surname}");
    ldap = newLdapAuthentication(ms);
    userOneModel = ldap.authenticate("UserOne", "userOnePassword".toCharArray());
    assertNotNull(userOneModel);
    assertEquals("Mr. User One", userOneModel.displayName);
}
Also used : UserModel(com.gitblit.models.UserModel) MemorySettings(com.gitblit.tests.mock.MemorySettings) Test(org.junit.Test)

Example 7 with MemorySettings

use of com.gitblit.tests.mock.MemorySettings in project gitblit by gitblit.

the class GravatarTest method gravatarThumbnailTest.

@Test
public void gravatarThumbnailTest() {
    IStoredSettings settings = new MemorySettings();
    settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
    Injector injector = Guice.createInjector(new AvatarModule(settings));
    AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
    String username = "username";
    String emailAddress = "emailAddress";
    int width = 10;
    String url = avatarGenerator.getURL(username, emailAddress, false, width);
    assertNotNull(url);
    assertEquals(ActivityUtils.getGravatarThumbnailUrl(emailAddress, width), url);
}
Also used : GravatarGenerator(com.gitblit.GravatarGenerator) AvatarGenerator(com.gitblit.AvatarGenerator) IStoredSettings(com.gitblit.IStoredSettings) Injector(com.google.inject.Injector) MemorySettings(com.gitblit.tests.mock.MemorySettings) Test(org.junit.Test)

Example 8 with MemorySettings

use of com.gitblit.tests.mock.MemorySettings in project gitblit by gitblit.

the class LdapBasedUnitTest method getSettings.

protected MemorySettings getSettings() {
    Map<String, Object> backingMap = new HashMap<String, Object>();
    backingMap.put(Keys.realm.userService, usersConf.getAbsolutePath());
    backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
    switch(authMode) {
        case ANONYMOUS:
            backingMap.put(Keys.realm.ldap.username, "");
            backingMap.put(Keys.realm.ldap.password, "");
            break;
        case DS_MANAGER:
            backingMap.put(Keys.realm.ldap.username, DIRECTORY_MANAGER);
            backingMap.put(Keys.realm.ldap.password, "password");
            break;
        case USR_MANAGER:
            backingMap.put(Keys.realm.ldap.username, USER_MANAGER);
            backingMap.put(Keys.realm.ldap.password, "passwd");
            break;
        default:
            throw new RuntimeException("Unimplemented AuthMode case!");
    }
    backingMap.put(Keys.realm.ldap.maintainTeams, "true");
    backingMap.put(Keys.realm.ldap.accountBase, ACCOUNT_BASE);
    backingMap.put(Keys.realm.ldap.accountPattern, "(&(objectClass=person)(sAMAccountName=${username}))");
    backingMap.put(Keys.realm.ldap.groupBase, GROUP_BASE);
    backingMap.put(Keys.realm.ldap.groupMemberPattern, "(&(objectClass=group)(member=${dn}))");
    backingMap.put(Keys.realm.ldap.admins, "UserThree @Git_Admins \"@Git Admins\"");
    backingMap.put(Keys.realm.ldap.displayName, "displayName");
    backingMap.put(Keys.realm.ldap.email, "email");
    backingMap.put(Keys.realm.ldap.uid, "sAMAccountName");
    MemorySettings ms = new MemorySettings(backingMap);
    return ms;
}
Also used : HashMap(java.util.HashMap) MemorySettings(com.gitblit.tests.mock.MemorySettings)

Example 9 with MemorySettings

use of com.gitblit.tests.mock.MemorySettings in project gitblit by gitblit.

the class GravatarTest method gravatarIdenticonTest.

@Test
public void gravatarIdenticonTest() {
    IStoredSettings settings = new MemorySettings();
    settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
    Injector injector = Guice.createInjector(new AvatarModule(settings));
    AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
    String username = "username";
    String emailAddress = "emailAddress";
    int width = 10;
    String url = avatarGenerator.getURL(username, emailAddress, true, width);
    assertNotNull(url);
    assertEquals(ActivityUtils.getGravatarIdenticonUrl(emailAddress, width), url);
}
Also used : GravatarGenerator(com.gitblit.GravatarGenerator) AvatarGenerator(com.gitblit.AvatarGenerator) IStoredSettings(com.gitblit.IStoredSettings) Injector(com.google.inject.Injector) MemorySettings(com.gitblit.tests.mock.MemorySettings) Test(org.junit.Test)

Example 10 with MemorySettings

use of com.gitblit.tests.mock.MemorySettings 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

MemorySettings (com.gitblit.tests.mock.MemorySettings)11 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IStoredSettings (com.gitblit.IStoredSettings)4 UserModel (com.gitblit.models.UserModel)3 AvatarGenerator (com.gitblit.AvatarGenerator)2 GravatarGenerator (com.gitblit.GravatarGenerator)2 Injector (com.google.inject.Injector)2 File (java.io.File)2 AuthenticationManager (com.gitblit.manager.AuthenticationManager)1 IRuntimeManager (com.gitblit.manager.IRuntimeManager)1 IUserManager (com.gitblit.manager.IUserManager)1 RepositoryManager (com.gitblit.manager.RepositoryManager)1 RuntimeManager (com.gitblit.manager.RuntimeManager)1 UserManager (com.gitblit.manager.UserManager)1 LuceneService (com.gitblit.service.LuceneService)1 SshDaemonClient (com.gitblit.transport.ssh.SshDaemonClient)1 SshKrbAuthenticator (com.gitblit.transport.ssh.SshKrbAuthenticator)1 XssFilter (com.gitblit.utils.XssFilter)1 AllowXssFilter (com.gitblit.utils.XssFilter.AllowXssFilter)1