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);
}
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);
}
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;
}
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);
}
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"));
}
Aggregations