jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1400067 - in /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security: ./ authentication/ authentication/token/ principal/ user/
Date Fri, 19 Oct 2012 12:23:48 GMT
Author: jukka
Date: Fri Oct 19 12:23:48 2012
New Revision: 1400067

URL: http://svn.apache.org/viewvc?rev=1400067&view=rev
Log:
OAK-352: Oak builder for simplified repository construction

Simplify repository construction for the security tests

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
Fri Oct 19 12:23:48 2012
@@ -22,8 +22,11 @@ import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginException;
 
+import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.junit.Before;
 
 /**
@@ -31,17 +34,22 @@ import org.junit.Before;
  */
 public abstract class AbstractSecurityTest {
 
+    protected final SecurityProvider securityProvider =
+            new SecurityProviderImpl();
+
     private ContentRepository contentRepository;
 
     @Before
     public void before() throws Exception {
-        contentRepository = createRepository();
+        contentRepository = new Oak()
+                .with(new InitialContent())
+                .with(securityProvider)
+                .createContentRepository();
+
         // TODO: OAK-17. workaround for missing test configuration
         Configuration.setConfiguration(new OakConfiguration());
     }
 
-    protected abstract ContentRepository createRepository();
-
     protected ContentSession login(Credentials credentials)
             throws LoginException, NoSuchWorkspaceException {
         return contentRepository.login(credentials, null);
@@ -52,4 +60,4 @@ public abstract class AbstractSecurityTe
         return new SimpleCredentials("admin", "admin".toCharArray());
     }
 
-}
\ No newline at end of file
+}

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
Fri Oct 19 12:23:48 2012
@@ -26,17 +26,12 @@ import javax.security.auth.login.LoginEx
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.AuthInfo;
-import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
 import org.junit.After;
@@ -53,8 +48,6 @@ import static org.junit.Assert.fail;
  */
 public class DefaultLoginModuleTest extends AbstractSecurityTest {
 
-    SecurityProvider securityProvider = new SecurityProviderImpl();
-
     ContentSession admin;
 
     @Before
@@ -73,14 +66,6 @@ public class DefaultLoginModuleTest exte
         }
     }
 
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(securityProvider)
-            .createContentRepository();
-    }
-
     @Test
     public void testNullLogin() throws Exception {
         ContentSession cs = null;

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
Fri Oct 19 12:23:48 2012
@@ -21,15 +21,10 @@ import javax.jcr.GuestCredentials;
 import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 
-import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.AuthInfo;
-import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
 import org.junit.After;
@@ -43,8 +38,6 @@ import static org.junit.Assert.assertEqu
  */
 public class GuestDefaultLoginModuleTest extends AbstractSecurityTest {
 
-    SecurityProvider securityProvider = new SecurityProviderImpl();
-
     @Before
     public void before() throws Exception {
         super.before();
@@ -56,14 +49,6 @@ public class GuestDefaultLoginModuleTest
         Configuration.setConfiguration(null);
     }
 
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(securityProvider)
-            .createContentRepository();
-    }
-
     @Test
     public void testNullLogin() throws Exception {
         ContentSession cs = login(null);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
Fri Oct 19 12:23:48 2012
@@ -24,16 +24,11 @@ import javax.security.auth.login.Configu
 import javax.security.auth.login.LoginException;
 
 import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials;
-import org.apache.jackrabbit.oak.Oak;
-import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule;
 import org.apache.jackrabbit.oak.security.authentication.token.TokenProviderImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo;
 import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider;
 import org.junit.After;
@@ -48,7 +43,6 @@ import static org.junit.Assert.fail;
  */
 public class TokenLoginModuleTest extends AbstractSecurityTest {
 
-    SecurityProvider securityProvider = new SecurityProviderImpl();
     ContentSession admin;
 
     @Before
@@ -65,14 +59,6 @@ public class TokenLoginModuleTest extend
         admin.close();
     }
 
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(securityProvider)
-            .createContentRepository();
-    }
-
     @Test
     public void testNullLogin() throws Exception {
         ContentSession cs = null;

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
Fri Oct 19 12:23:48 2012
@@ -23,13 +23,7 @@ import org.junit.Test;
 /**
  * TokenProviderImplTest...
  */
-public class TokenProviderImplTest extends AbstractSecurityTest {
-
-    @Override
-    protected ContentRepository createRepository() {
-        // TODO
-        return null;
-    }
+public class TokenProviderImplTest {
 
     @Test
     public void testDoCreateToken() throws Exception {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
Fri Oct 19 12:23:48 2012
@@ -19,16 +19,10 @@ package org.apache.jackrabbit.oak.securi
 import java.security.Principal;
 import java.util.Set;
 
-import org.apache.jackrabbit.oak.Oak;
-import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexHook;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
 import org.junit.Before;
@@ -43,7 +37,6 @@ import static org.junit.Assert.assertTru
  */
 public class PrincipalProviderImplTest extends AbstractSecurityTest {
 
-    private SecurityProvider securityProvider = new SecurityProviderImpl();
     private ContentSession admin;
     private PrincipalProviderImpl principalProvider;
 
@@ -56,15 +49,6 @@ public class PrincipalProviderImplTest e
         principalProvider = new PrincipalProviderImpl(root, securityProvider.getUserConfiguration(),
NamePathMapper.DEFAULT);
     }
 
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(new PropertyIndexHook())
-            .with(securityProvider)
-            .createContentRepository();
-    }
-
     @Test
     public void testGetPrincipals() throws Exception {
         String adminId = admin.getAuthInfo().getUserID();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
Fri Oct 19 12:23:48 2012
@@ -20,17 +20,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.oak.Oak;
-import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtility;
@@ -50,7 +45,6 @@ import static org.junit.Assert.fail;
  */
 public class UserManagerImplTest extends AbstractSecurityTest {
 
-    SecurityProvider securityProvider = new SecurityProviderImpl();
     ContentSession admin;
     Root root;
     UserManagerImpl userMgr;
@@ -68,14 +62,6 @@ public class UserManagerImplTest extends
         admin.close();
     }
 
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(securityProvider)
-            .createContentRepository();
-    }
-
     @Test
     public void testSetPassword() throws Exception {
         User user = userMgr.createUser("a", "pw");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java?rev=1400067&r1=1400066&r2=1400067&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
Fri Oct 19 12:23:48 2012
@@ -16,21 +16,16 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.ContentRepository;
-import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexHook;
 import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
-import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.util.Text;
@@ -50,9 +45,8 @@ import static org.junit.Assert.fail;
  * TODO: add tests for setProtectedProperty (might still be refactored...)
  * TODO: add tests for findAuthorizables once implementation is ready
  */
-public class UserProviderTest extends AbstractSecurityTest {
+public class UserProviderTest {
 
-    private ContentSession contentSession;
     private Root root;
 
     private ConfigurationParameters defaultConfig;
@@ -63,12 +57,12 @@ public class UserProviderTest extends Ab
     private String customUserPath = "/home/users";
     private String customGroupPath = "/home/groups";
 
-    private List<String> cleanupPaths = new ArrayList<String>();
-
     @Before
     public void setUp() throws Exception {
-        contentSession = login(getAdminCredentials());
-        root = contentSession.getLatestRoot();
+        root = new Oak()
+                .with(new InitialContent())
+                .with(new PropertyIndexHook())
+                .createRoot();
 
         defaultConfig = new ConfigurationParameters();
         defaultUserPath = defaultConfig.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
@@ -77,29 +71,11 @@ public class UserProviderTest extends Ab
         customOptions = new HashMap<String, Object>();
         customOptions.put(UserConstants.PARAM_GROUP_PATH, customGroupPath);
         customOptions.put(UserConstants.PARAM_USER_PATH, customUserPath);
-
-        cleanupPaths.add(defaultUserPath);
-        cleanupPaths.add(defaultGroupPath);
-        cleanupPaths.add(customUserPath);
-        cleanupPaths.add(customGroupPath);
     }
 
     @After
-    public void tearDown() throws Exception {
-        for (String path : cleanupPaths) {
-            Tree t = root.getTree(path);
-            if (t != null) {
-                t.remove();
-            }
-        }
-    }
-
-    @Override
-    protected ContentRepository createRepository() {
-        return new Oak()
-            .with(new InitialContent())
-            .with(new PropertyIndexHook())
-            .createContentRepository();
+    public void tearDown() {
+        root = null;
     }
 
     private UserProvider createUserProvider() {



Mime
View raw message