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

creating user with existing login thros proper http status code

parent d8511866
......@@ -187,12 +187,12 @@ public class UserController extends BaseController {
@RequestMapping(value = "/users/{login:.+}", method = { RequestMethod.POST }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> addOverlay(
public Map<String, Object> addUser(
@RequestBody MultiValueMap<String, Object> formData,
@PathVariable(value = "login") String login,
@CookieValue(value = Configuration.AUTH_TOKEN) String token
) throws SecurityException, IOException, QueryException {
return userRest.addProject(token, login, formData);
return userRest.addUser(token, login, formData);
}
......
......@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectExistsException;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.api.QueryException;
......@@ -753,7 +754,7 @@ public class UserRestImpl extends BaseRestImpl {
return getUser(token, login, "");
}
public Map<String, Object> addProject(String token, String login, MultiValueMap<String, Object> userData)
public Map<String, Object> addUser(String token, String login, MultiValueMap<String, Object> userData)
throws QueryException, SecurityException {
if (!getUserService().userHasPrivilege(token, PrivilegeType.USER_MANAGEMENT)) {
throw new SecurityException("Access denied");
......@@ -761,7 +762,7 @@ public class UserRestImpl extends BaseRestImpl {
User user = getUserService().getUserByLogin(login);
if (user != null) {
throw new QueryException("user exists");
throw new ObjectExistsException("user exists");
}
user = new User();
user.setLogin(login);
......
......@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.HashMap;
......@@ -17,6 +18,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
......@@ -24,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import lcsb.mapviewer.api.ObjectExistsException;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.map.MiriamType;
......@@ -65,6 +68,29 @@ public class UserRestImplTest extends RestTestFunctions {
}
}
@Test
public void testAddExistingUser() throws Exception {
try {
userRestImpl.addUser(adminToken, Configuration.ANONYMOUS_LOGIN, new LinkedMultiValueMap<>());
fail("Exception expected");
} catch (ObjectExistsException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAddUser() throws Exception {
try {
Object response = userRestImpl.addUser(adminToken, "test_user", new LinkedMultiValueMap<>());
assertNotNull(response);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testUpdatePrivileges() throws Exception {
try {
......
Markdown is supported
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