aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java2
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java38
2 files changed, 38 insertions, 2 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index 41f7cefc..5c2701eb 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -270,7 +270,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
public com.juick.Message getMessage(final int mid) {
List<com.juick.Message> list = getJdbcTemplate().query(
"SELECT messages.message_id, 0 as rid, 0 as replyto, "
- + "messages.user_id, users.nick, 0 as banned, "
+ + "messages.user_id, users.nick, users.banned as banned, "
+ "TIMESTAMPDIFF(MINUTE, messages.ts, NOW()),"
+ "messages.ts,"
+ "messages.readonly, messages.privacy, messages.replies,"
diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java
index b4fa14bb..ffa540b8 100644
--- a/juick-www/src/test/java/com/juick/www/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java
@@ -1,5 +1,6 @@
package com.juick.www;
+import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.juick.Message;
@@ -22,11 +23,12 @@ import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
import org.springframework.web.context.WebApplicationContext;
import javax.inject.Inject;
+import java.io.IOException;
import java.util.Collections;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.when;
/**
@@ -87,4 +89,38 @@ public class WebAppTests {
HtmlPage threadPage = webClient.getPage("http://localhost:8080/ugnich/1");
assertThat(threadPage.getTitleText(), equalTo("ugnich:"));
}
+ @Test
+ public void bannedUserBlogandPostShouldReturn404() throws IOException {
+ String userName = "isilmine";
+ String userPassword = "secret";
+ String msgText = "автор этого поста был забанен";
+ String hash = "12345678";
+
+ User user = MockUtils.mockUser(2, userName, userPassword);
+ user.setBanned(true);
+ Message msg = MockUtils.mockMessage(2, user, msgText);
+
+ when(userService.getUIDbyName(userName))
+ .thenReturn(2);
+ when(userService.getUserByName(userName))
+ .thenReturn(user);
+ when(userService.getUserByUID(2))
+ .thenReturn(Optional.of(user));
+ when(userService.getFullyUserByName(userName))
+ .thenReturn(user);
+ when(messagesService.getMyFeed(2, 0))
+ .thenReturn(Collections.singletonList(2));
+ when(messagesService.getMessages(Collections.singletonList(2)))
+ .thenReturn(Collections.singletonList(msg));
+ when(userService.getUIDbyHash(hash))
+ .thenReturn(1);
+ when(messagesService.getMessageAuthor(2)).thenReturn(user);
+ when(messagesService.canViewThread(2, 0)).thenReturn(true);
+ when(messagesService.getMessage(2)).thenReturn(msg);
+ webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
+ Page blogPage = webClient.getPage("http://localhost:8080/isilmine");
+ Page threadPage = webClient.getPage("http://localhost:8080/isilmine/2");
+ assertThat(blogPage.getWebResponse().getStatusCode(), equalTo(404));
+ assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(404));
+ }
}