incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1512253 - in /sling/branches/SLING-2987-healthcheck-redesign: core/src/main/java/org/apache/sling/hc/impl/healthchecks/ core/src/test/java/org/apache/sling/hc/impl/ samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/
Date Fri, 09 Aug 2013 11:05:22 GMT
Author: bdelacretaz
Date: Fri Aug  9 11:05:22 2013
New Revision: 1512253

URL: http://svn.apache.org/r1512253
Log:
SLING-2987 - DefaultLoginsHealthCheckTest checks multiple logins

Modified:
    sling/branches/SLING-2987-healthcheck-redesign/core/src/main/java/org/apache/sling/hc/impl/healthchecks/DefaultLoginsHealthCheck.java
    sling/branches/SLING-2987-healthcheck-redesign/core/src/test/java/org/apache/sling/hc/impl/DefaultLoginsHealthCheckTest.java
    sling/branches/SLING-2987-healthcheck-redesign/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json

Modified: sling/branches/SLING-2987-healthcheck-redesign/core/src/main/java/org/apache/sling/hc/impl/healthchecks/DefaultLoginsHealthCheck.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/core/src/main/java/org/apache/sling/hc/impl/healthchecks/DefaultLoginsHealthCheck.java?rev=1512253&r1=1512252&r2=1512253&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/core/src/main/java/org/apache/sling/hc/impl/healthchecks/DefaultLoginsHealthCheck.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/core/src/main/java/org/apache/sling/hc/impl/healthchecks/DefaultLoginsHealthCheck.java
Fri Aug  9 11:05:22 2013
@@ -19,6 +19,7 @@ package org.apache.sling.hc.impl.healthc
 
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Credentials;
@@ -54,14 +55,10 @@ public class DefaultLoginsHealthCheck im
 
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final Map<String, String> info = new HashMap<String, String>();
-    private String username;
-    private String password;
     
-    @Property
-    public static final String PROP_USERNAME = "username";
-    
-    @Property
-    public static final String PROP_PASSWORD = "password";
+    @Property(cardinality=500)
+    public static final String PROP_LOGINS = "logins";
+    private List<String> logins;
     
     @Property(cardinality=50)
     public static final String PROP_TAGS = Constants.HC_TAGS;
@@ -77,37 +74,57 @@ public class DefaultLoginsHealthCheck im
     
     @Activate
     public void activate(ComponentContext ctx) {
-        username = PropertiesUtil.toString(ctx.getProperties().get(PROP_USERNAME), "");
-        password = PropertiesUtil.toString(ctx.getProperties().get(PROP_PASSWORD), "");
+        logins = Arrays.asList(PropertiesUtil.toStringArray(ctx.getProperties().get(PROP_LOGINS),
new String[] {}));
         
-        info.put(PROP_USERNAME, username);
         info.put(Constants.HC_NAME, PropertiesUtil.toString(ctx.getProperties().get(Constants.HC_NAME),
""));
         info.put(Constants.HC_MBEAN_NAME, PropertiesUtil.toString(ctx.getProperties().get(Constants.HC_MBEAN_NAME),
""));
         info.put(Constants.HC_TAGS, 
                 Arrays.asList(PropertiesUtil.toStringArray(ctx.getProperties().get(Constants.HC_TAGS),
new String[] {})).toString());
         
-        log.info("Activated, username={}", username);
+        log.info("Activated, logins={}", logins);
     }
     
     @Override
     public Result execute(ResultLog log) {
         final Result result = new Result(this, log);
-        final Credentials creds = new SimpleCredentials(username, password.toCharArray());
-        Session s = null;
-        try {
-            s = repository.login(creds);
-            if(s != null) {
-                log.warn("Login as [{}] succeeded, was expecting it to fail", username);
-            } else {
-                log.debug("Login as [{}] didn't throw an Exception but returned null Session",
username);
+        int checked=0;
+        int failures=0;
+        
+        for(String login : logins) {
+            final String [] parts = login.split(":");
+            if(parts.length != 2) {
+                log.warn("Expected login in the form username:password, got {}", login);
+                continue;
             }
-        } catch(RepositoryException re) {
-            log.debug("Login as [{}] failed, as expected", username);
-        } finally {
-            if(s != null) {
-                s.logout();
+            checked++;
+            final String username = parts[0].trim();
+            final String password = parts[1].trim();
+            final Credentials creds = new SimpleCredentials(username, password.toCharArray());
+            Session s = null;
+            try {
+                s = repository.login(creds);
+                if(s != null) {
+                    failures++;
+                    log.warn("Login as [{}] succeeded, was expecting it to fail", username);
+                } else {
+                    log.debug("Login as [{}] didn't throw an Exception but returned null
Session", username);
+                }
+            } catch(RepositoryException re) {
+                log.debug("Login as [{}] failed, as expected", username);
+            } finally {
+                if(s != null) {
+                    s.logout();
+                }
             }
         }
+        
+        if(checked==0) {
+            log.warn("Did not check any logins, configured logins={}", logins);
+        } else if(failures != 0){
+            log.warn("Checked {} logins, {} tests failed", checked, failures);
+        } else {
+            log.debug("Checked {} logins, all tests successful", checked);
+        }
         return result;
     }
 

Modified: sling/branches/SLING-2987-healthcheck-redesign/core/src/test/java/org/apache/sling/hc/impl/DefaultLoginsHealthCheckTest.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/core/src/test/java/org/apache/sling/hc/impl/DefaultLoginsHealthCheckTest.java?rev=1512253&r1=1512252&r2=1512253&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/core/src/test/java/org/apache/sling/hc/impl/DefaultLoginsHealthCheckTest.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/core/src/test/java/org/apache/sling/hc/impl/DefaultLoginsHealthCheckTest.java
Fri Aug  9 11:05:22 2013
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Field;
+import java.util.Arrays;
 
 import javax.jcr.Credentials;
 import javax.jcr.Session;
@@ -42,10 +43,9 @@ public class DefaultLoginsHealthCheckTes
     
     private final Logger logger = LoggerFactory.getLogger(getClass());
     
-    private Result getTestResult(String username, String password) throws Exception {
+    private Result getTestResult(String login) throws Exception {
         final DefaultLoginsHealthCheck c = new DefaultLoginsHealthCheck();
-        setField(c, "username", username);
-        setField(c, "password", password);
+        setField(c, "logins", Arrays.asList(new String[] { login }));
         
         final SlingRepository repo = Mockito.mock(SlingRepository.class);
         setField(c, "repository", repo);
@@ -73,11 +73,11 @@ public class DefaultLoginsHealthCheckTes
     
     @Test
     public void testHealthCheckFails() throws Exception {
-        assertFalse("Expecting failed check", getTestResult("admin",  "admin").isOk());
+        assertFalse("Expecting failed check", getTestResult("admin:admin").isOk());
     }
     
     @Test
     public void testHealthCheckSucceeds() throws Exception {
-        assertTrue("Expecting successful check", getTestResult("FOO",  "bar").isOk());
+        assertTrue("Expecting successful check", getTestResult("FOO:bar").isOk());
     }
 }
\ No newline at end of file

Modified: sling/branches/SLING-2987-healthcheck-redesign/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json?rev=1512253&r1=1512252&r2=1512253&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.hc.DefaultLoginsHealthCheck-1.json
Fri Aug  9 11:05:22 2013
@@ -1,7 +1,6 @@
 {
     "jcr:primaryType" : "sling:OsgiConfig",
-    "username" : "admin",
-    "password" : "admin",
-    "hc.name" : "Admin login fails with default password", 
+    "logins" : ["admin:admin","foo:bar"],
+    "hc.name" : "Default logins should fail", 
     "hc.tags" : [security] 
 }



Mime
View raw message