@@ -22,7 +22,6 @@ import (
2222
2323 "github.com/go-git/go-git/v5/plumbing/transport"
2424 "github.com/go-git/go-git/v5/plumbing/transport/http"
25- "github.com/go-git/go-git/v5/plumbing/transport/ssh"
2625 . "github.com/onsi/gomega"
2726
2827 "github.com/fluxcd/source-controller/pkg/git"
@@ -72,6 +71,7 @@ func Test_transportAuth(t *testing.T) {
7271 name string
7372 opts * git.AuthOptions
7473 wantFunc func (g * WithT , t transport.AuthMethod , opts * git.AuthOptions )
74+ kexAlgos []string
7575 wantErr error
7676 }{
7777 {
@@ -128,10 +128,10 @@ func Test_transportAuth(t *testing.T) {
128128 Identity : []byte (privateKeyFixture ),
129129 },
130130 wantFunc : func (g * WithT , t transport.AuthMethod , opts * git.AuthOptions ) {
131- tt , ok := t .(* ssh. PublicKeys )
131+ tt , ok := t .(* CustomPublicKeys )
132132 g .Expect (ok ).To (BeTrue ())
133- g .Expect (tt .User ).To (Equal (opts .Username ))
134- g .Expect (tt .Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
133+ g .Expect (tt .pk . User ).To (Equal (opts .Username ))
134+ g .Expect (tt .pk . Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
135135 },
136136 },
137137 {
@@ -143,10 +143,31 @@ func Test_transportAuth(t *testing.T) {
143143 Identity : []byte (privateKeyPassphraseFixture ),
144144 },
145145 wantFunc : func (g * WithT , t transport.AuthMethod , opts * git.AuthOptions ) {
146- tt , ok := t .(* ssh. PublicKeys )
146+ tt , ok := t .(* CustomPublicKeys )
147147 g .Expect (ok ).To (BeTrue ())
148- g .Expect (tt .User ).To (Equal (opts .Username ))
149- g .Expect (tt .Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
148+ g .Expect (tt .pk .User ).To (Equal (opts .Username ))
149+ g .Expect (tt .pk .Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
150+ },
151+ },
152+ {
153+ name : "SSH with custom key exchanges" ,
154+ opts : & git.AuthOptions {
155+ Transport : git .SSH ,
156+ Username : "example" ,
157+ Identity : []byte (privateKeyFixture ),
158+ KnownHosts : []byte (knownHostsFixture ),
159+ },
160+ kexAlgos : []string {"curve25519-sha256" , "diffie-hellman-group-exchange-sha256" },
161+ wantFunc : func (g * WithT , t transport.AuthMethod , opts * git.AuthOptions ) {
162+ tt , ok := t .(* CustomPublicKeys )
163+ g .Expect (ok ).To (BeTrue ())
164+ g .Expect (tt .pk .User ).To (Equal (opts .Username ))
165+ g .Expect (tt .pk .Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
166+ config , err := tt .ClientConfig ()
167+ g .Expect (err ).ToNot (HaveOccurred ())
168+ g .Expect (config .Config .KeyExchanges ).To (Equal (
169+ []string {"curve25519-sha256" , "diffie-hellman-group-exchange-sha256" }),
170+ )
150171 },
151172 },
152173 {
@@ -168,11 +189,11 @@ func Test_transportAuth(t *testing.T) {
168189 KnownHosts : []byte (knownHostsFixture ),
169190 },
170191 wantFunc : func (g * WithT , t transport.AuthMethod , opts * git.AuthOptions ) {
171- tt , ok := t .(* ssh. PublicKeys )
192+ tt , ok := t .(* CustomPublicKeys )
172193 g .Expect (ok ).To (BeTrue ())
173- g .Expect (tt .User ).To (Equal (opts .Username ))
174- g .Expect (tt .Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
175- g .Expect (tt .HostKeyCallback ).ToNot (BeNil ())
194+ g .Expect (tt .pk . User ).To (Equal (opts .Username ))
195+ g .Expect (tt .pk . Signer .PublicKey ().Type ()).To (Equal ("ssh-rsa" ))
196+ g .Expect (tt .pk . HostKeyCallback ).ToNot (BeNil ())
176197 },
177198 },
178199 {
@@ -202,6 +223,10 @@ func Test_transportAuth(t *testing.T) {
202223 t .Run (tt .name , func (t * testing.T ) {
203224 g := NewWithT (t )
204225
226+ if len (tt .kexAlgos ) > 0 {
227+ git .KexAlgos = tt .kexAlgos
228+ }
229+
205230 got , err := transportAuth (tt .opts )
206231 if tt .wantErr != nil {
207232 g .Expect (err ).To (Equal (tt .wantErr ))
0 commit comments