[
https://issues.apache.org/jira/browse/WICKET-5424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Martin Grigorov reopened WICKET-5424:
-------------------------------------
The issue is still existing in master branch -
http://ci.apache.org/builders/wicket-master/builds/1522/steps/compile/logs/stdio.
I've used the attached quickstart as a test case.
> Page.isPageStateless() returning true in regular run but false in WicketTester
> ------------------------------------------------------------------------------
>
> Key: WICKET-5424
> URL: https://issues.apache.org/jira/browse/WICKET-5424
> Project: Wicket
> Issue Type: Bug
> Affects Versions: 6.8.0, 6.12.0
> Reporter: Jyri-Matti Lähteenmäki
> Assignee: Sven Meier
> Fix For: 6.13.0, 7.0.0
>
> Attachments: WICKET-5424-tester.patch, wicket-bug-test.zip
>
>
> Motivation:
> Healthcheck/heartbeat pages must always be stateless to prevent significant
> amounts of session creation and storage.
> Also each anonymously accessed page in a public site should be stateless due
> to the same reason (otherwise the site could easily be DoSsed down).
> It would be nice to verify these requirements by tests.
> If I create an ought-to-be-stateless page with an AjaxLink which is hidden by
> a behavior:
> public class MyPage extends WebPage {
> public MyPage() {
> add(new AjaxLink<Void>("link") {
> @Override
> public void onClick(AjaxRequestTarget target) {
> //
> }
> }.add(new Behavior() {
> @Override
> public void onConfigure(Component c) {
> c.setVisible(false);
> }
> }));
> add(new Label("isPageStateless", new AbstractReadOnlyModel<Boolean>()
> {
> @Override
> public Boolean getObject() {
> return MyPage.this.isPageStateless();
> }
> }));
> }
> }
> then checking through a web server the page correctly prints "true", and no
> HttpSessions are created.
> However, when I try to verify statelessness through WicketTester, the
> following test passes:
> @Test
> public void testName() throws Exception {
> WicketTester tester = new WicketTester(new WebApplication() {
> @Override
> public Class<? extends Page> getHomePage() {
> return MyPage.class;
> }
> });
> tester.startPage(MyPage.class);
> tester.assertLabel("isPageStateless", "false");
> assertFalse(tester.getLastRenderedPage().isPageStateless());
> }
> It seems that somehow due to WicketTester, isPageStateless() is being invoked
> before any behaviors are run (and thus the AjaxLink is still visible), and
> since stateless-flag for the page is cached, it remains false.
> If it's by design that isPageStateless should always return the same result
> during each request, then I guess that the statelessness resolution process
> must not depend on anything happening after the page constructor? I assume
> it's not by design.
> Suggestions:
> A) Obvious fix would be to remove stateless-flag caching, since apparently it
> is causing problems, as also suggested by a hackish comment in Page.init().
> In general, caching should always be used sparingly.
> B) Or maybe whoever is invoking isPageStateless() at an early stage should
> actually be using Page.peekPageStateless()? But this doesn't really seem like
> a real fix, more like a temporary hack.
> C) All caching could also be disabled during test runs, but this would not be
> a good thing since tests should reproduce the actual behavior as closely as
> possible.
> D) In case this is a known issue without a proper fix, how then could I
> verify page statelessness through WicketTester? Currently I'm clearing the
> stateless-cache by reflection, which feels kind of bad...
--
This message was sent by Atlassian JIRA
(v6.1#6144)