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-32526] - Handle null @AncestorInPath when selecting Jobs/Dow… #79
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d43c49a
[JENKINS-32526] - Handle null @AncestorInPath when selecting Jobs/Dow…
Dohbedoh 85c8b1a
[JENKINS-32526] - Fixed imports and ordered set, changed attribute cl…
Dohbedoh 65b30d6
[JENKINS-32526] - Fixed workflow compatibility for DownstreamBuilds s…
Dohbedoh bf6f1e1
[JENKINS-32526] - Ancestors null: Fixed autocompletion and the method…
Dohbedoh 44cfb04
[JENKINS-32526] - Ancestors null: Reimplemented getRootProject and s…
Dohbedoh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/hudson/plugins/copyartifact/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,9 @@ | |
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import hudson.plugins.copyartifact.testutils.CopyArtifactUtil; | ||
import jenkins.model.Jenkins; | ||
import hudson.FilePath; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Cause; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.FreeStyleBuild; | ||
|
@@ -44,6 +43,9 @@ | |
import hudson.model.StringParameterValue; | ||
import hudson.model.User; | ||
import hudson.model.Result; | ||
import hudson.plugins.copyartifact.testutils.CopyArtifactUtil; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like wildcard import. (especially for classes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No sorry. That's the IDE that organized import automatically. |
||
import jenkins.model.Jenkins; | ||
import hudson.FilePath; | ||
import hudson.plugins.copyartifact.testutils.FileWriteBuilder; | ||
import hudson.security.Permission; | ||
import hudson.security.AuthorizationMatrixProperty; | ||
|
@@ -546,13 +548,28 @@ public void testCheckUpstreamProjectName() throws Exception { | |
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(project2, "../project1").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(project2, "project3").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(project2, "/folder1/project3").kind); | ||
|
||
//JENKINS-32526: Check that it behaves gracefully for an unknown context | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamProjectName(null, null).kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamProjectName(null, "").kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamProjectName(null, " ").kind); | ||
|
||
//Ancestor null | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "nosuchproject").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "$VAR").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "FOO${VAR}").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "Project\\$").kind); // limitation | ||
//Only relative path from Root works | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "folder1/project2").kind); | ||
|
||
// permission check | ||
Authentication a = Jenkins.getAuthentication(); | ||
try { | ||
SecurityContextHolder.getContext().setAuthentication(User.get("devel").impersonate()); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(project2, "../project1").kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamProjectName(project2, "project3").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "/project1").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamProjectName(null, "project3").kind); | ||
} finally { | ||
SecurityContextHolder.getContext().setAuthentication(a); | ||
} | ||
|
@@ -605,14 +622,77 @@ public void testCheckUpstreamBuildNumber() throws Exception { | |
|
||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamBuildNumber(project1, "project2", "9999").kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamBuildNumber(project1, "project2", "NosuchBuild").kind); | ||
|
||
|
||
//JENKINS-32526: Check that it behaves gracefully for an unknown context | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "", Integer.toString(build1.getNumber())).kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "$VAR", Integer.toString(build1.getNumber())).kind); | ||
|
||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamBuildNumber(null, "project2", null).kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamBuildNumber(null, "project2", "").kind); | ||
assertEquals(FormValidation.Kind.ERROR, d.doCheckUpstreamBuildNumber(null, "project2", " ").kind); | ||
|
||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", "FOO${VAR}").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", "\\${VAR}").kind); // limitation | ||
|
||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", Integer.toString(build1.getNumber())).kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", build1.getId()).kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", build1.getDisplayName()).kind); | ||
|
||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", "9999").kind); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project2", "NosuchBuild").kind); | ||
|
||
// permission check | ||
Authentication a = Jenkins.getAuthentication(); | ||
try { | ||
SecurityContextHolder.getContext().setAuthentication(User.get("devel").impersonate()); | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(project1, "project3", "nosuchbuild").kind); // limitation | ||
assertEquals(FormValidation.Kind.OK, d.doCheckUpstreamBuildNumber(null, "project3", "nosuchbuild").kind); | ||
} finally { | ||
SecurityContextHolder.getContext().setAuthentication(a); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAutoCompleteUpstreamProjectName() throws Exception { | ||
DownstreamBuildSelector.DescriptorImpl d = (DownstreamBuildSelector.DescriptorImpl) j.jenkins.getDescriptorOrDie(DownstreamBuildSelector.class); | ||
|
||
ProjectMatrixAuthorizationStrategy pmas = new ProjectMatrixAuthorizationStrategy(); | ||
pmas.add(Jenkins.READ, "devel"); | ||
|
||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
j.jenkins.setAuthorizationStrategy(pmas); | ||
|
||
// project1 | ||
// project2 cannot read from devel | ||
FreeStyleProject project1 = j.createFreeStyleProject("project1"); | ||
{ | ||
Map<Permission, Set<String>> map = new HashMap<Permission, Set<String>>(); | ||
map.put(Item.READ, Sets.newHashSet("devel")); | ||
project1.addProperty(new AuthorizationMatrixProperty(map)); | ||
} | ||
|
||
FreeStyleProject project2 = j.createFreeStyleProject("project2"); | ||
|
||
//Check Empty strings | ||
testAutoCompleteUpstreamProjectName(new String [] {project1.getName(), project2.getName()}, "", project1, d); | ||
//Check simple matching string | ||
testAutoCompleteUpstreamProjectName(new String [] {project1.getName(), project2.getName()}, "proj", project1, d); | ||
//Check non matching string | ||
testAutoCompleteUpstreamProjectName(new String [] {}, "FOO", project1, d); | ||
//Check matching string | ||
testAutoCompleteUpstreamProjectName(new String [] {project1.getName()}, "project1", project2, d); | ||
} | ||
|
||
private void testAutoCompleteUpstreamProjectName( | ||
String [] expectedValues, | ||
String value, | ||
AbstractProject project, | ||
DownstreamBuildSelector.DescriptorImpl d) { | ||
|
||
Set<String> actualValues = new TreeSet<String>(d.doAutoCompleteUpstreamProjectName(value, project).getValues()); | ||
assertArrayEquals(expectedValues, actualValues.toArray(new String [actualValues.size()])); | ||
//JENKINS-32526: Auto-completion disabled if no context | ||
actualValues = new TreeSet<String>(d.doAutoCompleteUpstreamProjectName(value, null).getValues()); | ||
assertArrayEquals(new String[] {}, actualValues.toArray(new String [actualValues.size()])); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You should skip the validation if
project
isnull
(that is, when configuring a template).