Author: angela
Date: Thu Aug 18 08:40:27 2016
New Revision: 1756740
URL: http://svn.apache.org/viewvc?rev=1756740&view=rev
Log:
minor improvement: improve test coverage for o.a.j.oak.spi.security.user
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/AuthorizableTypeTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/UserIdCredentialsTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/ClearMembershipActionTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/CompositeActionProviderTest.java
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/AuthorizableTypeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/AuthorizableTypeTest.java?rev=1756740&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/AuthorizableTypeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/AuthorizableTypeTest.java
Thu Aug 18 08:40:27 2016
@@ -0,0 +1,97 @@
+/*
+ * 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.user;
+
+import java.util.UUID;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class AuthorizableTypeTest extends AbstractSecurityTest {
+
+ private Group gr;
+
+ @Override
+ public void before() throws Exception {
+ super.before();
+
+ gr = getUserManager(root).createGroup("gr" +
UUID.randomUUID().toString());
+ root.commit();
+ }
+
+ @Override
+ public void after() throws Exception {
+ try {
+ if (gr != null) {
+ gr.remove();
+ root.commit();
+ }
+ } finally {
+ super.after();
+ }
+ }
+
+ @Test
+ public void testGetType() throws Exception {
+ assertSame(AuthorizableType.USER,
AuthorizableType.getType(UserManager.SEARCH_TYPE_USER));
+ assertSame(AuthorizableType.GROUP,
AuthorizableType.getType(UserManager.SEARCH_TYPE_GROUP));
+ assertSame(AuthorizableType.AUTHORIZABLE,
AuthorizableType.getType(UserManager.SEARCH_TYPE_AUTHORIZABLE));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetTypeIllegalSearchType() throws Exception {
+ AuthorizableType.getType(0);
+ }
+
+ @Test
+ public void testIsTypeUser() throws Exception {
+ assertFalse(AuthorizableType.USER.isType(null));
+ assertTrue(AuthorizableType.USER.isType(getTestUser()));
+ assertFalse(AuthorizableType.USER.isType(gr));
+ }
+
+ @Test
+ public void testIsTypeGroup() throws Exception {
+ assertFalse(AuthorizableType.GROUP.isType(null));
+ assertFalse(AuthorizableType.GROUP.isType(getTestUser()));
+ assertTrue(AuthorizableType.GROUP.isType(gr));
+
+ }
+
+ @Test
+ public void testIsTypeAuthorizable() throws Exception {
+ assertFalse(AuthorizableType.AUTHORIZABLE.isType(null));
+ assertTrue(AuthorizableType.AUTHORIZABLE.isType(getTestUser()));
+ assertTrue(AuthorizableType.AUTHORIZABLE.isType(gr));
+ }
+
+ @Test
+ public void testGetAuthorizableClass() {
+ assertEquals(User.class, AuthorizableType.USER.getAuthorizableClass());
+ assertEquals(Group.class,
AuthorizableType.GROUP.getAuthorizableClass());
+ assertEquals(Authorizable.class,
AuthorizableType.AUTHORIZABLE.getAuthorizableClass());
+ }
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/UserIdCredentialsTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/UserIdCredentialsTest.java?rev=1756740&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/UserIdCredentialsTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/UserIdCredentialsTest.java
Thu Aug 18 08:40:27 2016
@@ -0,0 +1,31 @@
+/*
+ * 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.user;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class UserIdCredentialsTest {
+
+ @Test
+ public void testGetId() {
+ UserIdCredentials creds = new UserIdCredentials("id");
+ assertEquals("id", creds.getUserId());
+ }
+
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/ClearMembershipActionTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/ClearMembershipActionTest.java?rev=1756740&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/ClearMembershipActionTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/ClearMembershipActionTest.java
Thu Aug 18 08:40:27 2016
@@ -0,0 +1,100 @@
+/*
+ * 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.user.action;
+
+import java.util.UUID;
+
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class ClearMembershipActionTest extends AbstractSecurityTest {
+
+ private ClearMembershipAction action;
+
+ private Group gr;
+
+ @Override
+ public void before() throws Exception {
+ super.before();
+
+ gr = getUserManager(root).createGroup("gr" +
UUID.randomUUID().toString());
+ root.commit();
+
+ action = new ClearMembershipAction();
+ action.init(getSecurityProvider(), ConfigurationParameters.EMPTY);
+ }
+
+ @Override
+ public void after() throws Exception {
+ try {
+ if (gr != null) {
+ gr.remove();
+ root.commit();
+ }
+ } finally {
+ super.after();
+ }
+ }
+
+ @Test
+ public void testOnCreateUser() throws Exception {
+ action.onCreate(getTestUser(), "pw", root, NamePathMapper.DEFAULT);
+ assertFalse(root.hasPendingChanges());
+ }
+
+ @Test
+ public void testOnCreateGroup() throws Exception {
+ action.onCreate(gr, root, NamePathMapper.DEFAULT);
+ assertFalse(root.hasPendingChanges());
+ }
+
+ @Test
+ public void testOnPwChange() throws Exception {
+ action.onPasswordChange(getTestUser(), "newPw", root,
NamePathMapper.DEFAULT);
+ assertFalse(root.hasPendingChanges());
+ }
+
+ @Test
+ public void testOnRemoveUserNoMembership() throws Exception {
+ action.onRemove(getTestUser(), root, NamePathMapper.DEFAULT);
+ assertFalse(root.hasPendingChanges());
+ }
+
+ @Test
+ public void testOnRemoveGroupNoMembership() throws Exception {
+ action.onRemove(gr, root, NamePathMapper.DEFAULT);
+ assertFalse(root.hasPendingChanges());
+ }
+
+ @Test
+ public void testOnRemoveUserWithMembership() throws Exception {
+ User u = getTestUser();
+ gr.addMember(u);
+ root.commit();
+
+ action.onRemove(u, root, NamePathMapper.DEFAULT);
+ assertTrue(root.hasPendingChanges());
+ assertFalse(gr.isDeclaredMember(u));
+ }
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/CompositeActionProviderTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/CompositeActionProviderTest.java?rev=1756740&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/CompositeActionProviderTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/user/action/CompositeActionProviderTest.java
Thu Aug 18 08:40:27 2016
@@ -0,0 +1,74 @@
+/*
+ * 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.user.action;
+
+import java.util.List;
+import javax.annotation.Nonnull;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CompositeActionProviderTest extends AbstractSecurityTest {
+
+ @Test
+ public void testEmpty() {
+ CompositeActionProvider cap = new CompositeActionProvider();
+
assertTrue(cap.getAuthorizableActions(getSecurityProvider()).isEmpty());
+ }
+
+ @Test
+ public void testSingle() {
+ AuthorizableActionProvider aap = new TestAuthorizableActionProvider();
+ assertEquals(aap.getAuthorizableActions(getSecurityProvider()), new
CompositeActionProvider(aap).getAuthorizableActions(getSecurityProvider()));
+ }
+
+ @Test
+ public void testMultiple() {
+ AuthorizableActionProvider aap = new TestAuthorizableActionProvider();
+ AuthorizableActionProvider aap2 = new TestAuthorizableActionProvider();
+
+ assertEquals(ImmutableList.of(TestAction.INSTANCE,
TestAction.INSTANCE), new CompositeActionProvider(aap,
aap2).getAuthorizableActions(getSecurityProvider()));
+ }
+
+ @Test
+ public void testMultiple2() {
+ AuthorizableActionProvider aap = new TestAuthorizableActionProvider();
+ AuthorizableActionProvider aap2 = new TestAuthorizableActionProvider();
+
+ assertEquals(ImmutableList.of(TestAction.INSTANCE,
TestAction.INSTANCE), new CompositeActionProvider(ImmutableList.of(aap,
aap2)).getAuthorizableActions(getSecurityProvider()));
+ }
+
+
+ private final class TestAuthorizableActionProvider implements
AuthorizableActionProvider {
+
+ @Nonnull
+ @Override
+ public List<? extends AuthorizableAction>
getAuthorizableActions(@Nonnull SecurityProvider securityProvider) {
+ return ImmutableList.of(TestAction.INSTANCE);
+ }
+ }
+
+ private static final class TestAction extends AbstractAuthorizableAction {
+
+ private static final AuthorizableAction INSTANCE = new TestAction();
+ }
+}
\ No newline at end of file