From commits-return-94962-archive-asf-public=cust-asf.ponee.io@sling.apache.org Wed Jul 14 11:41:12 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id E2798180669 for ; Wed, 14 Jul 2021 13:41:11 +0200 (CEST) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id 273743F171 for ; Wed, 14 Jul 2021 11:41:11 +0000 (UTC) Received: (qmail 60983 invoked by uid 500); 14 Jul 2021 11:41:11 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 60974 invoked by uid 99); 14 Jul 2021 11:41:10 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jul 2021 11:41:10 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B09D081EE9; Wed, 14 Jul 2021 11:41:10 +0000 (UTC) Date: Wed, 14 Jul 2021 11:41:10 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-commons-crypto] branch master updated: test POST requests with missing parameters and no crypto service available MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <162626287063.9346.1777209278906123373@gitbox.apache.org> From: olli@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-commons-crypto X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: e7cad7181edd3bacd85ed240d03a3700f75df6d1 X-Git-Newrev: 6ec023c8b278ac0b181b1aa7bc7fcd5bdfec100e X-Git-Rev: 6ec023c8b278ac0b181b1aa7bc7fcd5bdfec100e X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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"); + } + }