Skip to content

Commit

Permalink
Revert "ENG-442 update tests for csrf enable in spring security (#637)…
Browse files Browse the repository at this point in the history
…" (#645)

This reverts commit 6d70b22.

Co-authored-by: Breno Queiroz <[email protected]>
  • Loading branch information
BrenoQVDS and Breno Queiroz authored May 20, 2020
1 parent ba6f4d7 commit 682937b
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 292 deletions.
6 changes: 0 additions & 6 deletions plugins/entando-plugin-jacms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,5 @@
<version>1.18.2</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package org.entando.entando.plugins.jacms.web.contentmodel;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.agiletec.aps.system.common.FieldSearchFilter;
import com.agiletec.aps.system.services.user.UserDetails;
import com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel;
Expand All @@ -24,6 +13,16 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ContentModelControllerIntegrationTest extends AbstractControllerIntegrationTest {

private static final String BASE_URI = "/plugins/cms/contentmodels";
Expand All @@ -41,15 +40,15 @@ public void testGetContentModelsSortId() throws Exception {
ResultActions result = mockMvc
.perform(get(BASE_URI)
.param("sort", "id")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload[0].id", is(1)));

result = mockMvc
.perform(get(BASE_URI)
.param("direction", FieldSearchFilter.DESC_ORDER)
.param("sort", "id")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload[0].id", is(11)));

Expand All @@ -61,7 +60,7 @@ public void testGetContentModelDefaultSorting() throws Exception {
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc
.perform(get(BASE_URI)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.metaData.pageSize", is(100)));
result.andExpect(jsonPath("$.metaData.sort", is("id")));
Expand All @@ -77,15 +76,15 @@ public void testGetContentModelsSortByDescr() throws Exception {
.perform(get(BASE_URI)
.param("direction", FieldSearchFilter.ASC_ORDER)
.param("sort", "descr")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload[0].descr", is("List Model")));

result = mockMvc
.perform(get(BASE_URI)
.param("direction", FieldSearchFilter.DESC_ORDER)
.param("sort", "descr")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload[0].descr", is("scheda di un articolo")));

Expand All @@ -102,7 +101,7 @@ public void testGetContentModelsWithFilters() throws Exception {
.param("sort", "descr")
.param("filters[0].attribute", "contentType")
.param("filters[0].value", "ART")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.length()", is(4)));

Expand All @@ -114,7 +113,7 @@ public void testGetContentModelsWithFilters() throws Exception {
.param("filters[0].value", "ART")
.param("filters[1].attribute", "descr")
.param("filters[1].value", "MoDeL")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.length()", is(2)));
}
Expand All @@ -126,7 +125,7 @@ public void testGetContentModelOk() throws Exception {
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc
.perform(get(BASE_URI + "/{modelId}", "1")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.id", is(1)));

Expand All @@ -139,7 +138,7 @@ public void testGetContentModelKo() throws Exception {
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc
.perform(get(BASE_URI + "/{modelId}", "0")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isNotFound());
result.andExpect(jsonPath("$.errors[0].code", is("1")));
}
Expand All @@ -151,7 +150,7 @@ public void testGetContentModelDictionary() throws Exception {
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc
.perform(get(BASE_URI + "/dictionary")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());

}
Expand All @@ -164,7 +163,7 @@ public void testGetContentModelDictionaryWithTypeCode() throws Exception {
ResultActions result = mockMvc
.perform(get(BASE_URI + "/dictionary")
.param("typeCode", "EVN")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload").isNotEmpty());
result.andExpect(jsonPath("$.payload.$content").isNotEmpty());
Expand All @@ -178,7 +177,7 @@ public void testGetContentModelDictionaryValidTypeCodeInvalid() throws Exception
ResultActions result = mockMvc
.perform(get(BASE_URI + "/dictionary")
.param("typeCode", "LOL")
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isNotFound());
result.andExpect(jsonPath("$.errors[0].code", is("6")));
}
Expand All @@ -204,7 +203,7 @@ public void testCrudContentModel() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());
ContentModel contentModelAdded = this.contentModelManager.getContentModel(modelId);
Expand All @@ -226,7 +225,7 @@ public void testCrudContentModel() throws Exception {
.perform(put(BASE_URI + "/{id}", modelId)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());
contentModelAdded = this.contentModelManager.getContentModel(modelId);
Expand All @@ -240,7 +239,7 @@ public void testCrudContentModel() throws Exception {
.perform(delete(BASE_URI + "/{id}", modelId)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.modelId", is(String.valueOf(modelId))));
Expand Down Expand Up @@ -278,7 +277,7 @@ public void testAddWithInvalidContentType() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isConflict());
result.andExpect(jsonPath("$.errors[0].code", is("6")));
Expand Down Expand Up @@ -313,7 +312,7 @@ public void testAddWithIdAboveMax() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is("56")));
Expand Down Expand Up @@ -348,7 +347,7 @@ public void testChangeContentType() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());

Expand All @@ -365,7 +364,7 @@ public void testChangeContentType() throws Exception {
.perform(put(BASE_URI + "/{id}", modelId)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk())
.andExpect(jsonPath("$.errors.size()", is(0)))
Expand Down Expand Up @@ -401,7 +400,7 @@ public void testChangeWithInvalidContentType() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());

Expand All @@ -417,7 +416,7 @@ public void testChangeWithInvalidContentType() throws Exception {
.perform(put(BASE_URI + "/{id}", modelId)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isConflict())
.andExpect(jsonPath("$.errors[0].code", is(String.valueOf("6"))));
Expand Down Expand Up @@ -451,7 +450,7 @@ public void testChangeContentShapeToNull() throws Exception {
.perform(post(BASE_URI)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());

Expand All @@ -467,7 +466,7 @@ public void testChangeContentShapeToNull() throws Exception {
.perform(put(BASE_URI + "/{id}", modelId)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(payload)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errors.size()", is(1)));
Expand All @@ -492,7 +491,7 @@ public void testDeleteReferencedModel() throws Throwable {
ResultActions result = mockMvc
.perform(delete(BASE_URI + "/{id}", 2)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isConflict());
result.andExpect(jsonPath("$.errors[0].code", is(String.valueOf("5"))));
Expand All @@ -507,7 +506,7 @@ public void testGetModelPageReferences() throws Throwable {
ResultActions result = mockMvc
.perform(get(BASE_URI + "/{id}/pagereferences", 2)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.header("Authorization", "Bearer " + accessToken).with(csrf()));
.header("Authorization", "Bearer " + accessToken));

result.andExpect(status().isOk());
}
Expand Down
Loading

0 comments on commit 682937b

Please sign in to comment.