Skip to content

Commit

Permalink
Merge pull request #507 from jrarmstro/jarmstrong-githubapp-case-inse…
Browse files Browse the repository at this point in the history
…nsitive

[JENKINS-65029] `gitHubApp` owners are case insensitive
  • Loading branch information
jtnord authored Jul 20, 2022
2 parents 0c05abd + 15d932a commit 731f745
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit 731f745

Please sign in to comment.