Skip to content

Commit 3a4021b

Browse files
authored
Run GitClientTest.testSparseCheckoutWithCliGitLFS when credentials available (#1337)
The test fails in nearly 100% of cases when credentials are not provided, even though the repository is a public repository. When credentials are provided, the test only fails in about 20% of the cases. The credentials I use for the test are narrowly scoped to exactly one repository and to only allow access to repository content. Since the repository content is already publicly readable, the credential does not grant any additional permissions. The ci.jenkins.io agents do not have the credential, so they will not run the test. Testing done Confirmed that test fails consistently without credentials. Confirmed that test fails in approximately 20% of cases when I use a range of agents including: * Debian 11 * Debian 12 * Debian Testing * openSUSE 15.6 * Red Hat Enterprise Linux 8 * Rocky Linux 9 * Ubuntu 22 * Ubuntu 24 * Windows
1 parent 10c56e5 commit 3a4021b

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static org.junit.Assert.assertTrue;
2323
import static org.junit.Assert.fail;
2424

25+
import com.cloudbees.plugins.credentials.CredentialsScope;
26+
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
2527
import hudson.EnvVars;
2628
import hudson.FilePath;
2729
import hudson.model.TaskListener;
@@ -1373,18 +1375,23 @@ public void testCheckoutWithCliGitLFS() throws Exception {
13731375
assertFileContent("uuid.txt", "5e7733d8acc94636850cb466aec524e4");
13741376
}
13751377

1378+
private static final File HOME_DIR = new File(System.getProperty("user.home"));
1379+
private static final File SSH_DIR = new File(HOME_DIR, ".ssh");
1380+
private static final Path LFS_TOKEN_PATH = (new File(SSH_DIR, "jenkins-pipeline-utils-lfs-access-token").toPath());
1381+
13761382
@Issue("JENKINS-43427") // Git LFS sparse checkout support
13771383
@Test
13781384
public void testSparseCheckoutWithCliGitLFS() throws Exception {
1379-
String JENKINS_URL = System.getenv("JENKINS_URL") != null ? System.getenv("JENKINS_URL") : "";
1380-
if (JENKINS_URL.contains("ci.jenkins.io")
1381-
|| !gitImplName.equals("git")
1382-
|| !CLI_GIT_HAS_GIT_LFS
1383-
|| isWindows()) {
1384-
/* Test fails sporadically on ci.jenkins.io with GitHub error 'bad credentials' */
1385-
/* Slow test that does not tell us much more on Windows than Linux */
1385+
if (!gitImplName.equals("git") || !LFS_TOKEN_PATH.toFile().exists()) {
1386+
/* Git LFS not implemented in JGitAPIImpl */
1387+
/* Test requires an LFS credential for checkout, otherwise fails with GitHub error 'bad credentials' */
13861388
return;
13871389
}
1390+
String password = Files.readAllLines(LFS_TOKEN_PATH).get(0).trim();
1391+
String username = "MarkEWaite";
1392+
String id = "mwaite-lfs-credential-id";
1393+
String desc = "Mark Waite's LFS credential for a public repository";
1394+
var credential = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, id, desc, username, password);
13881395

13891396
String branch = "tests/largeFileSupport";
13901397

@@ -1418,6 +1425,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
14181425
.checkout()
14191426
.ref(remote + "/" + branch)
14201427
.lfsRemote(remote)
1428+
.lfsCredentials(credential)
14211429
.sparseCheckoutPaths(sparsePaths)
14221430
.execute();
14231431

@@ -1443,6 +1451,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
14431451
.checkout()
14441452
.ref(remote + "/" + branch)
14451453
.lfsRemote(remote)
1454+
.lfsCredentials(credential)
14461455
.sparseCheckoutPaths(sparsePaths)
14471456
.execute();
14481457

@@ -1469,6 +1478,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
14691478
.checkout()
14701479
.ref(remote + "/" + branch)
14711480
.lfsRemote(remote)
1481+
.lfsCredentials(credential)
14721482
.sparseCheckoutPaths(sparsePaths)
14731483
.execute();
14741484

@@ -1494,6 +1504,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
14941504
.checkout()
14951505
.ref(remote + "/" + branch)
14961506
.lfsRemote(remote)
1507+
.lfsCredentials(credential)
14971508
.sparseCheckoutPaths(sparsePaths)
14981509
.execute();
14991510

@@ -1519,6 +1530,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
15191530
.checkout()
15201531
.ref(remote + "/" + branch)
15211532
.lfsRemote(remote)
1533+
.lfsCredentials(credential)
15221534
.sparseCheckoutPaths(sparsePaths)
15231535
.execute();
15241536

@@ -1544,6 +1556,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
15441556
.checkout()
15451557
.ref(remote + "/" + branch)
15461558
.lfsRemote(remote)
1559+
.lfsCredentials(credential)
15471560
.sparseCheckoutPaths(sparsePaths)
15481561
.execute();
15491562

@@ -1569,6 +1582,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
15691582
.checkout()
15701583
.ref(remote + "/" + branch)
15711584
.lfsRemote(remote)
1585+
.lfsCredentials(credential)
15721586
.sparseCheckoutPaths(sparsePaths)
15731587
.execute();
15741588

@@ -1594,6 +1608,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
15941608
.checkout()
15951609
.ref(remote + "/" + branch)
15961610
.lfsRemote(remote)
1611+
.lfsCredentials(credential)
15971612
.sparseCheckoutPaths(sparsePaths)
15981613
.execute();
15991614

@@ -1619,6 +1634,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
16191634
.checkout()
16201635
.ref(remote + "/" + branch)
16211636
.lfsRemote(remote)
1637+
.lfsCredentials(credential)
16221638
.sparseCheckoutPaths(sparsePaths1)
16231639
.execute();
16241640

@@ -1676,6 +1692,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
16761692
.checkout()
16771693
.ref(remote + "/" + branch)
16781694
.lfsRemote(remote)
1695+
.lfsCredentials(credential)
16791696
.sparseCheckoutPaths(sparsePaths)
16801697
.execute();
16811698

@@ -1701,6 +1718,7 @@ public void testSparseCheckoutWithCliGitLFS() throws Exception {
17011718
.checkout()
17021719
.ref(remote + "/" + branch)
17031720
.lfsRemote(remote)
1721+
.lfsCredentials(credential)
17041722
.sparseCheckoutPaths(sparsePaths)
17051723
.execute();
17061724

0 commit comments

Comments
 (0)