You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2017/02/28 17:04:36 UTC
svn commit: r1784784 - in
/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak:
security/ security/authentication/ security/authentication/token/
spi/security/ spi/security/authentication/
Author: angela
Date: Tue Feb 28 17:04:36 2017
New Revision: 1784784
URL: http://svn.apache.org/viewvc?rev=1784784&view=rev
Log:
OAK-5793 : Improve coverage for security code in oak-core (wip)
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractCompositeConfigurationTest.java
- copied, changed from r1784739, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/AbstractCompositeConfigurationTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/PreAuthTest.java
- copied, changed from r1784739, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplNullTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/ImpersonationCredentialsTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/OpenAuthenticationConfigurationTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthContextTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthenticatedLoginTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/SystemSubjectTest.java
Removed:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/AbstractCompositeConfigurationTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/CompositeTokenConfigurationTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/GuestLoginModuleTest.java
Copied: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractCompositeConfigurationTest.java (from r1784739, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/AbstractCompositeConfigurationTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractCompositeConfigurationTest.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractCompositeConfigurationTest.java&p1=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/AbstractCompositeConfigurationTest.java&r1=1784739&r2=1784784&rev=1784784&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/AbstractCompositeConfigurationTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractCompositeConfigurationTest.java Tue Feb 28 17:04:36 2017
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.spi.security;
+package org.apache.jackrabbit.oak.security;
import java.util.List;
import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.CompositeConfiguration;
+import org.apache.jackrabbit.oak.spi.security.SecurityConfiguration;
public abstract class AbstractCompositeConfigurationTest<T extends SecurityConfiguration> extends AbstractSecurityTest {
Copied: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/PreAuthTest.java (from r1784739, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/PreAuthTest.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/PreAuthTest.java&p1=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthTest.java&r1=1784739&r2=1784784&rev=1784784&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/PreAuthTest.java Tue Feb 28 17:04:36 2017
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.spi.security.authentication;
+package org.apache.jackrabbit.oak.security.authentication;
import java.security.Principal;
import java.security.PrivilegedAction;
@@ -30,6 +30,8 @@ import javax.security.auth.login.LoginEx
import org.apache.jackrabbit.oak.AbstractSecurityTest;
import org.apache.jackrabbit.oak.api.AuthInfo;
import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl;
+import org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/CompositeTokenConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/CompositeTokenConfigurationTest.java?rev=1784784&r1=1784783&r2=1784784&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/CompositeTokenConfigurationTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/CompositeTokenConfigurationTest.java Tue Feb 28 17:04:36 2017
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.securi
import java.util.List;
-import org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest;
+import org.apache.jackrabbit.oak.security.AbstractCompositeConfigurationTest;
import org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration;
import org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenProvider;
import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration;
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java?rev=1784784&r1=1784783&r2=1784784&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java Tue Feb 28 17:04:36 2017
@@ -20,6 +20,9 @@ import java.lang.reflect.Field;
import java.util.List;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -29,15 +32,33 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-public class CompositeConfigurationTest extends AbstractCompositeConfigurationTest {
+public class CompositeConfigurationTest {
private static final String NAME = "test";
- @Override
- public void before() throws Exception {
- super.before();
+ private CompositeConfiguration compositeConfiguration;
- compositeConfiguration = new CompositeConfiguration("test", getSecurityProvider()) {};
+ @Before
+ public void before() throws Exception {
+ compositeConfiguration = new CompositeConfiguration("test", new SecurityProvider() {
+ @Nonnull
+ @Override
+ public ConfigurationParameters getParameters(@Nullable String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Nonnull
+ @Override
+ public Iterable<? extends SecurityConfiguration> getConfigurations() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Nonnull
+ @Override
+ public <T> T getConfiguration(@Nonnull Class<T> configClass) {
+ throw new UnsupportedOperationException();
+ }
+ }) {};
}
@Test
@@ -67,14 +88,14 @@ public class CompositeConfigurationTest
compositeConfiguration.addConfiguration(new SecurityConfiguration.Default());
compositeConfiguration.addConfiguration(new SecurityConfiguration.Default());
- List<SecurityConfiguration> configurations = getConfigurations();
+ List<SecurityConfiguration> configurations = compositeConfiguration.getConfigurations();
assertFalse(configurations.isEmpty());
assertEquals(2, configurations.size());
SecurityConfiguration def = new SecurityConfiguration.Default();
compositeConfiguration.setDefaultConfig(def);
- configurations = getConfigurations();
+ configurations = compositeConfiguration.getConfigurations();
assertEquals(2, configurations.size());
assertFalse(configurations.contains(def));
}
@@ -88,7 +109,7 @@ public class CompositeConfigurationTest
compositeConfiguration.addConfiguration(sc);
compositeConfiguration.removeConfiguration(def);
- List<SecurityConfiguration> configurations = compositeConfiguration.getConfigurations();
+ List configurations = compositeConfiguration.getConfigurations();
assertEquals(1, configurations.size());
assertEquals(sc, configurations.iterator().next());
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplNullTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplNullTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplNullTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplNullTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,68 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import javax.security.auth.Subject;
+
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class AuthInfoImplNullTest {
+
+ private final AuthInfoImpl authInfo = new AuthInfoImpl(null, null, null);
+
+ @Test
+ public void testGetUserID() {
+ assertNull(authInfo.getUserID());
+ }
+
+ @Test
+ public void testGetAttributeNames() {
+ String[] attrNames = authInfo.getAttributeNames();
+ assertNotNull(attrNames);
+ assertEquals(0, attrNames.length);
+ }
+
+ @Test
+ public void testGetAttribute() {
+ assertNull(authInfo.getAttribute("any"));
+ }
+
+ @Test
+ public void testGetPrincipals() {
+ assertTrue(authInfo.getPrincipals().isEmpty());
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(authInfo.toString());
+ }
+
+ @Test
+ public void testCreateAuthInfoFromEmptySubject() {
+ AuthInfo info = AuthInfoImpl.createFromSubject(new Subject());
+ assertNull(info.getUserID());
+ assertEquals(0, info.getAttributeNames().length);
+ assertTrue(info.getPrincipals().isEmpty());
+
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,131 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import java.security.Principal;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+import javax.security.auth.Subject;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class AuthInfoImplTest {
+
+ private static final String USER_ID = "userId";
+ private static final Map<String, String> ATTRIBUTES = ImmutableMap.of("attr", "value");
+ private static final Set<Principal> PRINCIPALS = ImmutableSet.<Principal>of(new PrincipalImpl("principalName"));
+
+ private final AuthInfoImpl authInfo = new AuthInfoImpl(USER_ID, ATTRIBUTES, PRINCIPALS);
+
+ @Test
+ public void testGetUserID() {
+ assertEquals(USER_ID, authInfo.getUserID());
+ }
+
+ @Test
+ public void testGetAttributeNames() {
+ String[] attrNames = authInfo.getAttributeNames();
+ assertArrayEquals(ATTRIBUTES.keySet().toArray(new String[ATTRIBUTES.size()]), attrNames);
+ }
+
+ @Test
+ public void testGetAttribute() {
+ for (String attrName : ATTRIBUTES.keySet()) {
+ assertEquals(ATTRIBUTES.get(attrName), authInfo.getAttribute(attrName));
+ }
+ }
+
+ @Test
+ public void testGetPrincipals() {
+ assertEquals(PRINCIPALS, authInfo.getPrincipals());
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(authInfo.toString());
+ }
+
+ @Test
+ public void testCreateFromSubjectWithAuthInfo() {
+ Subject subject = new Subject();
+ subject.getPublicCredentials().add(authInfo);
+
+ AuthInfo info = AuthInfoImpl.createFromSubject(subject);
+ assertEquals(USER_ID, info.getUserID());
+ assertEquals(PRINCIPALS, info.getPrincipals());
+ assertArrayEquals(authInfo.getAttributeNames(), info.getAttributeNames());
+ }
+
+ @Test
+ public void testCreateFromSubjectWithPrincipals() {
+ Subject subject = new Subject();
+ subject.getPrincipals().addAll(PRINCIPALS);
+
+ AuthInfo info = AuthInfoImpl.createFromSubject(subject);
+ assertNull(info.getUserID());
+ assertEquals(PRINCIPALS, info.getPrincipals());
+ assertEquals(0, info.getAttributeNames().length);
+ }
+
+ @Test
+ public void testCreateFromSubjectWithSimpleCredentials() {
+ Subject subject = new Subject();
+ subject.getPublicCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
+
+ AuthInfo info = AuthInfoImpl.createFromSubject(subject);
+ assertEquals(USER_ID, info.getUserID());
+ assertTrue(info.getPrincipals().isEmpty());
+ assertEquals(0, info.getAttributeNames().length);
+ }
+
+ @Test
+ public void testCreateFromSubjectWithPrivateSimpleCredentials() {
+ Subject subject = new Subject();
+ subject.getPrivateCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
+
+ AuthInfo info = AuthInfoImpl.createFromSubject(subject);
+ assertNull(info.getUserID());
+ assertTrue(info.getPrincipals().isEmpty());
+ assertEquals(0, info.getAttributeNames().length);
+ }
+
+
+ @Test
+ public void testCreateFromSubjectWithAnyCredentials() {
+ Subject subject = new Subject();
+ subject.getPublicCredentials().add(new Credentials() {
+ });
+
+ AuthInfo info = AuthInfoImpl.createFromSubject(subject);
+ assertNull(info.getUserID());
+ assertTrue(info.getPrincipals().isEmpty());
+ assertEquals(0, info.getAttributeNames().length);
+ }
+}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/GuestLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/GuestLoginModuleTest.java?rev=1784784&r1=1784783&r2=1784784&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/GuestLoginModuleTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/GuestLoginModuleTest.java Tue Feb 28 17:04:36 2017
@@ -60,6 +60,8 @@ public class GuestLoginModuleTest {
assertTrue(guestLoginModule.commit());
assertFalse(subject.getPrincipals(EveryonePrincipal.class).isEmpty());
assertFalse(subject.getPublicCredentials(GuestCredentials.class).isEmpty());
+
+ assertTrue(guestLoginModule.logout());
}
@Test
@@ -75,6 +77,8 @@ public class GuestLoginModuleTest {
assertFalse(guestLoginModule.commit());
assertTrue(subject.getPrincipals().isEmpty());
assertTrue(subject.getPublicCredentials().isEmpty());
+
+ assertFalse(guestLoginModule.logout());
}
@Test
@@ -90,6 +94,50 @@ public class GuestLoginModuleTest {
assertFalse(guestLoginModule.commit());
assertTrue(subject.getPrincipals().isEmpty());
assertTrue(subject.getPublicCredentials().isEmpty());
+
+ assertFalse(guestLoginModule.logout());
+ }
+
+ @Test
+ public void testThrowingCallbackhandler() throws LoginException {
+ Subject subject = new Subject();
+ CallbackHandler cbh = new ThrowingCallbackHandler(true);
+ Map sharedState = new HashMap();
+ guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
+
+ assertFalse(guestLoginModule.login());
+ assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
+
+ assertFalse(guestLoginModule.commit());
+ assertTrue(subject.getPublicCredentials(GuestCredentials.class).isEmpty());
+
+ assertFalse(guestLoginModule.logout());
+ }
+
+ @Test
+ public void testThrowingCallbackhandler2() throws LoginException {
+ Subject subject = new Subject();
+ CallbackHandler cbh = new ThrowingCallbackHandler(false);
+ Map sharedState = new HashMap();
+ guestLoginModule.initialize(subject, cbh, sharedState, Collections.<String, Object>emptyMap());
+
+ assertFalse(guestLoginModule.login());
+ assertFalse(sharedState.containsKey(AbstractLoginModule.SHARED_KEY_CREDENTIALS));
+
+ assertFalse(guestLoginModule.commit());
+ assertTrue(subject.getPublicCredentials(GuestCredentials.class).isEmpty());
+
+ assertFalse(guestLoginModule.logout());
+ }
+
+ @Test
+ public void testAbort() throws LoginException {
+ assertTrue(guestLoginModule.abort());
+ }
+
+ @Test
+ public void testLogout() throws LoginException {
+ assertFalse(guestLoginModule.logout());
}
//--------------------------------------------------------------------------
@@ -112,4 +160,22 @@ public class GuestLoginModuleTest {
}
}
}
+
+ private class ThrowingCallbackHandler implements CallbackHandler {
+
+ private boolean throwIOException;
+
+ private ThrowingCallbackHandler(boolean throwIOException) {
+ this.throwIOException = throwIOException;
+ }
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ if (throwIOException) {
+ throw new IOException();
+ } else {
+ throw new UnsupportedCallbackException(new Callback() {});
+ }
+ }
+ }
}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/ImpersonationCredentialsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/ImpersonationCredentialsTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/ImpersonationCredentialsTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/ImpersonationCredentialsTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,45 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import javax.jcr.Credentials;
+import javax.jcr.GuestCredentials;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class ImpersonationCredentialsTest {
+
+ private final AuthInfo info = new AuthInfoImpl(null, null, null);
+
+ @Test
+ public void testGetBaseCredentials() {
+ Credentials creds = new GuestCredentials();
+ assertSame(creds, new ImpersonationCredentials(creds, info).getBaseCredentials());
+
+ Credentials simpleCreds = new SimpleCredentials("userId", new char[0]);
+ assertSame(simpleCreds, new ImpersonationCredentials(simpleCreds, info).getBaseCredentials());
+ }
+
+ @Test
+ public void testGetAuthInfo() {
+ assertSame(info, new ImpersonationCredentials(new Credentials() {}, info).getImpersonatorInfo());
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/OpenAuthenticationConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/OpenAuthenticationConfigurationTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/OpenAuthenticationConfigurationTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/OpenAuthenticationConfigurationTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,68 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import java.security.Principal;
+import javax.jcr.Credentials;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginException;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class OpenAuthenticationConfigurationTest {
+
+ private final OpenAuthenticationConfiguration authConfig = new OpenAuthenticationConfiguration();
+
+ private LoginContextProvider lcp;
+
+ @Before
+ public void before() {
+ lcp = authConfig.getLoginContextProvider(null);
+ }
+
+ @Test
+ public void testLoginContextProvider() {
+ assertNotNull(lcp);
+ }
+
+ @Test
+ public void testLoginContextSubject() throws LoginException {
+ Credentials creds = new Credentials() {};
+ LoginContext ctx = lcp.getLoginContext(creds, null);
+ assertNotNull(ctx);
+
+ Subject subject = ctx.getSubject();
+ assertEquals(new Subject(true, ImmutableSet.<Principal>of(), ImmutableSet.of(), ImmutableSet.of(creds)), subject);
+ }
+
+ @Test
+ public void testLogin() throws LoginException {
+ // nop => must not throw
+ lcp.getLoginContext(new Credentials() {}, null).login();
+ }
+
+ @Test
+ public void testLogout() throws LoginException {
+ // nop => must not throw
+ lcp.getLoginContext(new Credentials() {}, null).logout();
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthContextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthContextTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthContextTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthContextTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,48 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import javax.security.auth.Subject;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class PreAuthContextTest {
+
+ private final Subject subject = new Subject();
+ private final PreAuthContext ctx = new PreAuthContext(subject);
+
+ @Test
+ public void testGetSuject() {
+ assertSame(subject, ctx.getSubject());
+ }
+
+ @Test
+ public void testLogin() {
+ // must not throw exception and must not change the subject
+ ctx.login();
+ assertSame(subject, ctx.getSubject());
+ }
+
+ @Test
+ public void testLogout() {
+ // must not throw exception and must not change the subject
+ ctx.logout();
+ assertSame(subject, ctx.getSubject());
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthenticatedLoginTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthenticatedLoginTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthenticatedLoginTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/PreAuthenticatedLoginTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,35 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class PreAuthenticatedLoginTest {
+
+ @Test
+ public void testGetUserId() {
+ assertEquals("id", new PreAuthenticatedLogin("id").getUserId());
+ }
+
+ @Test
+ public void testGetUserIdFromNullValue() {
+ assertNull(new PreAuthenticatedLogin(null).getUserId());
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/SystemSubjectTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/SystemSubjectTest.java?rev=1784784&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/SystemSubjectTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/SystemSubjectTest.java Tue Feb 28 17:04:36 2017
@@ -0,0 +1,47 @@
+/*
+ * 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.jackrabbit.oak.spi.security.authentication;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.jackrabbit.oak.spi.security.principal.SystemPrincipal;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SystemSubjectTest {
+
+ @Test
+ public void testPrincipals() {
+ assertEquals(ImmutableSet.of(SystemPrincipal.INSTANCE), SystemSubject.INSTANCE.getPrincipals());
+ }
+
+ @Test
+ public void testReadOnly() {
+ assertTrue(SystemSubject.INSTANCE.isReadOnly());
+ }
+
+ @Test
+ public void testPublicCredentials() {
+ assertTrue(SystemSubject.INSTANCE.getPublicCredentials().isEmpty());
+ }
+
+ @Test
+ public void testPrivateCredentials() {
+ assertTrue(SystemSubject.INSTANCE.getPrivateCredentials().isEmpty());
+ }
+}
\ No newline at end of file