You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2021/07/14 11:41:10 UTC
[sling-org-apache-sling-commons-crypto] branch master updated: test
POST requests with missing parameters and no crypto service available
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 6ec023c test POST requests with missing parameters and no crypto service available
6ec023c is described below
commit 6ec023c8b278ac0b181b1aa7bc7fcd5bdfec100e
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Wed Jul 14 13:41:00 2021 +0200
test POST requests with missing parameters and no crypto service available
---
.../internal/EncryptWebConsolePluginTest.java | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
index de31c2d..d4b7594 100644
--- a/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
+++ b/src/test/java/org/apache/sling/commons/crypto/webconsole/internal/EncryptWebConsolePluginTest.java
@@ -32,6 +32,7 @@ import org.osgi.framework.BundleContext;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class EncryptWebConsolePluginTest {
@@ -62,4 +63,43 @@ public class EncryptWebConsolePluginTest {
}
}
+ @Test
+ public void testPostServiceIdParameterMissing() throws ServletException, IOException {
+ final BundleContext bundleContext = mock(BundleContext.class);
+ final HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getParameter("service-id")).thenReturn(null);
+ when(request.getParameter("message")).thenReturn("");
+ final HttpServletResponse response = mock(HttpServletResponse.class);
+ final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
+ plugin.activate(bundleContext);
+ plugin.doPost(request, response);
+ verify(response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter service-id is missing");
+ }
+
+ @Test
+ public void testPostMessageParameterMissing() throws IOException, ServletException {
+ final BundleContext bundleContext = mock(BundleContext.class);
+ final HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getParameter("service-id")).thenReturn("");
+ when(request.getParameter("message")).thenReturn(null);
+ final HttpServletResponse response = mock(HttpServletResponse.class);
+ final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
+ plugin.activate(bundleContext);
+ plugin.doPost(request, response);
+ verify(response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter message is missing");
+ }
+
+ @Test
+ public void testPostCryptoServiceNotAvailable() throws ServletException, IOException {
+ final BundleContext bundleContext = mock(BundleContext.class);
+ final HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getParameter("service-id")).thenReturn("0");
+ when(request.getParameter("message")).thenReturn("");
+ final HttpServletResponse response = mock(HttpServletResponse.class);
+ final EncryptWebConsolePlugin plugin = new EncryptWebConsolePlugin();
+ plugin.activate(bundleContext);
+ plugin.doPost(request, response);
+ verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "Crypto service with service id 0 not found");
+ }
+
}