Commit f987da70 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

password cannot be null

parent e4ac848c
......@@ -55,6 +55,7 @@ public class UserDaoTest extends PersistTestFunctions {
long counter = userDao.getCount();
user = new User();
user.setCryptedPassword("");
user.setLogin(testLogin);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
......@@ -104,6 +105,7 @@ public class UserDaoTest extends PersistTestFunctions {
user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
long counter2 = userDao.getCount();
......@@ -115,6 +117,7 @@ public class UserDaoTest extends PersistTestFunctions {
assertNull(user2);
user2 = new User();
user2.setCryptedPassword("");
user2.setLogin(testLogin);
userDao.add(user2);
......@@ -186,6 +189,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchema() throws Exception {
try {
User user = new User();
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
uas.setValidateMiriamTypes(true);
UserClassAnnotators ca = new UserClassAnnotators();
......@@ -227,6 +231,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchemaGuiPreferences() throws Exception {
try {
User user = new User();
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
UserGuiPreference option = new UserGuiPreference();
......@@ -252,6 +257,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchemaRequiredAnnotations() throws Exception {
try {
User user = new User();
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
uas.addClassRequiredAnnotations(
......@@ -275,6 +281,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorParams() throws Exception {
try {
User user = new User();
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
UserClassAnnotators classAnnotators = new UserClassAnnotators(Integer.class);
......
......@@ -94,58 +94,58 @@ public class UserRestImpl extends BaseRestImpl {
String column = string.toLowerCase();
Object value;
switch (column) {
case "id":
case "idobject":
value = user.getId();
break;
case "name":
value = user.getName();
break;
case "surname":
value = user.getSurname();
break;
case "login":
value = user.getLogin();
break;
case "email":
value = user.getEmail();
break;
case "mincolor":
value = user.getMinColor();
break;
case "maxcolor":
value = user.getMaxColor();
break;
case "neutralcolor":
value = user.getNeutralColor();
break;
case "simplecolor":
value = user.getSimpleColor();
break;
case "removed":
value = user.isRemoved();
break;
case "termsofuseconsent":
value = user.isTermsOfUseConsent();
break;
case "connectedtoldap":
value = user.isConnectedToLdap();
break;
case "ldapaccountavailable":
if (ldapAvailable == null) {
ldapAvailable = false;
}
value = ldapAvailable;
break;
case "privileges":
value = preparePrivileges(user);
break;
case "preferences":
value = preparePreferences(user);
break;
default:
value = "Unknown column";
break;
case "id":
case "idobject":
value = user.getId();
break;
case "name":
value = user.getName();
break;
case "surname":
value = user.getSurname();
break;
case "login":
value = user.getLogin();
break;
case "email":
value = user.getEmail();
break;
case "mincolor":
value = user.getMinColor();
break;
case "maxcolor":
value = user.getMaxColor();
break;
case "neutralcolor":
value = user.getNeutralColor();
break;
case "simplecolor":
value = user.getSimpleColor();
break;
case "removed":
value = user.isRemoved();
break;
case "termsofuseconsent":
value = user.isTermsOfUseConsent();
break;
case "connectedtoldap":
value = user.isConnectedToLdap();
break;
case "ldapaccountavailable":
if (ldapAvailable == null) {
ldapAvailable = false;
}
value = ldapAvailable;
break;
case "privileges":
value = preparePrivileges(user);
break;
case "preferences":
value = preparePreferences(user);
break;
default:
value = "Unknown column";
break;
}
result.put(string, value);
}
......@@ -412,7 +412,7 @@ public class UserRestImpl extends BaseRestImpl {
}
if (value instanceof MiriamType) {
return (MiriamType) value;
}
}
return MiriamType.valueOf((String) value);
}
......@@ -707,13 +707,16 @@ public class UserRestImpl extends BaseRestImpl {
throw new QueryException("login must match url");
}
} else if (key.equalsIgnoreCase("defaultPrivileges")) {
if (stringValue != null ) {
if (stringValue != null) {
defaultPrivileges = "true".equalsIgnoreCase(stringValue);
}
} else {
throw new QueryException("Unknown parameter: " + key);
}
}
if (user.getCryptedPassword() == null) {
throw new QueryException("password cannot be null");
}
getUserService().addUser(user);
if (defaultPrivileges) {
getUserService().grantDefaultPrivileges(user);
......
......@@ -146,6 +146,7 @@ public class UserServiceTest extends ServiceTestFunctions {
long logCount = getInfos().size();
User user2 = new User();
user2.setLogin("login");
user2.setCryptedPassword("");
userService.addUser(user2);
assertNotNull(user2.getId());
long logCount2 = getInfos().size();
......
......@@ -300,7 +300,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName"))));
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("password", "FirstName")
)));
RequestBuilder grantRequest = post("/users/" + testLogin)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
......@@ -313,6 +315,24 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
assertNotNull(userService.getUserByLogin(testLogin));
}
@Test
public void testAddUserWithoutPassword() throws Exception {
String testLogin = "xyz";
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName")
)));
RequestBuilder grantRequest = post("/users/" + testLogin)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(grantRequest)
.andExpect(status().isBadRequest());
}
@Test
public void testGrantDefaultPrivilegesWhenAddingUser() throws Exception {
String testLogin = "xyz";
......@@ -324,6 +344,7 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("password", "FirstName"),
new BasicNameValuePair("defaultPrivileges", "true"))));
RequestBuilder grantRequest = post("/users/" + testLogin)
......@@ -358,6 +379,7 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("password", "FirstName"),
new BasicNameValuePair("defaultPrivileges", "true"))));
RequestBuilder grantRequest = post("/users/" + testLogin)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment