Loading src/main/java/it/inaf/oats/vospace/CreateNodeController.java +2 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,8 @@ public class CreateNodeController extends BaseNodeController { List<String> nodeGroups = Arrays.asList(groupWritePropValues.get(0).split(" ", -1)); if (!nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) { if (userGroups == null || !nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) { // If groups don't match check ownership at least List<String> nodeOwner = getNodePropertyByURI(parentNode, "ivo://ivoa.net/vospace/core#creator"); Loading src/test/java/it/inaf/oats/vospace/CreateNodeControllerTest.java +54 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.mockito.ArgumentMatchers.any; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; Loading @@ -26,9 +25,14 @@ import net.ivoa.xml.vospace.v2.LinkNode; import java.util.List; import it.inaf.ia2.aa.data.User; import java.util.Optional; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.ContextConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @SpringBootTest @AutoConfigureMockMvc(addFilters = false) @ContextConfiguration(classes = {TokenFilterConfig.class}) @TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true") @AutoConfigureMockMvc public class CreateNodeControllerTest { @MockBean Loading @@ -48,11 +52,27 @@ public class CreateNodeControllerTest { // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("test1 test2"); groups.setValue("group1 group2"); parentNode.setProperties(List.of(groups)); return parentNode; } private ContainerNode getContainerParentNodeWithCreator(String path){ ContainerNode parentNode = new ContainerNode(); // Set parent node address at / parentNode.setUri("vos://example.com!vospace" + path); // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("group3"); Property creator = new Property(); creator.setUri("ivo://ivoa.net/vospace/core#creator"); creator.setValue("user2"); parentNode.setProperties(List.of(groups,creator)); return parentNode; } private LinkNode getLinkParentNode(String path) { LinkNode parentNode = new LinkNode(); // Set parent node address at / Loading @@ -60,7 +80,7 @@ public class CreateNodeControllerTest { // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("test1 test2"); groups.setValue("group1 group2"); parentNode.setProperties(List.of(groups)); return parentNode; } Loading @@ -80,7 +100,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_XML)) Loading @@ -98,7 +118,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_JSON)) Loading @@ -116,7 +136,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -134,7 +154,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) Loading @@ -151,11 +171,8 @@ public class CreateNodeControllerTest { when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getContainerParentNode("/"))); User user = new User(); user.setGroups(List.of("test3", "test4")); mockMvc.perform(put("/nodes/mydata2") .principal(user) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -176,7 +193,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/mydata1"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -194,7 +211,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.ofNullable(null)); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -212,7 +229,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getLinkParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -227,10 +244,10 @@ public class CreateNodeControllerTest { String requestBody = getResourceFileContent("create-unstructured-data-node.xml"); when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getLinkParentNode("/"))); .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user1_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -240,6 +257,24 @@ public class CreateNodeControllerTest { verifyArguments(); } @Test public void testWriteWithOnlyOwnership() throws Exception { String requestBody = getResourceFileContent("create-unstructured-data-node.xml"); when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getContainerParentNodeWithCreator("/"))); mockMvc.perform(put("/nodes/mydata1") .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) .andDo(print()) .andExpect(status().is2xxSuccessful()); verifyArguments(); } private void verifyArguments() { verify(controller).createNode( argThat(node -> { Loading Loading
src/main/java/it/inaf/oats/vospace/CreateNodeController.java +2 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,8 @@ public class CreateNodeController extends BaseNodeController { List<String> nodeGroups = Arrays.asList(groupWritePropValues.get(0).split(" ", -1)); if (!nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) { if (userGroups == null || !nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) { // If groups don't match check ownership at least List<String> nodeOwner = getNodePropertyByURI(parentNode, "ivo://ivoa.net/vospace/core#creator"); Loading
src/test/java/it/inaf/oats/vospace/CreateNodeControllerTest.java +54 −19 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.mockito.ArgumentMatchers.any; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; Loading @@ -26,9 +25,14 @@ import net.ivoa.xml.vospace.v2.LinkNode; import java.util.List; import it.inaf.ia2.aa.data.User; import java.util.Optional; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.ContextConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @SpringBootTest @AutoConfigureMockMvc(addFilters = false) @ContextConfiguration(classes = {TokenFilterConfig.class}) @TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true") @AutoConfigureMockMvc public class CreateNodeControllerTest { @MockBean Loading @@ -48,11 +52,27 @@ public class CreateNodeControllerTest { // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("test1 test2"); groups.setValue("group1 group2"); parentNode.setProperties(List.of(groups)); return parentNode; } private ContainerNode getContainerParentNodeWithCreator(String path){ ContainerNode parentNode = new ContainerNode(); // Set parent node address at / parentNode.setUri("vos://example.com!vospace" + path); // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("group3"); Property creator = new Property(); creator.setUri("ivo://ivoa.net/vospace/core#creator"); creator.setValue("user2"); parentNode.setProperties(List.of(groups,creator)); return parentNode; } private LinkNode getLinkParentNode(String path) { LinkNode parentNode = new LinkNode(); // Set parent node address at / Loading @@ -60,7 +80,7 @@ public class CreateNodeControllerTest { // Set groupwrite property Property groups = new Property(); groups.setUri("ivo://ivoa.net/vospace/core#groupwrite"); groups.setValue("test1 test2"); groups.setValue("group1 group2"); parentNode.setProperties(List.of(groups)); return parentNode; } Loading @@ -80,7 +100,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_XML)) Loading @@ -98,7 +118,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_JSON)) Loading @@ -116,7 +136,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -134,7 +154,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) Loading @@ -151,11 +171,8 @@ public class CreateNodeControllerTest { when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getContainerParentNode("/"))); User user = new User(); user.setGroups(List.of("test3", "test4")); mockMvc.perform(put("/nodes/mydata2") .principal(user) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -176,7 +193,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getContainerParentNode("/mydata1"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -194,7 +211,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.ofNullable(null)); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -212,7 +229,7 @@ public class CreateNodeControllerTest { .thenReturn(Optional.of(getLinkParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -227,10 +244,10 @@ public class CreateNodeControllerTest { String requestBody = getResourceFileContent("create-unstructured-data-node.xml"); when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getLinkParentNode("/"))); .thenReturn(Optional.of(getContainerParentNode("/"))); mockMvc.perform(put("/nodes/mydata1") .principal(getUser()) .header("Authorization", "Bearer user1_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) Loading @@ -240,6 +257,24 @@ public class CreateNodeControllerTest { verifyArguments(); } @Test public void testWriteWithOnlyOwnership() throws Exception { String requestBody = getResourceFileContent("create-unstructured-data-node.xml"); when(nodeDao.listNode(eq("/"))) .thenReturn(Optional.of(getContainerParentNodeWithCreator("/"))); mockMvc.perform(put("/nodes/mydata1") .header("Authorization", "Bearer user2_token") .content(requestBody) .contentType(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML)) .andDo(print()) .andExpect(status().is2xxSuccessful()); verifyArguments(); } private void verifyArguments() { verify(controller).createNode( argThat(node -> { Loading