Copilot commented on code in PR #410: URL: https://github.com/apache/commons-jexl/pull/410#discussion_r3853027508
########## src/test/java/org/apache/commons/jexl3/internal/introspection/PermissionsRestrictedSweepTest.java: ########## @@ -0,0 +1,159 @@ +/* + * 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 + * + * https://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.commons.jexl3.internal.introspection; + +import static org.apache.commons.jexl3.introspection.JexlPermissions.RESTRICTED; +import static org.apache.commons.jexl3.introspection.JexlPermissions.SECURE; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.ListResourceBundle; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.TimeZone; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Phaser; +import java.util.concurrent.Semaphore; +import java.util.stream.BaseStream; + +import org.apache.commons.jexl3.introspection.JexlUberspect; +import org.junit.jupiter.api.Test; + +/** + * Checks the RESTRICTED (and SECURE) deny-list closes the containment gaps around + * process handles, module/resource loading, JVM-global mutators, uninterruptible + * blockers and off-heap/common-pool resources. + */ +class PermissionsRestrictedSweepTest { + + private static Method getMethod(final Class<?> clazz, final String name) { + for (final Method method : clazz.getMethods()) { + if (method.getName().equals(name)) { + return method; + } + } + return null; + } Review Comment: getMethod(...) returns null when a method name is missing, and most call sites immediately pass that value into RESTRICTED.allow(...). Since allow(null) is treated as a denial, these assertions can silently pass even if the JDK API changes or a method name is misspelled, weakening the test. Consider making getMethod fail fast (throw) when it can’t find the requested method. ########## src/test/java/org/apache/commons/jexl3/JXLTTest.java: ########## @@ -148,7 +148,13 @@ public String toString() { public static List<JexlBuilder> engines() { final JexlFeatures f = new JexlFeatures(); f.lexical(true).lexicalShade(true); - final JexlPermissions permissions = JexlPermissions.RESTRICTED.compose("org.apache.commons.jexl3 +{ JXLTTest{} }"); + // deny the test class itself but explicitly allow the nested fixture classes: a whole-class + // denial now propagates to nested classes (the -X{} keying gap is closed), so the fixtures + // the scripts touch must be positively declared inside the (container) block + final JexlPermissions permissions = JexlPermissions.RESTRICTED.compose( + "org.apache.commons.jexl3 +{ JXLTTest {" + + " +Context311 {} +Executor311 {} +Froboz {} +FrobozWriter {} +Arithmetic425 {}" + + " } }"); Review Comment: The permissions DSL here relies on the implicit default (a class entry without an explicit sign being treated as a denial) to deny JXLTTest. Since the surrounding comment explicitly describes this as a denial, it would be clearer/less error-prone to make the class denial explicit with a '-' sign (and keep the nested fixtures as explicit '+' allows). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
