diff options
author | Alexander Alexeev | 2016-11-28 13:39:04 +0700 |
---|---|---|
committer | Alexander Alexeev | 2016-11-28 13:39:04 +0700 |
commit | bc23d2d2125d2086847397e85335f29a70668f6b (patch) | |
tree | 8c4f0ce7a91763eec65ce36559b7a6c388d9c68d /juick-api/src/test/java/com/juick | |
parent | 47a285e60b0780c7d81e4e1b77736f69e0aaf761 (diff) |
remember-me authorization with test; a statndard DaoAuthentication provider used
Diffstat (limited to 'juick-api/src/test/java/com/juick')
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 37 |
1 files changed, 36 insertions, 1 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 7f238b79..cec2bc7d 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 @@ -19,6 +19,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.http.MediaType; +import org.springframework.security.crypto.codec.Base64; import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -28,7 +29,9 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; +import javax.servlet.http.Cookie; import java.util.Collections; +import java.util.Optional; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -150,7 +153,39 @@ public class MessagesTests { } @Test - public void homeTestWithSimpleCors() throws Exception { + public void homeTestWithMessagesAndRememberMe() throws Exception { + String ugnichName = "ugnich"; + String uginchPassword = "MyPassw0rd!"; + String msgText = "Привет, я - Угнич"; + String hash = "12345678"; + + User user = getUser(1, ugnichName, uginchPassword); + Message msg = getMessage(user, msgText); + + when(userService.getUserByName(ugnichName)) + .thenReturn(user); + when(userService.getUserByUID(1)) + .thenReturn(Optional.of(user)); + when(userService.getFullyUserByName(ugnichName)) + .thenReturn(user); + when(messagesService.getMyFeed(1, 0)) + .thenReturn(Collections.singletonList(1)); + when(messagesService.getMessages(Collections.singletonList(1))) + .thenReturn(Collections.singletonList(msg)); + when(userService.getUIDbyHash(hash)) + .thenReturn(1); + + Cookie cookie = new Cookie("hash", new String(Base64.encode(hash.getBytes()))); + cookie.setDomain("juick.com"); + cookie.setMaxAge(100); + + mockMvc.perform( + get("/home").cookie(cookie)) + .andExpect(status().isOk()); + } + + @Test + public void homeTestWithMEssagesAndSimpleCors() throws Exception { String ugnichName = "ugnich"; String uginchPassword = "MyPassw0rd!"; |