3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.usermanager.internal;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
16 import java.util.concurrent.ConcurrentHashMap;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
21 import org.opendaylight.controller.sal.authorization.UserLevel;
22 import org.opendaylight.controller.sal.utils.ServiceHelper;
23 import org.opendaylight.controller.usermanager.AuthResponse;
24 import org.opendaylight.controller.usermanager.IAAAProvider;
25 import org.opendaylight.controller.usermanager.IUserManager;
28 * Unit Tests for UserManagerImpl
30 public class UserManagerImplTest {
32 private static UserManagerImpl um;
35 * @throws java.lang.Exception
38 public static void setUpBeforeClass() throws Exception {
40 IUserManager userManager = (IUserManager) ServiceHelper
41 .getGlobalInstance(IUserManager.class, new Object());
42 if (userManager instanceof UserManagerImpl) {
43 um = (UserManagerImpl) userManager;
45 um = new UserManagerImpl();
46 um.setAuthProviders(new ConcurrentHashMap<String, IAAAProvider>());
48 // mock up a remote server list with a dummy server
49 um.setRemoteServerConfigList(new ConcurrentHashMap<String, ServerConfig>() {
50 static final long serialVersionUID = 1L;
52 put("dummyServerConfig", new ServerConfig() { // Server config can't be empty
53 static final long serialVersionUID = 8645L;
55 public String getAddress() {
59 public String getSecret() {
63 public String getProtocol() {
70 // mock up a localUserConfigList with an admin user
71 um.setLocalUserConfigList(new ConcurrentHashMap<String, UserConfig>() {
72 static final long serialVersionUID = 2L;
74 put("admin", new UserConfig("admin", "7029,7455,8165,7029,7881",
75 UserLevel.SYSTEMADMIN.toString()));
78 // instantiate an empty activeUser collection
79 um.setActiveUsers(new ConcurrentHashMap<String, AuthenticatedUser>());
87 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#addAAAProvider(org.opendaylight.controller.usermanager.IAAAProvider)}
91 public void testAddAAAProvider() {
92 // instantiate an anonymous AAAProvider
93 IAAAProvider a3p = new IAAAProvider() {
95 public AuthResponse authService(String userName, String password,
96 String server, String secretKey) {
97 return new AuthResponse();
100 public String getName() {
101 return "dummyAAAProvider";
105 um.addAAAProvider(a3p);
106 assertEquals(a3p, um.getAAAProvider("dummyAAAProvider"));
112 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#removeAAAProvider(org.opendaylight.controller.usermanager.IAAAProvider)}
114 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#getAAAProvider(java.lang.String)}
118 public void testRemoveAAAProvider() {
119 um.removeAAAProvider(um.getAAAProvider("dummyAAAProvider"));
120 assertTrue(um.getAAAProviderNames().isEmpty());
125 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#authenticate(java.lang.String, java.lang.String)}
129 public void testAuthenticateStringString() {
130 UserConfig uc = new UserConfig("administrator", "admin",
131 UserLevel.SYSTEMADMIN.toString());
133 AuthResultEnum authResult = um.authenticate("administrator", "admin");
134 assertEquals(authResult, AuthResultEnum.AUTH_ACCEPT_LOC);
139 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#addRemoveLocalUser(org.opendaylight.controller.usermanager.internal.UserConfig, boolean)}
143 public void testAddRemoveLocalUser() {
144 UserConfig uc = new UserConfig("sysadmin", "7029,7455,8165,7029,7881",
145 UserLevel.SYSTEMADMIN.toString());
147 assertTrue(um.getLocalUserList().contains(uc));
148 um.removeLocalUser(uc);
149 assertFalse(um.getLocalUserList().contains(uc));
154 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#changeLocalUserPassword(java.lang.String, java.lang.String, java.lang.String)}
158 public void testChangeLocalUserPassword() {
159 // fail("Not yet implemented");
164 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#userLogout(java.lang.String)}
168 public void testUserLogout() {
169 // fail("Not yet implemented");
174 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#userTimedOut(java.lang.String)}
178 public void testUserTimedOut() {
179 // fail("Not yet implemented");
184 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#authenticate(org.springframework.security.core.Authentication)}
188 public void testAuthenticateAuthentication() {
189 // fail("Not yet implemented");
194 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#saveLocalUserList()}
198 public void testSaveLocalUserList() {
199 // fail("Not yet implemented");
204 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#saveAAAServerList()}
208 public void testSaveAAAServerList() {
209 // fail("Not yet implemented");
214 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#saveAuthorizationList()}
218 public void testSaveAuthorizationList() {
219 // fail("Not yet implemented");
224 * {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#readObject(java.io.ObjectInputStream)}
228 public void testReadObject() {
229 // fail("Not yet implemented");