| | |
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.hamcrest.CoreMatchers.is;
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | | import static org.junit.Assert.assertThat;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.HashMap;
|
| | |
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.RedmineUserService;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.tests.mock.MemorySettings;
|
| | | import com.gitblit.tests.mock.MockRuntimeManager;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | public class RedmineUserServiceTest {
|
| | | public class RedmineUserServiceTest extends GitblitUnitTest {
|
| | |
|
| | | private static final String JSON = "{\"user\":{\"created_on\":\"2011-03-28T00:41:29Z\",\"lastname\":\"foo\","
|
| | | + "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\","
|
| | |
| | | @Test
|
| | | public void testAuthenticate() throws Exception {
|
| | | RedmineUserService redmineUserService = new RedmineUserService();
|
| | | redmineUserService.setup(new MemorySettings(new HashMap<String, Object>()));
|
| | | redmineUserService.setup(new MockRuntimeManager());
|
| | | redmineUserService.setTestingCurrentUserAsJson(JSON);
|
| | | UserModel userModel = redmineUserService.authenticate("RedmineAdminId", "RedmineAPIKey".toCharArray());
|
| | | assertThat(userModel.getName(), is("redmineadminid"));
|
| | |
| | | @Test
|
| | | public void testAuthenticateNotAdminUser() throws Exception {
|
| | | RedmineUserService redmineUserService = new RedmineUserService();
|
| | | redmineUserService.setup(new MemorySettings(new HashMap<String, Object>()));
|
| | | redmineUserService.setup(new MockRuntimeManager());
|
| | | redmineUserService.setTestingCurrentUserAsJson(NOT_ADMIN_JSON);
|
| | | UserModel userModel = redmineUserService.authenticate("RedmineUserId", "RedmineAPIKey".toCharArray());
|
| | | assertThat(userModel.getName(), is("redmineuserid"));
|
| | |
| | | assertNotNull(userModel.cookie);
|
| | | assertThat(userModel.canAdmin, is(false));
|
| | | }
|
| | | |
| | |
|
| | | @Test
|
| | | public void testLocalAccount() {
|
| | | RedmineUserService redmineUserService = new RedmineUserService();
|
| | | redmineUserService.setup(new MemorySettings(new HashMap<String, Object>()));
|
| | | redmineUserService.setup(new MockRuntimeManager());
|
| | |
|
| | | UserModel localAccount = new UserModel("bruce");
|
| | | localAccount.displayName = "Bruce Campbell";
|
| | |
| | | redmineUserService.deleteUser(localAccount.username);
|
| | | assertTrue("Failed to add local account",
|
| | | redmineUserService.updateUserModel(localAccount));
|
| | | assertEquals("Accounts are not equal!", |
| | | localAccount, |
| | | assertEquals("Accounts are not equal!",
|
| | | localAccount,
|
| | | redmineUserService.authenticate(localAccount.username, "gimmesomesugar".toCharArray()));
|
| | | assertTrue("Failed to delete local account!",
|
| | | redmineUserService.deleteUser(localAccount.username));
|