|
5 | 5 | import com.cloudbees.plugins.credentials.CredentialsStore; |
6 | 6 | import com.cloudbees.plugins.credentials.SystemCredentialsProvider; |
7 | 7 | import com.cloudbees.plugins.credentials.common.StandardCredentials; |
| 8 | +import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials; |
8 | 9 | import com.cloudbees.plugins.credentials.domains.Domain; |
9 | 10 | import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; |
10 | 11 | import org.htmlunit.html.HtmlPage; |
@@ -2915,6 +2916,30 @@ public void testCommitMessageIsPrintedToLogs() throws Exception { |
2915 | 2916 | r.waitForMessage("Commit message: \"test commit\"", run); |
2916 | 2917 | } |
2917 | 2918 |
|
| 2919 | + @Issue("JENKINS-73677") |
| 2920 | + @Test |
| 2921 | + public void testExtensionsDecorateClientAfterSettingCredentials() throws Exception { |
| 2922 | + assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable()); |
| 2923 | + FreeStyleProject project = setupSimpleProject("master"); |
| 2924 | + StandardCredentials extensionCredentials = createCredential(CredentialsScope.GLOBAL, "github"); |
| 2925 | + store.addCredentials(Domain.global(), extensionCredentials); |
| 2926 | + // setup global config |
| 2927 | + List<UserRemoteConfig> remoteConfigs = GitSCM.createRepoList("https://github.com/jenkinsci/git-plugin", null); |
| 2928 | + project.setScm(new GitSCM( |
| 2929 | + remoteConfigs, |
| 2930 | + Collections.singletonList(new BranchSpec("master")), |
| 2931 | + false, |
| 2932 | + null, |
| 2933 | + null, |
| 2934 | + null, |
| 2935 | + List.of(new TestSetCredentialsGitSCMExtension((StandardUsernameCredentials) extensionCredentials)))); |
| 2936 | + sampleRepo.init(); |
| 2937 | + sampleRepo.write("file", "v1"); |
| 2938 | + sampleRepo.git("commit", "--all", "--message=test commit"); |
| 2939 | + Run<?, ?> run = r.buildAndAssertSuccess(project); |
| 2940 | + r.waitForMessage("using GIT_ASKPASS to set credentials " + extensionCredentials.getDescription(), run); |
| 2941 | + } |
| 2942 | + |
2918 | 2943 | private void setupJGit(GitSCM git) { |
2919 | 2944 | git.gitTool="jgit"; |
2920 | 2945 | r.jenkins.getDescriptorByType(GitTool.DescriptorImpl.class).setInstallations(new JGitTool(Collections.emptyList())); |
@@ -2948,4 +2973,19 @@ private boolean isWindows() { |
2948 | 2973 | private StandardCredentials createCredential(CredentialsScope scope, String id) { |
2949 | 2974 | return new UsernamePasswordCredentialsImpl(scope, id, "desc: " + id, "username", "password"); |
2950 | 2975 | } |
| 2976 | + |
| 2977 | + public static class TestSetCredentialsGitSCMExtension extends GitSCMExtension { |
| 2978 | + |
| 2979 | + private final StandardUsernameCredentials credentials; |
| 2980 | + |
| 2981 | + public TestSetCredentialsGitSCMExtension(StandardUsernameCredentials credentials) { |
| 2982 | + this.credentials = credentials; |
| 2983 | + } |
| 2984 | + |
| 2985 | + @Override |
| 2986 | + public GitClient decorate(GitSCM scm, GitClient git) throws GitException { |
| 2987 | + git.setCredentials(credentials); |
| 2988 | + return git; |
| 2989 | + } |
| 2990 | + } |
2951 | 2991 | } |
0 commit comments