*/
package org.opendaylight.controller.usermanager;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.opendaylight.controller.sal.authorization.AuthResultEnum;
import org.opendaylight.controller.sal.authorization.UserLevel;
-import org.opendaylight.controller.usermanager.AuthResponse;
-import org.opendaylight.controller.usermanager.AuthorizationConfig;
-import org.opendaylight.controller.usermanager.UserConfig;
-
/*
* This test case includes tests for UserConfig and the extending class AuthorizationConfig
*/
.isSuccess());
// New Password = null, No change in password
- assertTrue(userConfig.getPassword().equals(UserConfig.hash("ciscocisco")));
+ assertTrue(userConfig.authenticate("ciscocisco").getStatus().equals(AuthResultEnum.AUTH_ACCEPT_LOC));
// Password changed successfully, no change in user role
assertTrue(userConfig.update("ciscocisco", "cisco123", roles)
.isSuccess());
- assertTrue(userConfig.getPassword().equals(UserConfig.hash("cisco123")));
+ assertTrue(userConfig.authenticate("cisco123").getStatus().equals(AuthResultEnum.AUTH_ACCEPT_LOC));
assertTrue(userConfig.getRoles().get(0).equals(
UserLevel.NETWORKOPERATOR.toString()));
roles.add(UserLevel.SYSTEMADMIN.toString());
assertTrue(userConfig.update("cisco123", "cisco123", roles)
.isSuccess());
- assertTrue(userConfig.getPassword().equals(UserConfig.hash("cisco123")));
+ assertTrue(userConfig.authenticate("cisco123").getStatus().equals(AuthResultEnum.AUTH_ACCEPT_LOC));
assertTrue(userConfig.getRoles().get(0)
.equals(UserLevel.SYSTEMADMIN.toString()));
// Password and role changed successfully
assertTrue(userConfig.update("cisco123", "ciscocisco", roles)
.isSuccess());
- assertTrue(userConfig.getPassword().equals(UserConfig.hash("ciscocisco")));
+ assertTrue(userConfig.authenticate("ciscocisco").getStatus().equals(AuthResultEnum.AUTH_ACCEPT_LOC));
assertTrue(userConfig.getRoles().get(0)
.equals(UserLevel.SYSTEMADMIN.toString()));
assertTrue(authresp.getStatus().equals(AuthResultEnum.AUTH_ACCEPT_LOC));
authresp = userConfig.authenticate("wrongPassword");
assertTrue(authresp.getStatus().equals(AuthResultEnum.AUTH_REJECT_LOC));
+ }
- // test equals()
- roles.clear();
- roles.add(UserLevel.NETWORKOPERATOR.toString());
- userConfig = new UserConfig("uname", "ciscocisco", roles);
- assertEquals(userConfig, userConfig);
- UserConfig userConfig2 = new UserConfig("uname", "ciscocisco", roles);
- assertEquals(userConfig, userConfig2);
+ @Test
+ public void userConfigPasswordTest() {
+
+ String regex = UserConfig.PASSWORD_REGEX;
+ String password = null;
+
+ // Good password
+ password = "aBc@eF#h9";
+ assertTrue(password.matches(regex));
+ password = "^aBc@eF#h9$88ad*o&";
+ assertTrue(password.matches(regex));
+ password = "_^aBc@\":eF#h;9$\\8|8ad*o&-(){}/,.><?+-";
+ assertTrue(password.matches(regex));
+ password = "culonE1)";
+ assertTrue(password.matches(regex));
+
+ // Too short
+ password = "aB3@eF#";
+ assertFalse(password.matches(regex));
+
+ // No number
+ password = "#BeCCC#CeDfDf";
+ assertFalse(password.matches(regex));
+
+ // No lower case
+ password = "AB8C#CC@C4";
+ assertFalse(password.matches(regex));
+
+ // No upper case
+ password = "ab8defg9!";
+ assertFalse(password.matches(regex));
+
+ // No special characters
+ password = "aBc4ef7H8";
+ assertFalse(password.matches(regex));
+
+ // Underscore is a special character
+ password = "Azmb_123 ";
+ assertTrue(password.matches(regex));
}
}