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

Improve unit test framework to execute in near sandboxed jenkins environment #32

Open
sparshev opened this issue Jul 23, 2019 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@sparshev
Copy link
Collaborator

Right now unit tests are executing in a quite relaxed environment, but we need a way to check that the same logic will work in jenkins sandbox (by using the original script-security plugin) and right now it's hard to say for sure.

@sparshev sparshev added enhancement New feature or request help wanted Extra attention is needed labels Jul 23, 2019
@sparshev
Copy link
Collaborator Author

sparshev commented Nov 3, 2019

Ok, the thing is moving slightly - right now I'm going through mocking of CPS Script, hopefully this is possible.

@sparshev
Copy link
Collaborator Author

sparshev commented Nov 6, 2019

Prepared CPS test base #49 and posted a couple of issues to JenkinsPipelineUnit:

Still not used security plugin I think, but CPS is already something.

@sparshev sparshev added this to the v1.0.0 milestone Nov 6, 2019
@sparshev
Copy link
Collaborator Author

sparshev commented Nov 7, 2019

JenkinsPipelineUnit don't allow to execute CPS tests on somehow complex pipelines that using groovy closures methods (.find/.findAll and many others) due to issue (for example [1,2,3].findAll { it > 1 } will return false instead of [2,3]), like the one was fixed here: jenkinsci/workflow-cps-plugin#124

@sparshev
Copy link
Collaborator Author

sparshev commented Mar 4, 2020

I tried a number of ways and seems just one is working well for us:

Running CPS tes base of the JenkinsPipelineUnit

Uses groovy-cps, but without improvements of workflow-cps plugin, so making not much sense.

Running JenkinsRule with intercepting CpsScript

Unfortunately will not work properly, because CpsScript is highly protected: final invokeMethod() and the other functions that could be changed - it requires too much support and not working without changes.

Running JenkinsRule with intercepting groovy-cps Invoker classes (SandboxInvoker, DefaultInvoker)

Working well with minimal changes and there is a minimal risk of some additional changes. Also allow to prepare rules for sandboxed or non-sandboxed scopes and choose the depth of the intercepting:

  • only CpsScript calls - like for JenkinsPipelineUnit
  • all calls in the CPS
  • maybe there is a way to narrow the scope to the loaded shared libraries...

So the last approach looks promising.

@sparshev sparshev removed the help wanted Extra attention is needed label Mar 4, 2020
@sparshev
Copy link
Collaborator Author

sparshev commented Mar 5, 2020

Just completed JenkinsRule unit tests implementation, there is still some issues - but looks like it's working as expected.

@sparshev
Copy link
Collaborator Author

sparshev commented Mar 5, 2020

Asked here to help with some jenkins-related issues here: https://issues.jenkins-ci.org/browse/JENKINS-33925

@sparshev
Copy link
Collaborator Author

sparshev commented Mar 5, 2020

The issue with not proper placing of the Build.fileExists(openshift) could be related to some issues with MPLModule execution. Maybe it's not closing the block properly.

@sparshev
Copy link
Collaborator Author

sparshev commented Mar 5, 2020

Ok, found workaround - just use the current node (if it's BlockStartNode) together with enclosures - otherwise MPLModule for some reason will add extra trace items.

@sparshev
Copy link
Collaborator Author

Davin suggested a couple of other ways to achieve the same result to register the custom interceptor here: cloudbees/groovy-cps#107 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant