commit | author | age
|
04a985
|
1 |
package com.gitblit.tests; |
JM |
2 |
|
|
3 |
import static org.hamcrest.CoreMatchers.is; |
|
4 |
|
|
5 |
import java.util.HashMap; |
|
6 |
|
|
7 |
import org.junit.Test; |
|
8 |
|
|
9 |
import com.gitblit.IStoredSettings; |
|
10 |
import com.gitblit.auth.RedmineAuthProvider; |
b4a63a
|
11 |
import com.gitblit.manager.AuthenticationManager; |
04a985
|
12 |
import com.gitblit.manager.RuntimeManager; |
JM |
13 |
import com.gitblit.manager.UserManager; |
|
14 |
import com.gitblit.models.UserModel; |
|
15 |
import com.gitblit.tests.mock.MemorySettings; |
fc3a39
|
16 |
import com.gitblit.utils.XssFilter; |
JM |
17 |
import com.gitblit.utils.XssFilter.AllowXssFilter; |
04a985
|
18 |
|
JM |
19 |
public class RedmineAuthenticationTest extends GitblitUnitTest { |
|
20 |
|
|
21 |
private static final String JSON = "{\"user\":{\"created_on\":\"2011-03-28T00:41:29Z\",\"lastname\":\"foo\"," |
|
22 |
+ "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\"," |
|
23 |
+ "\"id\":4,\"login\":\"RedmineUserId\",\"mail\":\"baz@example.com\"}}"; |
|
24 |
|
|
25 |
MemorySettings getSettings() { |
|
26 |
return new MemorySettings(new HashMap<String, Object>()); |
|
27 |
} |
|
28 |
|
|
29 |
RedmineAuthProvider newRedmineAuthentication(IStoredSettings settings) { |
fc3a39
|
30 |
XssFilter xssFilter = new AllowXssFilter(); |
JM |
31 |
RuntimeManager runtime = new RuntimeManager(settings, xssFilter, GitBlitSuite.BASEFOLDER).start(); |
ca4d98
|
32 |
UserManager users = new UserManager(runtime, null).start(); |
04a985
|
33 |
RedmineAuthProvider redmine = new RedmineAuthProvider(); |
JM |
34 |
redmine.setup(runtime, users); |
|
35 |
return redmine; |
|
36 |
} |
|
37 |
|
|
38 |
RedmineAuthProvider newRedmineAuthentication() { |
|
39 |
return newRedmineAuthentication(getSettings()); |
|
40 |
} |
ca4d98
|
41 |
|
b4a63a
|
42 |
AuthenticationManager newAuthenticationManager() { |
fc3a39
|
43 |
XssFilter xssFilter = new AllowXssFilter(); |
JM |
44 |
RuntimeManager runtime = new RuntimeManager(getSettings(), xssFilter, GitBlitSuite.BASEFOLDER).start(); |
ca4d98
|
45 |
UserManager users = new UserManager(runtime, null).start(); |
b4a63a
|
46 |
RedmineAuthProvider redmine = new RedmineAuthProvider(); |
JM |
47 |
redmine.setup(runtime, users); |
|
48 |
redmine.setTestingCurrentUserAsJson(JSON); |
|
49 |
AuthenticationManager auth = new AuthenticationManager(runtime, users); |
|
50 |
auth.addAuthenticationProvider(redmine); |
|
51 |
return auth; |
|
52 |
} |
04a985
|
53 |
|
JM |
54 |
@Test |
|
55 |
public void testAuthenticate() throws Exception { |
|
56 |
RedmineAuthProvider redmine = newRedmineAuthentication(); |
|
57 |
redmine.setTestingCurrentUserAsJson(JSON); |
|
58 |
UserModel userModel = redmine.authenticate("RedmineAdminId", "RedmineAPIKey".toCharArray()); |
|
59 |
assertThat(userModel.getName(), is("redmineadminid")); |
|
60 |
assertThat(userModel.getDisplayName(), is("baz foo")); |
|
61 |
assertThat(userModel.emailAddress, is("baz@example.com")); |
|
62 |
assertNotNull(userModel.cookie); |
|
63 |
} |
|
64 |
|
|
65 |
@Test |
b4a63a
|
66 |
public void testAuthenticationManager() throws Exception { |
JM |
67 |
AuthenticationManager auth = newAuthenticationManager(); |
0d7c65
|
68 |
UserModel userModel = auth.authenticate("RedmineAdminId", "RedmineAPIKey".toCharArray(), null); |
b4a63a
|
69 |
assertThat(userModel.getName(), is("redmineadminid")); |
04a985
|
70 |
assertThat(userModel.getDisplayName(), is("baz foo")); |
JM |
71 |
assertThat(userModel.emailAddress, is("baz@example.com")); |
|
72 |
assertNotNull(userModel.cookie); |
|
73 |
} |
|
74 |
} |