James Moger
2014-06-09 ca4d98678c20e4033fdaca09ecbbf0f5952e0b84
commit | author | age
9aa119 1 /*
JM 2  * Copyright 2013 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.tests;
17
18 import java.util.HashMap;
19
20 import org.junit.Test;
21
22 import com.gitblit.manager.AuthenticationManager;
23 import com.gitblit.manager.IAuthenticationManager;
24 import com.gitblit.manager.IUserManager;
25 import com.gitblit.manager.RuntimeManager;
26 import com.gitblit.manager.UserManager;
27 import com.gitblit.models.UserModel;
28 import com.gitblit.tests.mock.MemorySettings;
29
30 /**
31  * Class for testing local authentication.
32  *
33  * @author James Moger
34  *
35  */
36 public class AuthenticationManagerTest extends GitblitUnitTest {
37
38     IUserManager users;
39
40     MemorySettings getSettings() {
41         return new MemorySettings(new HashMap<String, Object>());
42     }
43
44     IAuthenticationManager newAuthenticationManager() {
45         RuntimeManager runtime = new RuntimeManager(getSettings(), GitBlitSuite.BASEFOLDER).start();
ca4d98 46         users = new UserManager(runtime, null).start();
9aa119 47         AuthenticationManager auth = new AuthenticationManager(runtime, users).start();
JM 48         return auth;
49     }
50
51     @Test
52     public void testAuthenticate() throws Exception {
53         IAuthenticationManager auth = newAuthenticationManager();
54
55         UserModel user = new UserModel("sunnyjim");
56         user.password = "password";
57         users.updateUserModel(user);
58
59         assertNotNull(auth.authenticate(user.username, user.password.toCharArray()));
60         user.disabled = true;
61
62         users.updateUserModel(user);
63         assertNull(auth.authenticate(user.username, user.password.toCharArray()));
64         users.deleteUserModel(user);
65     }
66 }