diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java index 7fadf8f92..d3136c528 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java @@ -27,6 +27,7 @@ import java.time.Instant; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -231,14 +232,21 @@ static AppInstallationToken generateAppInstallationToken( if (appInstallations.size() == 1) { appInstallation = appInstallations.get(0); } else { + final String ownerOrEmpty = owner != null ? owner : ""; appInstallation = appInstallations.stream() - .filter(installation -> installation.getAccount().getLogin().equals(owner)) + .filter( + installation -> + installation + .getAccount() + .getLogin() + .toLowerCase(Locale.ROOT) + .equals(ownerOrEmpty.toLowerCase(Locale.ROOT))) .findAny() .orElseThrow( () -> new IllegalArgumentException( - String.format(ERROR_NO_OWNER_MATCHING, appId, owner))); + String.format(ERROR_NO_OWNER_MATCHING, appId, ownerOrEmpty))); } GHAppInstallationToken appInstallationToken = diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java index 748882c9e..d0b262f84 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java @@ -100,7 +100,7 @@ public static void setUpJenkins() throws Exception { "sample", "54321", Secret.fromString(PKCS8_PRIVATE_KEY)); - appCredentials.setOwner("cloudbeers"); + appCredentials.setOwner("cloudBeers"); store.addCredentials(Domain.global(), appCredentials); appCredentialsNoOwner = new GitHubAppCredentials( @@ -536,7 +536,7 @@ public void testPassword() throws Exception { // ok assertEquals( e.getMessage(), - "Found multiple installations for GitHub app ID 54321 but none match credential owner \"null\". " + "Found multiple installations for GitHub app ID 54321 but none match credential owner \"\". " + "Set the right owner in the credential advanced options"); }