@@ -20,13 +20,19 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
+ "net/url"
23
24
"os"
24
25
"path/filepath"
25
26
"testing"
26
27
"time"
27
28
29
+ "github.com/fluxcd/pkg/gittestserver"
30
+ "github.com/fluxcd/pkg/ssh"
28
31
git2go "github.com/libgit2/git2go/v33"
29
32
. "github.com/onsi/gomega"
33
+ corev1 "k8s.io/api/core/v1"
34
+
35
+ "github.com/fluxcd/source-controller/pkg/git"
30
36
)
31
37
32
38
func TestCheckoutBranch_Checkout (t * testing.T ) {
@@ -444,3 +450,68 @@ func mockSignature(time time.Time) *git2go.Signature {
444
450
When : time ,
445
451
}
446
452
}
453
+
454
+ // This test is specifically to detect regression in libgit2's ED25519 key
455
+ // support for client authentication.
456
+ // Refer: https://github.com/fluxcd/source-controller/issues/399
457
+ func TestCheckout_ED25519 (t * testing.T ) {
458
+ g := NewWithT (t )
459
+ timeout := 5 * time .Second
460
+
461
+ // Create a git test server.
462
+ server , err := gittestserver .NewTempGitServer ()
463
+ g .Expect (err ).ToNot (HaveOccurred ())
464
+ defer os .RemoveAll (server .Root ())
465
+ server .Auth ("test-user" , "test-pswd" )
466
+ server .AutoCreate ()
467
+
468
+ server .KeyDir (filepath .Join (server .Root (), "keys" ))
469
+ g .Expect (server .ListenSSH ()).To (Succeed ())
470
+
471
+ go func () {
472
+ server .StartSSH ()
473
+ }()
474
+ defer server .StopSSH ()
475
+
476
+ repoPath := "test.git"
477
+
478
+ err = server .InitRepo ("testdata/git/repo" , git .DefaultBranch , repoPath )
479
+ g .Expect (err ).NotTo (HaveOccurred ())
480
+
481
+ sshURL := server .SSHAddress ()
482
+ repoURL := sshURL + "/" + repoPath
483
+
484
+ // Fetch host key.
485
+ u , err := url .Parse (sshURL )
486
+ g .Expect (err ).NotTo (HaveOccurred ())
487
+ g .Expect (u .Host ).ToNot (BeEmpty ())
488
+ knownHosts , err := ssh .ScanHostKey (u .Host , timeout )
489
+ g .Expect (err ).ToNot (HaveOccurred ())
490
+
491
+ kp , err := ssh .NewEd25519Generator ().Generate ()
492
+ g .Expect (err ).ToNot (HaveOccurred ())
493
+
494
+ secret := corev1.Secret {
495
+ Data : map [string ][]byte {
496
+ "identity" : kp .PrivateKey ,
497
+ "known_hosts" : knownHosts ,
498
+ },
499
+ }
500
+
501
+ authOpts , err := git .AuthOptionsFromSecret (repoURL , & secret )
502
+ g .Expect (err ).ToNot (HaveOccurred ())
503
+
504
+ // Prepare for checkout.
505
+ branchCheckoutStrat := & CheckoutBranch {Branch : git .DefaultBranch }
506
+ tmpDir , _ := os .MkdirTemp ("" , "test" )
507
+ defer os .RemoveAll (tmpDir )
508
+
509
+ ctx , cancel := context .WithTimeout (context .TODO (), timeout )
510
+ defer cancel ()
511
+
512
+ // Checkout the repo.
513
+ // This should always fail because the generated key above isn't present in
514
+ // the git server.
515
+ _ , err = branchCheckoutStrat .Checkout (ctx , tmpDir , repoURL , authOpts )
516
+ g .Expect (err ).To (BeNil ())
517
+ }
0 commit comments