|
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; |
@@ -2935,6 +2936,30 @@ public void testCommitMessageIsPrintedToLogs() throws Exception { |
2935 | 2936 | r.waitForMessage("Commit message: \"test commit\"", run); |
2936 | 2937 | } |
2937 | 2938 |
|
| 2939 | + @Issue("JENKINS-73677") |
| 2940 | + @Test |
| 2941 | + public void testExtensionsDecorateClientAfterSettingCredentials() throws Exception { |
| 2942 | + assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable()); |
| 2943 | + FreeStyleProject project = setupSimpleProject("master"); |
| 2944 | + StandardCredentials extensionCredentials = createCredential(CredentialsScope.GLOBAL, "github"); |
| 2945 | + store.addCredentials(Domain.global(), extensionCredentials); |
| 2946 | + // setup global config |
| 2947 | + List<UserRemoteConfig> remoteConfigs = GitSCM.createRepoList("https://github.com/jenkinsci/git-plugin", null); |
| 2948 | + project.setScm(new GitSCM( |
| 2949 | + remoteConfigs, |
| 2950 | + Collections.singletonList(new BranchSpec("master")), |
| 2951 | + false, |
| 2952 | + null, |
| 2953 | + null, |
| 2954 | + null, |
| 2955 | + List.of(new TestSetCredentialsGitSCMExtension((StandardUsernameCredentials) extensionCredentials)))); |
| 2956 | + sampleRepo.init(); |
| 2957 | + sampleRepo.write("file", "v1"); |
| 2958 | + sampleRepo.git("commit", "--all", "--message=test commit"); |
| 2959 | + Run<?, ?> run = r.buildAndAssertSuccess(project); |
| 2960 | + r.waitForMessage("using GIT_ASKPASS to set credentials " + extensionCredentials.getDescription(), run); |
| 2961 | + } |
| 2962 | + |
2938 | 2963 | private void setupJGit(GitSCM git) { |
2939 | 2964 | git.gitTool="jgit"; |
2940 | 2965 | r.jenkins.getDescriptorByType(GitTool.DescriptorImpl.class).setInstallations(new JGitTool(Collections.emptyList())); |
@@ -2968,4 +2993,19 @@ private boolean isWindows() { |
2968 | 2993 | private StandardCredentials createCredential(CredentialsScope scope, String id) throws FormException { |
2969 | 2994 | return new UsernamePasswordCredentialsImpl(scope, id, "desc: " + id, "username", "password-needs-to-be-14"); |
2970 | 2995 | } |
| 2996 | + |
| 2997 | + public static class TestSetCredentialsGitSCMExtension extends GitSCMExtension { |
| 2998 | + |
| 2999 | + private final StandardUsernameCredentials credentials; |
| 3000 | + |
| 3001 | + public TestSetCredentialsGitSCMExtension(StandardUsernameCredentials credentials) { |
| 3002 | + this.credentials = credentials; |
| 3003 | + } |
| 3004 | + |
| 3005 | + @Override |
| 3006 | + public GitClient decorate(GitSCM scm, GitClient git) throws GitException { |
| 3007 | + git.setCredentials(credentials); |
| 3008 | + return git; |
| 3009 | + } |
| 3010 | + } |
2971 | 3011 | } |
0 commit comments