|
25 | 25 |
|
26 | 26 | package org.jenkinsci.plugins.github_branch_source; |
27 | 27 |
|
| 28 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 29 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 30 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
28 | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
29 | 32 | import static org.hamcrest.Matchers.*; |
30 | 33 | import static org.junit.Assert.assertEquals; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
31 | 35 |
|
32 | 36 | import com.cloudbees.plugins.credentials.Credentials; |
33 | 37 | import com.cloudbees.plugins.credentials.CredentialsScope; |
|
67 | 71 | import org.hamcrest.Matchers; |
68 | 72 | import org.junit.Before; |
69 | 73 | import org.junit.Test; |
| 74 | +import org.jvnet.hudson.test.Issue; |
70 | 75 | import org.jvnet.hudson.test.MockAuthorizationStrategy; |
71 | 76 | import org.jvnet.hudson.test.MockFolder; |
72 | 77 | import org.mockito.Mock; |
@@ -576,6 +581,30 @@ public void doFillScanCredentials() throws Exception { |
576 | 581 | } |
577 | 582 | } |
578 | 583 |
|
| 584 | + @Issue("JENKINS-76235") |
| 585 | + @Test |
| 586 | + public void afterSaveWithGitHubAppOwnerMismatch() { |
| 587 | + // Given GitHub App credentials |
| 588 | + githubApi.stubFor(get(urlEqualTo("/app")) |
| 589 | + .willReturn(aResponse() |
| 590 | + .withHeader("Content-Type", "application/json") |
| 591 | + .withBody("{\"id\":54321,\"name\":\"test-app\"}"))); |
| 592 | + githubApi.stubFor(get(urlEqualTo("/app/installations")) |
| 593 | + .willReturn(aResponse() |
| 594 | + .withHeader("Content-Type", "application/json") |
| 595 | + .withBody("[{\"id\":654321,\"account\":{\"login\":\"corp\"},\"app_id\":54321}]"))); |
| 596 | + GitHubAppCredentials appCredentials = GitHubApp.createCredentials("test-app-creds"); |
| 597 | + appCredentials.setApiUri(githubApi.baseUrl()); |
| 598 | + // And using a owner that doesn't have the application installed |
| 599 | + appCredentials.setOwner("org-or-user-without-app"); |
| 600 | + setCredentials(Collections.singletonList(appCredentials)); |
| 601 | + |
| 602 | + // When creating a SCMNavigator and calling afterSave |
| 603 | + navigator = navigatorForRepoOwner("corp", appCredentials.getId()); |
| 604 | + assertDoesNotThrow(() -> navigator.afterSave(Mockito.mock(SCMNavigatorOwner.class))); |
| 605 | + // Then no exception |
| 606 | + } |
| 607 | + |
579 | 608 | private SCMSourceObserver getObserver(Collection<String> names) { |
580 | 609 | return new SCMSourceObserver() { |
581 | 610 | @NonNull |
|
0 commit comments