Skip to content

Commit 731f745

Browse files
authored
Merge pull request #507 from jrarmstro/jarmstrong-githubapp-case-insensitive
[JENKINS-65029] `gitHubApp` owners are case insensitive
2 parents 0c05abd + 15d932a commit 731f745

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Instant;
2828
import java.util.HashMap;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import java.util.concurrent.TimeUnit;
3233
import java.util.logging.Level;
@@ -231,14 +232,21 @@ static AppInstallationToken generateAppInstallationToken(
231232
if (appInstallations.size() == 1) {
232233
appInstallation = appInstallations.get(0);
233234
} else {
235+
final String ownerOrEmpty = owner != null ? owner : "";
234236
appInstallation =
235237
appInstallations.stream()
236-
.filter(installation -> installation.getAccount().getLogin().equals(owner))
238+
.filter(
239+
installation ->
240+
installation
241+
.getAccount()
242+
.getLogin()
243+
.toLowerCase(Locale.ROOT)
244+
.equals(ownerOrEmpty.toLowerCase(Locale.ROOT)))
237245
.findAny()
238246
.orElseThrow(
239247
() ->
240248
new IllegalArgumentException(
241-
String.format(ERROR_NO_OWNER_MATCHING, appId, owner)));
249+
String.format(ERROR_NO_OWNER_MATCHING, appId, ownerOrEmpty)));
242250
}
243251

244252
GHAppInstallationToken appInstallationToken =

src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static void setUpJenkins() throws Exception {
100100
"sample",
101101
"54321",
102102
Secret.fromString(PKCS8_PRIVATE_KEY));
103-
appCredentials.setOwner("cloudbeers");
103+
appCredentials.setOwner("cloudBeers");
104104
store.addCredentials(Domain.global(), appCredentials);
105105
appCredentialsNoOwner =
106106
new GitHubAppCredentials(
@@ -536,7 +536,7 @@ public void testPassword() throws Exception {
536536
// ok
537537
assertEquals(
538538
e.getMessage(),
539-
"Found multiple installations for GitHub app ID 54321 but none match credential owner \"null\". "
539+
"Found multiple installations for GitHub app ID 54321 but none match credential owner \"\". "
540540
+ "Set the right owner in the credential advanced options");
541541
}
542542

0 commit comments

Comments
 (0)