Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-65585] Fix requestSubmit() usage #5479

Merged
merged 10 commits into from
May 25, 2021

Conversation

thomasgl-orange
Copy link
Contributor

@thomasgl-orange thomasgl-orange commented May 10, 2021

See JENKINS-65585 and #5405.

This is where I'm at, trying to untangle this 2.289 regression with HtmlUnit tests on some submit buttons.

What I've understood so far:

  • passing the "submitter" parameter is indeed required in some cases with HtmlUnit
  • the "submitter" param has to be a <button type="submit" /> or <input type="submit" /> (otherwise we get a JS exception)
  • it is possible to get the clicked button in yui/button submitForm() function (not sure my method is always correct, nor that it is the simplest one)
  • unfortunately, this button usually has type="button", because:
    • lib/form/submit.jelly produces an <input type="submit"/> (so far so good)
    • scripts/hudson-behavior.js YUIfy it by calling YAHOO.widget.Button
    • this constructor (also from yui/button-*.js) produces a <button type="button"/>, ignoring the original type

So, that's two (scary) changes in yui/button-*.js. It seems to fix the test regression on TrustHostKeyActionTest in ssh-slaves, but is not much tested otherwise. Hence this PR, to get a first CI run (I don't expect it to be blue).

FTR, the button-min.js has been regenerated with yuicompressor (plus copy/paste of the copyright header):

yuicompressor --type js --line-break 6060 war/src/main/webapp/scripts/yui/button/button-debug.js 

It gives two unmodified lines, and then a bunch of obfuscated minified code which should obviously be regenerated by a maintainer if this ever gets merged.

Proposed changelog entries

@thomasgl-orange
Copy link
Contributor Author

Unfortunately, this changes don't fix the failed tests in pipeline-input-step-plugin. It changes things a bit though, that's still interesting.

Test method:

  • the plugin pom.xml is patched to use a custom build of JTH-htmlunit, based on an up-to-date htmlunit version (I think it made no difference):
$ git diff -- pom.xml
diff --git a/pom.xml b/pom.xml
index 38cc735..819db36 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,14 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+
+      <dependency>
+  <groupId>org.jenkins-ci.main</groupId>
+  <artifactId>jenkins-test-harness-htmlunit</artifactId>
+  <version>3.1-SNAPSHOT</version>
+  <scope>test</scope>
+      </dependency>
+
         </dependencies>
     </dependencyManagement>
     <dependencies>
  • I'm running a single test:
mvn test -Djenkins.version=2.289 -Denforcer.skip=true -Dtest="InputStepTest#parameter"
  • BEFORE (with 2.289):
=== Starting parameter(org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest)
   0.094 [id=15]	INFO	o.jvnet.hudson.test.WarExploder#explode: Exploding /home/lwjs1183/.m2/repository/org/jenkins-ci/main/jenkins-war/2.289/jenkins-war-2.289.war into /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/jenkins-for-test
   2.298 [id=15]	INFO	o.jvnet.hudson.test.JenkinsRule#createWebServer: Running on http://localhost:41096/jenkins/
   4.778 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Started initialization
   4.972 [id=34]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins7196962060972152232/plugins/trilead-api.jpi
   4.997 [id=34]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins7196962060972152232/plugins/sshd.jpi
   5.070 [id=33]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins7196962060972152232/plugins/command-launcher.jpi
   5.089 [id=33]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins7196962060972152232/plugins/jdk-tool.jpi
   5.405 [id=28]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins7196962060972152232/plugins/bouncycastle-api.jpi
   5.916 [id=31]	INFO	jenkins.InitReactorRunner$1#onAttained: Listed all plugins
   8.042 [id=30]	INFO	jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
   8.050 [id=32]	INFO	jenkins.InitReactorRunner$1#onAttained: Started all plugins
   8.052 [id=32]	INFO	jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
   8.644 [id=33]	INFO	jenkins.InitReactorRunner$1#onAttained: System config loaded
   8.645 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: System config adapted
   8.645 [id=31]	INFO	jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
   8.646 [id=33]	INFO	jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
   8.886 [id=30]	INFO	jenkins.InitReactorRunner$1#onAttained: Completed initialization
   9.185 [foo #1] Started
   9.236 [foo #1] Running in Durability level: MAX_SURVIVABILITY
   9.996 [foo #1] [Pipeline] Start of Pipeline
  10.197 [foo #1] [Pipeline] echo
  10.248 [foo #1] before
  10.249 [foo #1] [Pipeline] input
  10.350 [foo #1] Input requested
  14.679 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Error in style rule. (Invalid token "--var". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "}", ";", "/", "-", <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <REM>, <EXS>, <CH>, <VW>, <VH>, <VMIN>, <VMAX>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION_CALC>, <FUNCTION_VAR>, <FUNCTION>, <UNKNOWN>, "progid:".)
  14.679 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Ignoring the following declarations in this rule.
  14.711 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  14.711 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Ignoring the whole rule.
  14.713 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  14.713 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Ignoring the whole rule.
  14.714 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  14.715 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Ignoring the whole rule.
  17.534 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Error in style rule. (Invalid token "--var". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "}", ";", "/", "-", <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <REM>, <EXS>, <CH>, <VW>, <VH>, <VMIN>, <VMAX>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION_CALC>, <FUNCTION_VAR>, <FUNCTION>, <UNKNOWN>, "progid:".)
  17.535 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Ignoring the following declarations in this rule.
  17.553 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  17.553 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Ignoring the whole rule.
  17.554 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  17.554 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Ignoring the whole rule.
  17.554 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  17.554 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Ignoring the whole rule.
  18.632 [id=62]	INFO	o.j.p.workflow.job.WorkflowRun#finish: foo #1 completed: ABORTED
  18.648 [foo #1] [Pipeline] End of Pipeline
  18.667 [foo #1] Rejected by alice
  18.667 [foo #1] Finished: ABORTED
  18.804 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Error in style rule. (Invalid token "--var". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "}", ";", "/", "-", <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <REM>, <EXS>, <CH>, <VW>, <VH>, <VMIN>, <VMAX>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION_CALC>, <FUNCTION_VAR>, <FUNCTION>, <UNKNOWN>, "progid:".)
  18.805 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [371:28] Ignoring the following declarations in this rule.
  18.827 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.828 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1550:17] Ignoring the whole rule.
  18.828 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.828 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1569:33] Ignoring the whole rule.
  18.829 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.829 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:41096/jenkins/static/fc52788e/jsbundles/base-styles-v2.css' [1588:49] Ignoring the whole rule.
  19.881 [id=15]	INFO	jenkins.model.Jenkins#cleanUp: Stopping Jenkins
  20.071 [id=15]	INFO	jenkins.model.Jenkins#cleanUp: Jenkins stopped
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 21.478 s <<< FAILURE! - in org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest
[ERROR] org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest.parameter  Time elapsed: 21.416 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: a string containing "after: false"
     but: was "Started
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] echo
before
[Pipeline] input
Input requested
[Pipeline] End of Pipeline
Rejected by alice
Finished: ABORTED
"
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.junit.Assert.assertThat(Assert.java:964)
	at org.junit.Assert.assertThat(Assert.java:930)
	at org.jvnet.hudson.test.JenkinsRule.assertLogContains(JenkinsRule.java:1438)
	at org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest.parameter(InputStepTest.java:149)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:598)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   InputStepTest.parameter:149->Assert.assertThat:930->Assert.assertThat:964 
Expected: a string containing "after: false"
     but: was "Started
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] echo
before
[Pipeline] input
Input requested
[Pipeline] End of Pipeline
Rejected by alice
Finished: ABORTED
"
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
  • AFTER (with patched 2.289):
=== Starting parameter(org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest)
   0.072 [id=15]	INFO	o.jvnet.hudson.test.WarExploder#explode: Exploding /home/lwjs1183/.m2/repository/org/jenkins-ci/main/jenkins-war/2.289-SNAPSHOT/jenkins-war-2.289-SNAPSHOT.war into /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/jenkins-for-test
   2.386 [id=15]	INFO	o.jvnet.hudson.test.JenkinsRule#createWebServer: Running on http://localhost:37084/jenkins/
   4.397 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Started initialization
   4.590 [id=28]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins6674665659598247629/plugins/trilead-api.jpi
   4.613 [id=28]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins6674665659598247629/plugins/sshd.jpi
   4.679 [id=32]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins6674665659598247629/plugins/command-launcher.jpi
   4.694 [id=32]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins6674665659598247629/plugins/jdk-tool.jpi
   5.031 [id=29]	INFO	hudson.PluginManager#considerDetachedPlugin: Loading a detached plugin as a dependency: /home/lwjs1183/git/jenkins-pipeline-input-step-plugin/target/tmp/jenkins6674665659598247629/plugins/bouncycastle-api.jpi
   5.546 [id=33]	INFO	jenkins.InitReactorRunner$1#onAttained: Listed all plugins
   7.538 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
   7.546 [id=27]	INFO	jenkins.InitReactorRunner$1#onAttained: Started all plugins
   7.549 [id=27]	INFO	jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
   9.230 [id=28]	INFO	jenkins.InitReactorRunner$1#onAttained: System config loaded
   9.230 [id=32]	INFO	jenkins.InitReactorRunner$1#onAttained: System config adapted
   9.231 [id=31]	INFO	jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
   9.232 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
   9.465 [id=28]	INFO	jenkins.InitReactorRunner$1#onAttained: Completed initialization
   9.756 [foo #1] Started
   9.807 [foo #1] Running in Durability level: MAX_SURVIVABILITY
  10.412 [foo #1] [Pipeline] Start of Pipeline
  10.613 [foo #1] [Pipeline] echo
  10.614 [foo #1] before
  10.664 [foo #1] [Pipeline] input
  10.765 [foo #1] Input requested
  15.145 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [371:28] Error in style rule. (Invalid token "--var". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "}", ";", "/", "-", <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <REM>, <EXS>, <CH>, <VW>, <VH>, <VMIN>, <VMAX>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION_CALC>, <FUNCTION_VAR>, <FUNCTION>, <UNKNOWN>, "progid:".)
  15.146 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [371:28] Ignoring the following declarations in this rule.
  15.178 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1550:17] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  15.179 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1550:17] Ignoring the whole rule.
  15.180 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1569:33] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  15.180 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1569:33] Ignoring the whole rule.
  15.181 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1588:49] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  15.181 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1588:49] Ignoring the whole rule.
  18.099 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [371:28] Error in style rule. (Invalid token "--var". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "}", ";", "/", "-", <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <REM>, <EXS>, <CH>, <VW>, <VH>, <VMIN>, <VMAX>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <UNICODE_RANGE>, <URI>, <FUNCTION_CALC>, <FUNCTION_VAR>, <FUNCTION>, <UNKNOWN>, "progid:".)
  18.099 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [371:28] Ignoring the following declarations in this rule.
  18.118 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1550:17] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.118 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1550:17] Ignoring the whole rule.
  18.119 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1569:33] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.119 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1569:33] Ignoring the whole rule.
  18.120 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#error: CSS error: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1588:49] Error in class selector. (Invalid token "only". Was expecting: <IDENT>.)
  18.120 [id=15]	WARNING	c.g.h.DefaultCssErrorHandler#warning: CSS warning: 'http://localhost:37084/jenkins/static/b05191ec/jsbundles/base-styles-v2.css' [1588:49] Ignoring the whole rule.
  19.146 [foo #1] Approved by alice
  19.297 [foo #1] [Pipeline] echo
  19.298 [foo #1] after: false
  19.298 [foo #1] [Pipeline] End of Pipeline
  19.306 [id=49]	INFO	o.j.p.workflow.job.WorkflowRun#finish: foo #1 completed: SUCCESS
  19.346 [foo #1] Finished: SUCCESS
  19.402 [id=15]	INFO	jenkins.model.Jenkins#cleanUp: Stopping Jenkins
  19.589 [id=15]	INFO	jenkins.model.Jenkins#cleanUp: Jenkins stopped
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 21.039 s <<< FAILURE! - in org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest
[ERROR] org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest.parameter  Time elapsed: 20.944 s  <<< ERROR!
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for http://localhost:37084/jenkins/job/foo/1/input/Icecream/submit
	at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:732)
	at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2479)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:977)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:1099)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1083)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1014)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:910)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:887)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:864)
	at com.gargoylesoftware.htmlunit.html.HtmlElementUtil.click(HtmlElementUtil.java:56)
	at org.jvnet.hudson.test.JenkinsRule.submit(JenkinsRule.java:1635)
	at org.jenkinsci.plugins.workflow.support.steps.input.InputStepTest.parameter(InputStepTest.java:131)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:598)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   InputStepTest.parameter:131 » FailingHttpStatusCode 404 Not Found for http://l...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

So, it seems that with this patch, the submit button value gets submitted with the input form (the pipeline gets "approved by Alice"), which is a step in the right direction. But then there is this 404 answer, from what I assume is an attempt at submitting the form again :-/
I see no such double-POST thing for a similar test from Firefox 88.

@thomasgl-orange
Copy link
Contributor Author

Added 0eb9318, which seems to avoid the double-POST issue in pipeline-input-step-plugin tests.
No idea what it will breaks elsewhere or in some real browsers, this would clearly require more testing...

@basil
Copy link
Member

basil commented May 12, 2021

It seems that this problem is reproducible within Jenkins core in jenkins.security.RekeySecretAdminMonitorTest#testBasicWorkflow with

diff --git a/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java b/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java
index d8a4555832..4551f8bebb 100644
--- a/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java
+++ b/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java
@@ -112,14 +112,14 @@ public class RekeySecretAdminMonitorTest {
         // one should see the warning. try scheduling it
         assertFalse(monitor.isScanOnBoot());
         HtmlForm form = getRekeyForm(wc);
-        submit(wc, form, "schedule");
+        j.submit(form, "schedule");
         assertTrue(monitor.isScanOnBoot());
         form = getRekeyForm(wc);
         assertTrue(getButton(form, 1).isDisabled());
 
         // run it now
         assertFalse(monitor.getLogFile().exists());
-        submit(wc, form, "background");
+        j.submit(form, "background");
         assertTrue(monitor.getLogFile().exists());
 
         // should be no warning/error now
@@ -134,7 +134,7 @@ public class RekeySecretAdminMonitorTest {
         // dismiss and the message will be gone
         assertTrue(monitor.isEnabled());
         form = getRekeyForm(wc);
-        submit(wc, form, "dismiss");
+        j.submit(form, "dismiss");
         assertFalse(monitor.isEnabled());
         assertThrows(ElementNotFoundException.class, () -> getRekeyForm(wc));
     }
@@ -143,17 +143,6 @@ public class RekeySecretAdminMonitorTest {
         return wc.goTo("manage").getFormByName("rekey");
     }
 
-    private void submit(JenkinsRule.WebClient wc, HtmlForm form, String name) throws IOException {
-        WebRequest request = form.getWebRequest(null);
-        /*
-         * TODO There is a long-undiagnosed issue with the test harness not being compatible with
-         * message.groovy's f.submit. Work around this by matching the behavior of a real browser
-         * (adding the desired button to the request as a parameter).
-         */
-        request.getRequestParameters().add(new NameValuePair(name, ""));
-        wc.getPage(request);
-    }
-
     private HtmlButton getButton(HtmlForm form, int index) {
         // due to the removal of method HtmlElement.getHtmlElementsByTagName
         Stream<HtmlButton> buttonStream = form.getElementsByTagName("button").stream()

With that diff and without the changes in this PR, jenkins.security.RekeySecretAdminMonitorTest#testBasicWorkflow consistently fails.

With that diff and with the changes in this PR, jenkins.security.RekeySecretAdminMonitorTest#testBasicWorkflow consistently passes.

@jtnord jtnord requested a review from daniel-beck May 14, 2021 17:04
@timja
Copy link
Member

timja commented May 17, 2021

@res0nance reported in #5470 (comment) that the related PCT issues picked up in the bom new LTS baseline PR are fixed by this change

@thomasgl-orange
Copy link
Contributor Author

thomasgl-orange commented May 17, 2021

I've added 8edaa20 earlier to limit potential side-effects of 0eb9318: as a precautionary measure, only do the preventDefault trick if submitForm() has called requestSubmit(). This way, nothing is changed for older browsers (those not supporting requestSubmit()).

I think this PR is ready for review. At least it seems to fix something (thanks @res0nance for running the PCT), so I will remove the WIP status.

Regarding the preventDefault trick, an alternative would be to return false from the _onClick handler. I'm not sure what difference it would make, what's "best". Maybe someone more knowledgeable than me on JS matters would have an opinion.

And also regarding this "avoiding double-submit in HtmlUnit" subject, I think there could be an alternative way (without preventDefault or return false). It's a bit convoluted, but deserves to be written down somewhere before I forget... I've spent a bit of time trying to reproduce it in a minimalist HtmlUnit unit test (without YUI or other JS libs), and did not manage at first: I was calling requestSubmit from the onlick handler of a submit button, but I was getting only one submission request. The explanation is that HtmlUnit's WebClient.download(...) skips the second request if it's identical to the first one (same URL / parameters / body):
https://github.com/HtmlUnit/htmlunit/blob/2.49.1/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java#L2400
Here are some tests showing how changing (or not) the form content between the two submits (hence the submit requests themselves) affects the WebClient behavior: thomasgl-orange/htmlunit@b73d2ef

In the case of Jenkins' forms, the POSTed body actually changes when the form is double-submitted. Example of what I was getting after b7d8c12 only (tcpdump during the InputStepTest.parameter() unit test mentioned above):

# first POST:
> POST /jenkins/job/foo/1/input/Icecream/submit HTTP/1.1
Host: localhost:35954
[...]
Content-Length: 186
Content-Type: application/x-www-form-urlencoded

name=chocolate&Jenkins-Crumb=test&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22chocolate%22%2C+%22value%22%3A+false%7D%2C+%22Jenkins-Crumb%22%3A+%22test%22%7D&proceed=Purchase+icecream

< HTTP/1.1 302 Found
[...]

# second POST:
> POST /jenkins/job/foo/1/input/Icecream/submit HTTP/1.1
Host: localhost:35954
[...]
Content-Length: 230
Content-Type: application/x-www-form-urlencoded

name=chocolate&Jenkins-Crumb=test&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22chocolate%22%2C+%22value%22%3A+false%7D%2C+%22Jenkins-Crumb%22%3A+%22test%22%2C+%22proceed%22%3A+%22Purchase+icecream%22%7D&proceed=Purchase+icecream

< HTTP/1.1 404 Not Found
[...]

In the second POST body, the proceed value is included in the json parameter (Structured Form Submission), whereas it's not there in the first one. Here is why:

Hope it makes sense. All that to say that if this JS magic was fixed to include the submit button value in the json serialization as soon as the first submit (if the onsubmit handlers order was somehow reversed), then both requests would be identical, and the second one would be skipped, which would be an alternative to 0eb9318 + 8edaa20.

@thomasgl-orange thomasgl-orange changed the title [WIP][JENKINS-65585] maybe fix requestSubmit() usage [JENKINS-65585] maybe fix requestSubmit() usage May 17, 2021
@thomasgl-orange thomasgl-orange marked this pull request as ready for review May 17, 2021 14:53
@timja timja requested a review from a team May 18, 2021 09:11
@timja
Copy link
Member

timja commented May 18, 2021

Do we want to ship this in weekly?

@jtnord jtnord requested a review from EstherAF May 18, 2021 09:16
@thomasgl-orange
Copy link
Contributor Author

Do we want to ship this in weekly?

If you do, maybe also include @basil's proposed change to RekeySecretAdminMonitorTest, so that there is a test in core which actually benefits from the change. (I can of course merge it in this PR if the commit has been pushed somewhere)

@timja
Copy link
Member

timja commented May 18, 2021

Do we want to ship this in weekly?

If you do, maybe also include @basil's proposed change to RekeySecretAdminMonitorTest, so that there is a test in core which actually benefits from the change. (I can of course merge it in this PR if the commit has been pushed somewhere)

can be added in a followup, weekly ships really soon

@daniel-beck
Copy link
Member

On-holding for:

It gives two unmodified lines, and then a bunch of obfuscated minified code which should obviously be regenerated by a maintainer if this ever gets merged.

@daniel-beck daniel-beck added bug For changelog: Minor bug. Will be listed after features on-hold This pull request depends on another event/release, and it cannot be merged right now regression-fix Pull request that fixes a regression in one of the previous Jenkins releases and removed on-hold This pull request depends on another event/release, and it cannot be merged right now labels May 18, 2021
@daniel-beck
Copy link
Member

Un-on-holding, I get the same minified version of the JS when regenerating it locally from the debug source.

(It's still wrong since we use the debug as reference, which has additional log statements, but that's for another time. It's not a regression in this PR, those statements have been in there since 2014.)

@MarkEWaite
Copy link
Contributor

MarkEWaite commented May 18, 2021

@thomasgl-orange I applied this change to my lts-backport-2.289 branch in commit 175a8407 .

I see in your comment that a further change was needed. I've applied that change in MarkEWaite@7f1e804

I've confirmed that it saves from Firefox 88 and from Chrome just as you reported in #5470 (comment) . I spent an hour clicking various other locations in the Jenkins UI with special focus on configuring jobs. I found no issues with that combination of changes.

@MarkEWaite MarkEWaite requested a review from timja May 18, 2021 23:58
@timja
Copy link
Member

timja commented May 19, 2021

Don’t we need to add the no validate change in this PR?

@timja
Copy link
Member

timja commented May 19, 2021

Do we want to ship this in weekly?

If you do, maybe also include @basil's proposed change to RekeySecretAdminMonitorTest, so that there is a test in core which actually benefits from the change. (I can of course merge it in this PR if the commit has been pushed somewhere)

applied @basil's patch

@thomasgl-orange
Copy link
Contributor Author

I've confirmed that it saves from Firefox 88 and from Chrome just as you reported in #5470 (comment) . I spent an hour clicking various other locations in the Jenkins UI with special focus on configuring jobs. I found no issues with that combination of changes.

Thanks @MarkEWaite for your tests.

Don’t we need to add the no validate change in this PR?

@timja: Yes, this last change was a bit too fresh to add in the PR yesterday, but since there is nothing obviously wrong with it after more testing, I've now included it.

Note: Can I Use data for formNoValidate: https://caniuse.com/mdn-api_htmlbuttonelement_formnovalidate (looks good, supported in IE10+ and in all standard browsers)

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a Javascript programmer, but my interactive testing with Firefox and Chrome found no issue with this. Without this change, I have a matrix job configuration that cannot be saved on either Firefox or Chrome. With this change, the job can be saved.

Thanks very much @thomasgl-orange !

@timja timja changed the title [JENKINS-65585] maybe fix requestSubmit() usage [JENKINS-65585] Fix requestSubmit() usage May 21, 2021
@timja
Copy link
Member

timja commented May 21, 2021

@thomasgl-orange any chance you can add a proposed changelog entry?

@thomasgl-orange
Copy link
Contributor Author

@timja: sure, added a proposed entry at the bottom of the initial PR comment

@timja timja requested a review from a team May 21, 2021 08:42
@timja timja added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 23, 2021
@timja
Copy link
Member

timja commented May 23, 2021

This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@timja timja merged commit 42c5633 into jenkinsci:master May 25, 2021
timja pushed a commit that referenced this pull request Jun 14, 2021
Co-authored-by: Basil Crow <[email protected]>
(cherry picked from commit 42c5633)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback regression-fix Pull request that fixes a regression in one of the previous Jenkins releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants