snoopdave commented on code in PR #199: URL: https://github.com/apache/roller/pull/199#discussion_r4177510513
########## app/src/test/java/org/apache/roller/weblogger/pojos/wrapper/WrapperPojoConfinementTest.java: ########## @@ -0,0 +1,143 @@ +/* + * 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. For additional information regarding + * copyright in this work, please see the NOTICE file in the + * top level directory of this distribution. + */ +package org.apache.roller.weblogger.pojos.wrapper; + +import java.io.StringWriter; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Properties; + +import org.apache.roller.weblogger.pojos.User; +import org.apache.roller.weblogger.pojos.Weblog; +import org.apache.roller.weblogger.pojos.WeblogEntry; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Covers what a template can reach through the pojo wrappers. + * + * <p>Weblog templates are authored by weblog administrators, a role Roller + * treats as untrusted and renders under <code>SecureUberspector</code>. The + * wrappers exist precisely so that role only sees a safe surface, so the + * wrapped objects themselves must stay out of the template-visible surface. + * Java rendering code that does need them goes through {@link Wrappers}, + * which is never put in a template context. + */ +public class WrapperPojoConfinementTest { + + private static final Class<?>[] WRAPPED_TYPES = { + Weblog.class, WeblogEntry.class, User.class, + }; + + private static VelocityEngine engine; + + @BeforeAll + public static void setUpEngine() { + // the same introspection sandbox the weblog renderer configures + Properties props = new Properties(); Review Comment: 🤖Claude: fixed by loading the shipped `src/main/webapp/WEB-INF/velocity.properties` and initialising the engine from it (not yet pushed). Only the settings that need a running webapp are dropped: resource loaders, macro libraries, the include event handler and the logger. The introspection settings come from the real file, and the test fails if the file no longer sets an uberspector. `WrapperPojoConfinementTest`: 3/3 pass on JDK 11. -- 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]
