Calling CLICommandInvoker.invoke() changes Jenkins authorization as a side effect which means that many operations against Jenkins model failed later.
It is a quite common to prepare data in Jenkins instance, call CLI command and verify the state of Jenkins model later.
How-to reproduce:
JenkinsRule j = new JenkinsRule(); j.createFreeStyleProject("aProject"); j.jenkins.getItem("aProject").getDisplayName() // OK -> 'aProject' CLICommandInvoker command = new CLICommandInvoker(j, "version"); CLICommandInvoker.Result result = command.authorizedTo(Jenkins.READ).invoke(); j.jenkins.getItem("aProject").getDisplayName() // Fail -> NPE
How-to fix:
- in CLICommandInvoker.setAuth() save current SecurityRealm, AuthorizationStrategy and thread's SecurityContext
- in CLICommandInvoker.invoke() after result = new Result(returnCode, out, err); call a new method restoreAuth()
- implement a new method CLICommandInvoker.restoreAuth() where SecurityRealm, AuthorizationStrategy and thread's SecurityContext is set to previously saved values
- is blocking
-
JENKINS-32535 Improve test coverage of CLI commands 'add-job-to-view' and 'remove-job-from-view'
-
- Resolved
-
[JENKINS-32571] Preserve original security settings after calling CLICommandInvoker.invoke()
Summary | Original: CLICommandInvoker.invoke() changes security setting permanently as a side effect | New: CLICommandInvoker.invoke() changes security settings permanently as a side effect |
Summary | Original: CLICommandInvoker.invoke() changes security settings permanently as a side effect | New: Preserve original security settings after calling CLICommandInvoker.invoke() |
Status | Original: Open [ 1 ] | New: In Progress [ 3 ] |
Link |
New:
This issue is blocking |
Labels | New: testing |
Resolution | New: Fixed [ 1 ] | |
Status | Original: In Progress [ 3 ] | New: Resolved [ 5 ] |
Workflow | Original: JNJira [ 168221 ] | New: JNJira + In-Review [ 198377 ] |