summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-24 23:18:50 -0500
committerJames Moger <james.moger@gitblit.com>2013-11-29 11:05:51 -0500
commit04a98505a4ab8f48aee22800fcac193d9367d0ae (patch)
treeeb05bc77eeafda1c5b7af9d7b5b27012065f7a98 /src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java
parentf8f6aa4d07cdfaaf23e24bf9eaf0a5fb9b437dda (diff)
downloadgitblit-04a98505a4ab8f48aee22800fcac193d9367d0ae.tar.gz
gitblit-04a98505a4ab8f48aee22800fcac193d9367d0ae.zip
Refactor user services and separate authentication (issue-281)
Change-Id: I336e005e02623fc5e11a4f8b4408bea5465a43fd
Diffstat (limited to 'src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java')
-rw-r--r--src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java b/src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java
new file mode 100644
index 00000000..1fe8459f
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/RedmineAuthenticationTest.java
@@ -0,0 +1,65 @@
+package com.gitblit.tests;
+
+import static org.hamcrest.CoreMatchers.is;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.auth.RedmineAuthProvider;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.models.UserModel;
+import com.gitblit.tests.mock.MemorySettings;
+
+public class RedmineAuthenticationTest 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\","
+ + "\"id\":4,\"login\":\"RedmineUserId\",\"mail\":\"baz@example.com\"}}";
+
+ private static final String NOT_ADMIN_JSON = "{\"user\":{\"lastname\":\"foo\","
+ + "\"last_login_on\":\"2012-09-08T13:59:01Z\",\"created_on\":\"2009-03-17T14:25:50Z\","
+ + "\"mail\":\"baz@example.com\",\"id\":5,\"firstname\":\"baz\"}}";
+
+ MemorySettings getSettings() {
+ return new MemorySettings(new HashMap<String, Object>());
+ }
+
+ RedmineAuthProvider newRedmineAuthentication(IStoredSettings settings) {
+ RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();
+ UserManager users = new UserManager(runtime).start();
+ RedmineAuthProvider redmine = new RedmineAuthProvider();
+ redmine.setup(runtime, users);
+ return redmine;
+ }
+
+ RedmineAuthProvider newRedmineAuthentication() {
+ return newRedmineAuthentication(getSettings());
+ }
+
+ @Test
+ public void testAuthenticate() throws Exception {
+ RedmineAuthProvider redmine = newRedmineAuthentication();
+ redmine.setTestingCurrentUserAsJson(JSON);
+ UserModel userModel = redmine.authenticate("RedmineAdminId", "RedmineAPIKey".toCharArray());
+ assertThat(userModel.getName(), is("redmineadminid"));
+ assertThat(userModel.getDisplayName(), is("baz foo"));
+ assertThat(userModel.emailAddress, is("baz@example.com"));
+ assertNotNull(userModel.cookie);
+ assertThat(userModel.canAdmin, is(true));
+ }
+
+ @Test
+ public void testAuthenticateNotAdminUser() throws Exception {
+ RedmineAuthProvider redmine = newRedmineAuthentication();
+ redmine.setTestingCurrentUserAsJson(NOT_ADMIN_JSON);
+ UserModel userModel = redmine.authenticate("RedmineUserId", "RedmineAPIKey".toCharArray());
+ assertThat(userModel.getName(), is("redmineuserid"));
+ assertThat(userModel.getDisplayName(), is("baz foo"));
+ assertThat(userModel.emailAddress, is("baz@example.com"));
+ assertNotNull(userModel.cookie);
+ assertThat(userModel.canAdmin, is(false));
+ }
+}