Skip to content
Permalink
Browse files

[FIXED JENKINS-41904] NPE from GitHubSCMSource$DescriptorImpl.doCheck…

…ScanCredentialsId when there is no contextual SCMSourceOwner.
  • Loading branch information...
jglick committed Feb 24, 2017
1 parent 3991b29 commit dc13e7a53b4ff1bda2a1eeed547f510ebfdefb2d
@@ -57,7 +57,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.1.8</version>
<version>2.1.12</version>
</dependency>
<dependency>
<groupId>com.coravy.hudson.plugins.github</groupId>
@@ -35,7 +35,6 @@
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.google.common.hash.Hashing;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
import hudson.Util;
@@ -66,8 +65,6 @@
import org.kohsuke.github.RateLimitHandler;
import org.kohsuke.github.extras.OkHttpConnector;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

/**
* Utilities that could perhaps be moved into {@code github-api}.
*/
@@ -78,7 +75,12 @@ private Connector() {
throw new IllegalAccessError("Utility class");
}

public static ListBoxModel listScanCredentials(SCMSourceOwner context, String apiUri) {
/** Binary compatibility. */
public static ListBoxModel listScanCredentials(@CheckForNull SCMSourceOwner context, String apiUri) {
return listScanCredentials((Item) context, apiUri);
}

public static ListBoxModel listScanCredentials(@CheckForNull Item context, String apiUri) {
return new StandardListBoxModel()
.includeEmptyValue()
.includeMatchingAs(
@@ -92,7 +94,12 @@ public static ListBoxModel listScanCredentials(SCMSourceOwner context, String ap
);
}

public static FormValidation checkScanCredentials(SCMSourceOwner context, String apiUri, String scanCredentialsId) {
/** Binary compatibility. */
public static FormValidation checkScanCredentials(@CheckForNull SCMSourceOwner context, String apiUri, String scanCredentialsId) {
return checkScanCredentials((Item) context, apiUri, scanCredentialsId);
}

public static FormValidation checkScanCredentials(@CheckForNull Item context, String apiUri, String scanCredentialsId) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return FormValidation.ok();
@@ -109,7 +116,8 @@ public static FormValidation checkScanCredentials(SCMSourceOwner context, String
if (!found) {
return FormValidation.error("Credentials not found");
}
if (!(context.hasPermission(Item.CONFIGURE)
if (context != null && !(
context.hasPermission(Item.CONFIGURE)
|| context.hasPermission(Item.BUILD)
|| context.hasPermission(CredentialsProvider.USE_ITEM))) {
return FormValidation.ok("Credentials found");
@@ -138,10 +146,18 @@ public static FormValidation checkScanCredentials(SCMSourceOwner context, String
}
}

/** Binary compatibility. */
@CheckForNull
public static StandardCredentials lookupScanCredentials(@CheckForNull SCMSourceOwner context,
@CheckForNull String apiUri,
@CheckForNull String scanCredentialsId) {
return lookupScanCredentials((Item) context, apiUri, scanCredentialsId);
}

@CheckForNull
public static StandardCredentials lookupScanCredentials(@CheckForNull Item context,
@CheckForNull String apiUri,
@CheckForNull String scanCredentialsId) {
if (Util.fixEmpty(scanCredentialsId) == null) {
return null;
} else {
@@ -159,7 +175,12 @@ public static StandardCredentials lookupScanCredentials(@CheckForNull SCMSourceO
}
}

public static ListBoxModel listCheckoutCredentials(SCMSourceOwner context, String apiUri) {
/** Binary compatibility. */
public static ListBoxModel listCheckoutCredentials(@CheckForNull SCMSourceOwner context, String apiUri) {
return listCheckoutCredentials((Item) context, apiUri);
}

public static ListBoxModel listCheckoutCredentials(@CheckForNull Item context, String apiUri) {
StandardListBoxModel result = new StandardListBoxModel();
result.includeEmptyValue();
result.add("- same as scan credentials -", GitHubSCMSource.DescriptorImpl.SAME);
@@ -233,17 +254,6 @@ private static Proxy getProxy(@Nonnull String host) {
}
}

/**
* @param config url and creds id to be hashed
*
* @return unique id for folder name to create cache inside of base cache dir
*/
private static String hashed(GitHubServerConfig config) {
return Hashing.murmur3_32().newHasher()
.putString(trimToEmpty(config.getApiUrl()))
.putString(trimToEmpty(config.getCredentialsId())).hash().toString();
}

/**
* Fail immediately and throw a customized exception.
*/
@@ -34,6 +34,7 @@
import hudson.Util;
import hudson.console.HyperlinkNote;
import hudson.model.Action;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
@@ -53,14 +54,12 @@
import jenkins.scm.api.SCMNavigatorOwner;
import jenkins.scm.api.SCMSourceCategory;
import jenkins.scm.api.SCMSourceObserver;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.impl.UncategorizedSCMSourceCategory;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.github.GHMyself;
@@ -593,17 +592,17 @@ public SCMNavigator newInstance(String name) {
}

@Restricted(NoExternalUse.class)
public FormValidation doCheckScanCredentialsId(@AncestorInPath SCMSourceOwner context,
public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context,
@QueryParameter String apiUri,
@QueryParameter String scanCredentialsId) {
return Connector.checkScanCredentials(context, apiUri, scanCredentialsId);
}

public ListBoxModel doFillScanCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String apiUri) {
public ListBoxModel doFillScanCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) {
return Connector.listScanCredentials(context, apiUri);
}

public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String apiUri) {
public ListBoxModel doFillCheckoutCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) {
return Connector.listCheckoutCredentials(context, apiUri);
}

@@ -42,12 +42,12 @@
import hudson.init.Initializer;
import hudson.model.Action;
import hudson.model.Actionable;
import hudson.model.Item;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.browser.GitRepositoryBrowser;
import hudson.plugins.git.browser.GithubWeb;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.PreBuildMerge;
@@ -67,15 +67,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLHandshakeException;
import jenkins.management.ConfigureLink;
import jenkins.plugins.git.AbstractGitSCMSource;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadCategory;
@@ -1225,7 +1223,7 @@ public FormValidation doCheckIncludes(@QueryParameter String value) {
}

@Restricted(NoExternalUse.class)
public FormValidation doCheckScanCredentialsId(@AncestorInPath SCMSourceOwner context,
public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context,
@QueryParameter String apiUri,
@QueryParameter String scanCredentialsId) {
return Connector.checkScanCredentials(context, apiUri, scanCredentialsId);
@@ -1289,15 +1287,15 @@ public boolean isApiUriSelectable() {
return !GitHubConfiguration.get().getEndpoints().isEmpty();
}

public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String apiUri) {
public ListBoxModel doFillCheckoutCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) {
return Connector.listCheckoutCredentials(context, apiUri);
}

public ListBoxModel doFillScanCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String apiUri) {
public ListBoxModel doFillScanCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) {
return Connector.listScanCredentials(context, apiUri);
}

public ListBoxModel doFillRepositoryItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String apiUri,
public ListBoxModel doFillRepositoryItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri,
@QueryParameter String scanCredentialsId, @QueryParameter String repoOwner) {
Set<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);

0 comments on commit dc13e7a

Please sign in to comment.
You can’t perform that action at this time.