This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 6ab5e4540a Remove the SecurityManager specific tests 6ab5e4540a is described below commit 6ab5e4540ab5ca2fbb783ab3ae47f53db96f651c Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jan 11 18:44:09 2023 +0000 Remove the SecurityManager specific tests --- build.xml | 13 -- ...estApplicationContextFacadeSecurityManager.java | 148 --------------------- .../util/security/SecurityManagerBaseTest.java | 50 ------- 3 files changed, 211 deletions(-) diff --git a/build.xml b/build.xml index 8f3aa69513..dc3c6ce1a8 100644 --- a/build.xml +++ b/build.xml @@ -2036,21 +2036,8 @@ <exclude name="**/*Performance.java" if="${test.excludePerformance}" /> <!-- Exclude tests that Gump can't compile --> <exclude name="org/apache/tomcat/buildutil/**" /> - <!-- - Avoid running tests which require the SecurityManager with other - tests. See below for more details. - --> - <exclude name="**/*SecurityManager.java" /> </fileset> </batchtest> - <!-- - Run tests which require the SecurityManager in their own forked - batch to ensure that global/system security settings don't pollute - other tests. See SecurityManagerBaseTest.java for more details. - --> - <batchtest todir="${test.reports}" unless="test.entry" fork="true"> - <fileset dir="test" includes="**/SecurityManager.java" excludes="${test.exclude}" /> - </batchtest> </junit> </jacoco:coverage> </sequential> diff --git a/test/org/apache/catalina/core/TestApplicationContextFacadeSecurityManager.java b/test/org/apache/catalina/core/TestApplicationContextFacadeSecurityManager.java deleted file mode 100644 index fc5a5d53f1..0000000000 --- a/test/org/apache/catalina/core/TestApplicationContextFacadeSecurityManager.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.catalina.core; - -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Collection; -import java.util.stream.Collectors; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; - -import org.apache.catalina.security.SecurityUtil; -import org.apache.tomcat.util.security.SecurityManagerBaseTest; -import org.easymock.EasyMock; -import org.easymock.IExpectationSetters; -import org.easymock.internal.LastControl; - -@RunWith(Parameterized.class) -public final class TestApplicationContextFacadeSecurityManager extends SecurityManagerBaseTest { - - /** - * @return {@link Collection} of non-static, non-object, public {@link - * Method}s in {@link ApplicationContextFacade} to be run with the the Java - * 2 {@link SecurityManager} been enabled. - */ - @Parameterized.Parameters(name = "{index}: method={0}") - public static Collection<Method> publicApplicationContextFacadeMethods() { - return Arrays.stream(ApplicationContextFacade.class.getMethods()) - .filter(method -> !Modifier.isStatic(method.getModifiers())) - .filter(method -> { - try { - Object.class.getMethod(method.getName(), method.getParameterTypes()); - return false; - } catch (final NoSuchMethodException e) { - return true; - } - }) - .collect(Collectors.toList()); - } - - - private static Object[] getDefaultParams(final Method method) { - final int paramsCount = method.getParameterCount(); - final Object[] params = new Object[paramsCount]; - final Class<?>[] paramTypes = method.getParameterTypes(); - for (int i = 0; i < params.length; i++) { - params[i] = getDefaultValue(paramTypes[i]); - } - return params; - } - - - @SuppressWarnings("unchecked") - private static <T> T getDefaultValue(final Class<T> clazz) { - return !isVoid(clazz) ? (T) Array.get(Array.newInstance(clazz, 1), 0) : null; - } - - - private static <T> boolean isVoid(Class<T> clazz) { - return void.class.equals(clazz) || Void.class.equals(clazz); - } - - - @Parameter(0) - public Method methodToTest; - - - /** - * Test for - * <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=64735">Bug - * 64735</a> which confirms that {@link ApplicationContextFacade} behaves - * correctly when the Java 2 {@link SecurityManager} has been enabled. - * - * @throws NoSuchMethodException Should never happen - * @throws IllegalAccessException Should never happen - * @throws InvocationTargetException Should never happen - */ - @Test - public void testBug64735() - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - Assert.assertTrue(SecurityUtil.isPackageProtectionEnabled()); - - // Mock the ApplicationContext that we provide to the ApplicationContextFacade. - final ApplicationContext mockAppContext = EasyMock.createMock(ApplicationContext.class); - final Method expectedAppContextMethod = - ApplicationContext.class.getMethod( - methodToTest.getName(), - methodToTest.getParameterTypes()); - - // Expect that only the provided method which is being tested will be called exactly once. - final IExpectationSetters<Object> expectationSetters; - if (isVoid(expectedAppContextMethod.getReturnType())) { - expectedAppContextMethod.invoke(mockAppContext, getDefaultParams(methodToTest)); - expectationSetters = EasyMock.expectLastCall(); - } else { - expectationSetters = - EasyMock.expect(expectedAppContextMethod.invoke( - mockAppContext, getDefaultParams(methodToTest))); - } - expectationSetters - .andAnswer(() -> { - Assert.assertEquals( - expectedAppContextMethod, - LastControl.getCurrentInvocation().getMethod()); - return getDefaultValue(expectedAppContextMethod.getReturnType()); - }).once(); - EasyMock.replay(mockAppContext); - EasyMock.verifyUnexpectedCalls(mockAppContext); - - // Invoke the method on ApplicationContextFacade. Fail if any unexpected exceptions are - // thrown. - try { - methodToTest.invoke( - new ApplicationContextFacade(mockAppContext), - getDefaultParams(methodToTest)); - } catch (final IllegalAccessException | InvocationTargetException e) { - throw new AssertionError( - "Failed to call " + - methodToTest + - " with SecurityManager enabled.", - e); - } - - // Verify that the method called through to the wrapped ApplicationContext correctly. - EasyMock.verifyRecording(); - } -} diff --git a/test/org/apache/tomcat/util/security/SecurityManagerBaseTest.java b/test/org/apache/tomcat/util/security/SecurityManagerBaseTest.java deleted file mode 100644 index af7ff8ffaf..0000000000 --- a/test/org/apache/tomcat/util/security/SecurityManagerBaseTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.tomcat.util.security; - -import java.security.Permission; - -import org.apache.catalina.security.SecurityUtil; - -/** - * Base test class for unit tests which require the Java 2 {@link - * SecurityManager} to be enabled. Tests that extend this class must be run in a - * forked SecurityManager test batch since this class modifies global {@link - * System} settings which may interfere with other tests. On static class - * initialization, this class sets up the {@code "package.definition"} and - * {@code "package.access"} system properties and adds a no-op SecurityManager - * which does not check permissions. These settings are required in order to - * make {@link org.apache.catalina.Globals#IS_SECURITY_ENABLED} and {@link - * SecurityUtil#isPackageProtectionEnabled()} return true. - */ -public abstract class SecurityManagerBaseTest { - static { - System.setProperty("package.definition", "test"); - System.setProperty("package.access", "test"); - System.setSecurityManager(new SecurityManager() { - @Override - public void checkPermission(final Permission permission) { - // no-op - } - - @Override - public void checkPermission(final Permission permission, Object context) { - // no-op - } - }); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org