aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/test/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-27 17:13:27 +0300
committerGravatar Vitaly Takmazov2016-11-27 17:13:27 +0300
commita1dfdabfa7a43b28d827458a0b4c5f6a2a1a9013 (patch)
tree301d1637666efdb05ef6ae390df4ca92f4233039 /juick-api/src/test/java
parente741ce2ec74765e49b9c279264afdddf5a1122f6 (diff)
juick-api: red tests for cors and hash authentication
Diffstat (limited to 'juick-api/src/test/java')
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
index 788582a0..6996adb9 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -9,6 +9,7 @@ import com.juick.api.configuration.ApiSecurityConfig;
import com.juick.configuration.DataConfiguration;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
+import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -72,6 +73,7 @@ public class MessagesTests {
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(SecurityMockMvcConfigurers.springSecurity())
+ .dispatchOptions(true)
.build();
}
@@ -107,9 +109,17 @@ public class MessagesTests {
mockMvc.perform(get("/home").with(httpBasic(ugnichName, uginchPassword)))
.andExpect(status().isOk())
+ .andExpect(header().string("Access-Control-Allow-Origin", "*"))
+ .andExpect(header().string("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE"))
+ .andExpect(header().string("Access-Control-Allow-Headers", "*"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(1)))
.andExpect(jsonPath("$[0].mid", is(1)))
.andExpect(jsonPath("$[0].body", is(msgText)));
+ String hash = RandomStringUtils.random(16);
+ when(userService.getHashByUID(1)).thenReturn(hash);
+ mockMvc.perform(get("/messages")
+ .param("hash", hash))
+ .andExpect(status().isOk());
}
}