aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-12-15 22:41:01 +0300
committerGravatar Vitaly Takmazov2022-12-15 22:41:01 +0300
commit540760905ebf929e2527034a1a7dc33e3c2a904a (patch)
treec2601f05974979e2943bb03870fc9aa9d1dced49 /src/test/java/com/juick/server
parentef5e5fc956e419e2ba053e4ac3df341af218aaf7 (diff)
Split ActivityPub test to fix tests
Diffstat (limited to 'src/test/java/com/juick/server')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 796417c8..2ea94d2f 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2181,8 +2181,6 @@ public class ServerTests {
assertThat(meUser, is(ugnich));
String testuserResponseString = IOUtils.toString(testuserResponse.getInputStream(),
StandardCharsets.UTF_8);
- String testappResponseString = IOUtils.toString(testappResponse.getInputStream(),
- StandardCharsets.UTF_8);
ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
URI testuserUri = URI.create("https://example.com/u/testuser");
URI testuserkeyUri = URI.create("https://example.com/u/testuser#main-key");
@@ -2193,8 +2191,6 @@ public class ServerTests {
.andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON));
restServiceServer.expect(times(4), requestTo(testuserkeyUri))
.andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON));
- restServiceServer.expect(times(2), requestTo(testAppUri))
- .andRespond(withSuccess(testappResponseString, MediaType.APPLICATION_JSON));
Person testuser = (Person) signatureManager.getContext(testuserUri).get();
assertThat(testuser.getPublicKey().getPublicKeyPem(), is(testKeystoreManager.getPublicKeyPem()));
Instant now2 = Instant.now();
@@ -2218,21 +2214,34 @@ public class ServerTests {
.header("Signature", testSignatureString).contentType(Context.LD_JSON_MEDIA_TYPE)
.content(payload))
.andExpect(status().isUnauthorized());
- // test flagging as application
- payload = IOUtils.toByteArray(flagPayload.getInputStream());
- digest = MessageDigest.getInstance("SHA-256").digest(payload); // (1)
- digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest));
- now2 = Instant.now();
- testRequestDate = DateFormattersHolder.getHttpDateFormatter().format(now2);
+ apClient.setRequestFactory(originalRequestFactory);
+ }
+
+ @Test
+ public void testFlaggingAsApplication() throws Exception {
+ var payload = IOUtils.toByteArray(flagPayload.getInputStream());
+ var digest = MessageDigest.getInstance("SHA-256").digest(payload); // (1)
+ var digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest));
+ var now2 = Instant.now();
+ String inboxUri = "/api/inbox";
+ String testHost = "localhost";
+ URI testAppUri = URI.create("https://example.com/actor");
+ String testappResponseString = IOUtils.toString(testappResponse.getInputStream(),
+ StandardCharsets.UTF_8);
+ var testRequestDate = DateFormattersHolder.getHttpDateFormatter().format(now2);
+ ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
+ MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient);
+ restServiceServer.expect(times(2), requestTo(testAppUri))
+ .andRespond(withSuccess(testappResponseString, MediaType.APPLICATION_JSON));
Application testapp = (Application) signatureManager.getContext(testAppUri).get();
assertThat(testapp.getPublicKey().getPublicKeyPem(), is(testKeystoreManager.getPublicKeyPem()));
- testSignatureString = signatureManager.addSignature(testapp, "localhost", "POST", inboxUri,
- testRequestDate,
- digestHeader, testKeystoreManager);
+ var testSignatureString = signatureManager.addSignature(testapp, "localhost", "POST", inboxUri,
+ testRequestDate,
+ digestHeader, testKeystoreManager);
mockMvc.perform(post(inboxUri).header("Host", testHost).header("Date", testRequestDate)
.header("Signature", testSignatureString).header("Digest", digestHeader)
.contentType(Context.LD_JSON_MEDIA_TYPE).content(payload))
- .andExpect(status().isAccepted());
+ .andExpect(status().isAccepted());
apClient.setRequestFactory(originalRequestFactory);
}