-
Notifications
You must be signed in to change notification settings - Fork 130
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
New Injected Test: Require a Stapler verb annotation on web method looking methods #133
base: master
Are you sure you want to change the base?
Conversation
cb1e719
to
f668b86
Compare
We can split the method into two, annotate one with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is promising. That will cause lots of failures for most of the plugins, as the @GET
is really rarely used. Do you plan to add a blog post explaining the reason of this hardening?
Well, yeah, but that's not exactly straightforward IMO, especially if faces with a few dozen of these in some plugins. The code needs to change nontrivially. We probably need
Yes, plus a better redirect target. It should take a while for this to get picked up by plugins anyway. A potential negative side effect of this would be that we cannot change form validation request methods at will anymore, without breaking lots of plugins. Looking at you, jenkinsci/jenkins@09d6046. |
@@ -65,6 +84,7 @@ public static TestSuite build(Map<String,?> params) throws Exception { | |||
String packaging = StringUtils.defaultIfBlank((String)params.get("packaging"), "hpi"); | |||
if ("hpi".equals(packaging)) { | |||
inJenkins.addTest(new OtherTests("testPluginActive", params)); | |||
inJenkins.addTest(new OtherTests("testStaplerDispatches", params)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather other things did not go into InjectedTest
(and that it would die). The reason being is that skipping part of the tests (rather than all of them) is pretty much impossible as it uses old junit Suites rather than newer test classes, and is hard to debug.
This would be much better going forward in a generate-tests
mojo in maven-hpi-plugin which then also makes it much easier to debug in an IDE. but otherwise 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skipping part of the tests (rather than all of them) is pretty much impossible
Well, you should not be skipping any of them. :-)
I am not sure how creating JUnit 4-style tests would make it easier to ignore some test cases; target/generated-test-sources/whatever/InjectedTest.java
would still not be editable.
Note that there is a reason all the tests go into one suite: so that only one Jenkins startup is needed, to minimize overhead.
At any rate, InjectedTest
is a well-established part of Jenkins plugin development. Proposals to replace its structure should be kept separate. So long as this PR does not introduce a test which is going to fail widely and spuriously (which I have not yet reviewed), it should be fine IMO.
method.setAccessible(true); | ||
return method; | ||
} catch (ClassNotFoundException e) { | ||
LOGGER.warning("This test requires Jenkins 2.154, Jenkins LTS 2.138.4, or newer to run, use e.g. -Djenkins.version=2.138.4"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of assume
from JUnit might be appropriate here for better integration with error reporting.
Needs a merge conflict fix + clarity on TODO items in the PR description |
1dd3f5a
to
3149ab3
Compare
3149ab3
to
1556b4c
Compare
PR build fails because of #167 (comment) |
This would be better put on hold until jenkinsci/jenkins#4623 is merged, or exclude |
Unsure. Would be beneficial, but IMO overall doesn't make a big difference if the docs say:
The advice needs to favor |
Agreed, it is fine so long as the docs guide users to use |
I still need to figure some stuff out. |
Related PR: jenkins-infra/jenkins.io#2291
This addition to InjectedTest will ensure all explicit or implied Stapler web methods declare an HTTP verb that they're to be used with. Similar to
escape-by-default
in Jelly, which is also only enforced by InjectedTests (and in a way the recent behavior reversal since 2.138.2).@RequirePOST
has been around forever, while@POST
and the other "verb" annotations were available since Jenkins 1.651. I think this 3y 3m old release is a more than reasonable baseline (once there's a non-TypedFilter
implementation for Jenkins before 2.138.4).The current releases of matrix-auth would behave as follows with this change:
Unsure whether all the rules are 100% matching what Stapler does, but it should be close enough.
TODO: