diff options
author | Vitaly Takmazov | 2023-01-14 08:47:35 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-14 08:47:35 +0300 |
commit | 442e11655d5da5d58462eb197d94676c4c7c17c6 (patch) | |
tree | cfa525c38d19c2de08b4e9fd31fb455b84cba1a5 /src/test/java/com/juick/server/tests/ServerTests.java | |
parent | 63ead138664a6477460884d266d4f93011ec134a (diff) |
Pass tests with configured domain
Diffstat (limited to 'src/test/java/com/juick/server/tests/ServerTests.java')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 80627275..8956c721 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -212,6 +212,10 @@ public class ServerTests { private ProfileUriBuilder profileUriBuilder; @Inject private WebApp webApp; + @Value("${ap_base_uri:http://localhost:8080/}") + private String baseUri; + @Value("${web_domain:localhost}") + private String webDomain; @Inject private RestTemplate apClient; @@ -558,7 +562,7 @@ public class ServerTests { is(String.format("https://i.juick.com/photos-512/%d.png", msg.getMid())))) .andExpect(jsonPath("$[0].user.avatar", - is(String.format("http://localhost:8080/av-96-%s.png", hash)))); + is(String.format(baseUri + "av-96-%s.png", hash)))); } @Test @@ -1647,14 +1651,14 @@ public class ServerTests { @Test public void accountUrlShouldBeExposedOverWebfinger() throws Exception { - mockMvc.perform(get("/.well-known/webfinger?resource=acct:ugnich@localhost") + mockMvc.perform(get("/.well-known/webfinger?resource=acct:ugnich@" + webDomain) .accept("application/jrd+json")).andExpect(status().isOk()) - .andExpect(jsonPath("$.subject", is("acct:ugnich@localhost"))) + .andExpect(jsonPath("$.subject", is("acct:ugnich@" + webDomain))) .andExpect(jsonPath("$.links", hasSize(1))) - .andExpect(jsonPath("$.links[0].href", is("http://localhost:8080/u/ugnich"))); - mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@localhost")) + .andExpect(jsonPath("$.links[0].href", is(baseUri + "u/ugnich"))); + mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@" + webDomain)) .andExpect(status().isNotFound()); - mockMvc.perform(get("/.well-known/webfinger?resource=acct:@localhost")) + mockMvc.perform(get("/.well-known/webfinger?resource=acct:@" + webDomain)) .andExpect(status().isNotFound()); } @@ -1664,7 +1668,7 @@ public class ServerTests { String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream())); mockMvc.perform(get("/u/ugnich").accept(Context.LD_JSON_MEDIA_TYPE)).andExpect(status().isOk()) .andExpect(jsonPath("$.icon.url", - is(String.format("http://localhost:8080/av-96-%s.png", hash)))) + is(String.format(baseUri + "av-96-%s.png", hash)))) .andExpect(jsonPath("$.publicKey.publicKeyPem", is(keystoreManager.getPublicKeyPem()))); jdbcTemplate.execute("DELETE FROM messages"); List<Integer> mids = IteratorUtils.toList(IntStream.rangeClosed(1, 30) @@ -1676,7 +1680,7 @@ public class ServerTests { mockMvc.perform(get("/u/ugnich/blog").accept(Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE)) .andExpect(status().isOk()).andExpect(jsonPath("$.orderedItems", hasSize(20))) .andExpect(jsonPath("$.next", - is("http://localhost:8080/u/ugnich/blog?before=" + is(baseUri + "u/ugnich/blog?before=" + midsPage.get(midsPage.size() - 1)))); } @@ -1722,7 +1726,7 @@ public class ServerTests { webClient.getCookieManager() .addCookie(new com.gargoylesoftware.htmlunit.util.Cookie(loginCookie.getDomain(), loginCookie.getName(), loginCookie.getValue())); - HtmlPage threadPage = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); + HtmlPage threadPage = webClient.getPage(String.format(baseUri + "ugnich/%d", mid)); assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(200)); assertThat(threadPage.querySelectorAll(".msg-comment-target").isEmpty(), equalTo(false)); assertThat(threadPage.querySelectorAll(".a-thread-comment").isEmpty(), equalTo(false)); @@ -1730,7 +1734,7 @@ public class ServerTests { assertThat(userService.isInBLAny(freefd.getUid(), ugnich.getUid()), equalTo(true)); User renha = userService.createUser("renha", "secret").orElseThrow(IllegalStateException::new); messagesService.createReply(mid, 0, renha, "people", null); - threadPage = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); + threadPage = webClient.getPage(String.format(baseUri + "ugnich/%d", mid)); assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(200)); assertThat(threadPage.querySelectorAll(".msg-comment-target").isEmpty(), equalTo(true)); assertThat(threadPage.querySelectorAll(".a-thread-comment").isEmpty(), equalTo(true)); @@ -1811,8 +1815,7 @@ public class ServerTests { webClient.getCookieManager() .addCookie(new com.gargoylesoftware.htmlunit.util.Cookie(loginCookie.getDomain(), loginCookie.getName(), loginCookie.getValue())); - String discussionsUrl = "http://localhost:8080/"; - HtmlPage discussions = webClient.getPage(discussionsUrl); + HtmlPage discussions = webClient.getPage(baseUri); assertThat(discussions.querySelectorAll("article").size(), is(0)); subscriptionService.subscribeMessage(messagesService.getMessage(mid).get(), freefd); discussions = (HtmlPage) discussions.refresh(); @@ -1832,7 +1835,7 @@ public class ServerTests { .getNodeValue(), is(String.valueOf(mid))); Message msg = messagesService.getMessage(mid).get(); - HtmlPage discussionsOld = webClient.getPage(discussionsUrl + "?to=" + msg.getUpdated().toEpochMilli()); + HtmlPage discussionsOld = webClient.getPage(baseUri + "?to=" + msg.getUpdated().toEpochMilli()); assertThat(discussionsOld.querySelectorAll("article").size(), is(1)); assertThat(discussionsOld.querySelectorAll("article").get(0).getAttributes().getNamedItem("data-mid") .getNodeValue(), is(String.valueOf(midNew))); @@ -1857,7 +1860,7 @@ public class ServerTests { .getNodeValue(), is(String.valueOf(midNew))); Message old = messagesService.getMessage(newMids.get(0)).get(); - discussionsOld = webClient.getPage(discussionsUrl + "?to=" + old.getUpdated().toEpochMilli()); + discussionsOld = webClient.getPage(baseUri + "?to=" + old.getUpdated().toEpochMilli()); assertThat(discussionsOld.querySelectorAll("article").size(), is(1)); assertThat(discussionsOld.querySelectorAll("article").get(0).getAttributes().getNamedItem("data-mid") .getNodeValue(), is(String.valueOf(mid))); @@ -1909,9 +1912,9 @@ public class ServerTests { int mid = messagesService.createMessage(ugnich.getUid(), "new test", null, Set.of()); subscriptionService.subscribeMessage(messagesService.getMessage(mid).get(), freefd); messagesService.createReply(mid, 0, ugnich, "new reply", null); - HtmlPage discussionsPage = webClient.getPage("http://localhost:8080/?show=discuss"); + HtmlPage discussionsPage = webClient.getPage(baseUri + "?show=discuss"); assertThat(discussionsPage.querySelectorAll("#global a .badge").size(), is(1)); - HtmlPage unreadThread = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); + HtmlPage unreadThread = webClient.getPage(String.format(baseUri + "ugnich/%d", mid)); assertThat(unreadThread.querySelectorAll("#global a .badge").size(), is(0)); messagesService.createReply(mid, 0, ugnich, "reply to ban", null); discussionsPage.refresh(); @@ -2284,7 +2287,7 @@ public class ServerTests { String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream())); assertThat(webApp.getAvatarUrl(userService.getUserByName(freefdName)), - is(String.format("http://localhost:8080/av-96-%s.png", hash))); + is(String.format(baseUri + "av-96-%s.png", hash))); ClassPathResource newAvatar = new ClassPathResource("static/durov.png"); byte[] newAvatarData = IOUtils.toByteArray(newAvatar.getInputStream()); @@ -2298,7 +2301,7 @@ public class ServerTests { String convertedAvatarHash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(convertedAvatarUri)); mockMvc.perform(get("/api/me").with(httpBasic(freefdName, freefdPassword))).andExpect(status().isOk()) .andExpect(jsonPath("$.avatar", is( - String.format("http://localhost:8080/i/a/%d-%s.png", freefd.getUid(), + String.format(baseUri + "i/a/%d-%s.png", freefd.getUid(), convertedAvatarHash)))); mockMvc.perform(post("/api/me").with(httpBasic(ugnichName, ugnichPassword)).param("password", "newPassword")) @@ -2742,7 +2745,7 @@ public class ServerTests { @Test public void signedGetTest() { - var protectedAccount = "http://localhost:8080/u/ugnich"; + var protectedAccount = baseUri + "u/ugnich"; var context = activityPubService.get(URI.create(protectedAccount)); assertThat(context.get().getId(), is(protectedAccount)); } |