Skip to content

WW-5662 Run core tests with the OGNL allowlist enabled, as shipped - #2194

Open
sohankanna wants to merge 1 commit into
apache:mainfrom
sohankanna:WW-5662
Open

sohankanna wants to merge 1 commit into
apache:mainfrom
sohankanna:WW-5662

Conversation

@sohankanna

Copy link
Copy Markdown

Fixes WW-5662

struts.allowlist.enable ships as true, but every core test that boots a Dispatcher gets it forced to false by StrutsTestCaseHelper. That's how WW-5659 (every file upload rejected under the shipped default) passed the full core suite.

What I measured first

With the helper forced to true, the core suite gave 64 failing tests in 23 classes, out of 3,874 (46 failures, 18 errors). That's far smaller than expected. Almost all of them read or write test fixtures (TestBean, TestAction, actions pushed straight onto the stack) that a configuration provider would have allowlisted in a real app. That made option 2 from the ticket practical, staged.

Change

  • StrutsInternalTestCase now boots with struts.allowlist.enable=true unless a test sets it explicitly.
  • New hook allowlistedFixtureClasses(): a test declares the hand-made beans and actions its OGNL expressions touch, and they are appended to struts.allowlist.classes. The Javadoc says to never list framework classes, because a framework class missing from the allowlist is exactly what these tests should catch.
  • New hook isAllowlistEnabled(), reserved for the classes not migrated yet. Each override carries a one-line reason and a WW-5662 reference, so the remaining gap is listed in the code instead of hidden in a helper default.
  • Every other class built on StrutsInternalTestCase (including the tag tests via AbstractUITagTest) now runs with the allowlist on, unchanged.
  • 10 classes migrated by declaring their fixtures: FormButtonTest, SubmitTest, TagModelTest, DateTextFieldInterceptorTest, StreamResultTest, CookieInterceptorTest, CookieInterceptorAnnotationTest, IteratorComponentTest, LazyParamInjectorTest, StrutsResultFactoryTest.
  • 10 classes opted out for now, with reasons:
    • anonymous fixture classes: StrutsResultSupportTest, StrutsUtilTest, FreemarkerResultMockedTest;
    • interceptors or results built without the configuration provider: DefaultInterceptorFactoryTest, ActionFileUploadInterceptorTest (LazyParamsAllowlistTest still covers that path with the allowlist on);
    • NodeGuardSelectionTest (object-creating expressions rejected before the guard);
    • OgnlUtilStrutsTest (size() on a JDK List);
    • CheckboxTest, OptGroupTest, FreemarkerTest (template rendering against undeclared stack state).
  • StrutsTestCaseHelper keeps its false default, so struts2-junit-plugin users see no change. That matches the ticket's non-goals.

Something to look at separately

OgnlUtilStrutsTest.testAccessToSizeMethod fails under the shipped allowlist because persons.size() on an ArrayList is rejected. If that's not intended for production either, it deserves its own ticket. I didn't change any framework behavior here.

Testing

  • mvn -pl core test: 3,876 run, 0 failures, 0 errors, BUILD SUCCESS (with WW-5855's two TokenHelperTest cases also in the tree, which is why it's 3,876 and not 3,874).
  • Same suite with the allowlist forced on before this change: 3,874 run, 46 failures, 18 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant