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

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 93963a8  SLING-10163 : Improve test coverage with sling.auth.core
93963a8 is described below

commit 93963a8b85ab1ec1c1ca540ee2c4351089f18bb6
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Mar 24 17:23:03 2021 +0100

    SLING-10163 : Improve test coverage with sling.auth.core
---
 .../core/impl/AuthenticationHandlersManager.java   |  2 +-
 .../sling/auth/core/impl/SlingAuthenticator.java   |  2 +-
 .../auth/core/impl/AuthenticationHandlersTest.java | 65 ++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
 
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
index dbfb103..f604cb1 100644
--- 
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
+++ 
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
@@ -60,7 +60,7 @@ public class AuthenticationHandlersManager extends 
PathBasedHolderCache<Abstract
      */
     Map<String, List<String>> getAuthenticationHandlerMap() {
         final List<AbstractAuthenticationHandlerHolder> registeredHolders = 
this.getHolders();
-        final LinkedHashMap<String, List<String>> handlerMap = new 
LinkedHashMap<String, List<String>>();
+        final LinkedHashMap<String, List<String>> handlerMap = new 
LinkedHashMap<>();
         for (final AbstractAuthenticationHandlerHolder holder : 
registeredHolders) {
             final List<String> provider = 
handlerMap.computeIfAbsent(holder.fullPath, key -> new ArrayList<>());
             provider.add(holder.getProvider());
diff --git 
a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java 
b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
index 5fa742d..6943259 100644
--- a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
+++ b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
@@ -1388,7 +1388,7 @@ public class SlingAuthenticator implements Authenticator,
 
         // redirect to there
         try {
-            response.sendRedirect(target);
+            response.sendRedirect(target); // NOSONAR The redirect is checked 
for validity using AuthUtil
         } catch (IOException e) {
             log.error("Failed to redirect to the page: " + target, e);
         }
diff --git 
a/src/test/java/org/apache/sling/auth/core/impl/AuthenticationHandlersTest.java 
b/src/test/java/org/apache/sling/auth/core/impl/AuthenticationHandlersTest.java
new file mode 100644
index 0000000..19663ca
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/auth/core/impl/AuthenticationHandlersTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.auth.core.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class AuthenticationHandlersTest {
+
+    @Test public void testDefaultConfiguration() {
+        final AuthenticationHandlersManager manager = new 
AuthenticationHandlersManager(SlingAuthenticatorTest.createDefaultConfig());
+
+        final Map<String, List<String>> map = 
manager.getAuthenticationHandlerMap();
+        assertEquals(1, map.size());
+        final List<String> list = map.get("/");
+        assertNotNull(list);
+        assertEquals(1, list.size());
+        assertEquals("HTTP Basic Authentication Handler (preemptive)", 
list.get(0));
+    }
+
+    @Test public void testDefaultConfigurationDisabled() {
+        final SlingAuthenticator.Config config = 
SlingAuthenticatorTest.createDefaultConfig();
+        
when(config.auth_http()).thenReturn(SlingAuthenticator.HTTP_AUTH_DISABLED);
+        final AuthenticationHandlersManager manager = new 
AuthenticationHandlersManager(config);
+
+        final Map<String, List<String>> map = 
manager.getAuthenticationHandlerMap();
+        assertTrue(map.isEmpty());
+    }
+
+    @Test public void testDefaultConfigurationEnabled() {
+        final SlingAuthenticator.Config config = 
SlingAuthenticatorTest.createDefaultConfig();
+        
when(config.auth_http()).thenReturn(SlingAuthenticator.HTTP_AUTH_ENABLED);
+        final AuthenticationHandlersManager manager = new 
AuthenticationHandlersManager(config);
+
+        final Map<String, List<String>> map = 
manager.getAuthenticationHandlerMap();
+        assertEquals(1, map.size());
+        final List<String> list = map.get("/");
+        assertNotNull(list);
+        assertEquals(1, list.size());
+        assertEquals("HTTP Basic Authentication Handler (enabled)", 
list.get(0));
+    }
+}

Reply via email to