This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new 57955c7  test missing and invalid parameters
57955c7 is described below

commit 57955c7cd1a8e1fcc79767e41ca154b316ea6556
Author: Oliver Lietz <[email protected]>
AuthorDate: Sun May 30 11:10:11 2021 +0200

    test missing and invalid parameters
---
 .../crypto/it/tests/EncryptWebConsolePluginIT.java | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git 
a/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
 
b/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
index 8827162..ea4e13a 100644
--- 
a/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
+++ 
b/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
@@ -27,6 +27,8 @@ import java.util.Hashtable;
 import javax.inject.Inject;
 
 import org.apache.sling.commons.crypto.CryptoService;
+import org.jsoup.Connection.Method;
+import org.jsoup.Connection.Response;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.junit.Before;
@@ -131,4 +133,46 @@ public class EncryptWebConsolePluginIT extends 
CryptoTestSupport {
         
assertThat(document.getElementById("ciphertext").text()).isEqualTo(text);
     }
 
+    @Test
+    public void testEncryptMissingMessage() throws IOException {
+        final ServiceReference<CryptoService> reference = 
registration.getReference();
+        final String id = 
reference.getProperty(Constants.SERVICE_ID).toString();
+        final Response response = Jsoup.connect(url)
+            .header("Authorization", String.format("Basic %s", CREDENTIALS))
+            .data("service-id", id)
+            .method(Method.POST)
+            .ignoreHttpErrors(true)
+            .execute();
+        assertThat(response.statusCode()).isEqualTo(400);
+        assertThat(response.statusMessage()).isEqualTo("Parameter message is 
missing");
+    }
+
+    @Test
+    public void testEncryptMissingServiceId() throws IOException {
+        final String message = "Very secret message";
+        final Response response = Jsoup.connect(url)
+            .header("Authorization", String.format("Basic %s", CREDENTIALS))
+            .data("message", message)
+            .method(Method.POST)
+            .ignoreHttpErrors(true)
+            .execute();
+        assertThat(response.statusCode()).isEqualTo(400);
+        assertThat(response.statusMessage()).isEqualTo("Parameter service-id 
is missing");
+    }
+
+    @Test
+    public void testEncryptMissingInvalidServiceId() throws IOException {
+        final String id = "invalid";
+        final String message = "Very secret message";
+        final Response response = Jsoup.connect(url)
+            .header("Authorization", String.format("Basic %s", CREDENTIALS))
+            .data("service-id", id)
+            .data("message", message)
+            .method(Method.POST)
+            .ignoreHttpErrors(true)
+            .execute();
+        assertThat(response.statusCode()).isEqualTo(404);
+        assertThat(response.statusMessage()).isEqualTo("Crypto service with 
service id invalid not found");
+    }
+
 }

Reply via email to