Skip to content
Snippets Groups Projects
Commit f987da70 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

password cannot be null

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