@@ -97,6 +97,20 @@ func TestSourceGitSSH(t *testing.T) {
9797 checkGitOp (t , ops , & src )
9898 })
9999
100+ t .Run ("with known hosts" , func (t * testing.T ) {
101+ knownHosts := "github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC7"
102+ src := Source {
103+ Git : & SourceGit {
104+ URL : fmt .Sprintf ("user@%s:test.git" , addr ),
105+ Commit : t .Name (),
106+ SSHKnownHosts : knownHosts ,
107+ },
108+ }
109+
110+ ops := getSourceOp (ctx , t , src )
111+ checkGitOp (t , ops , & src )
112+ })
113+
100114}
101115
102116func TestSourceGitHTTP (t * testing.T ) {
@@ -1061,6 +1075,18 @@ func checkGitOp(t *testing.T, ops []*pb.Op, src *Source) {
10611075 }
10621076 assert .Check (t , cmp .Equal (op .Attrs ["git.mountsshsock" ], ssh ), op )
10631077 }
1078+
1079+ // Check known hosts if set
1080+ if src .Git .SSHKnownHosts != "" {
1081+ // BuildKit's KnownSSHHosts option may add formatting like newlines
1082+ actualKnownHosts := op .Attrs ["git.knownsshhosts" ]
1083+ expectedKnownHosts := src .Git .SSHKnownHosts
1084+
1085+ // Remove trailing whitespace for comparison since BuildKit may add formatting
1086+ actualTrimmed := strings .TrimSpace (actualKnownHosts )
1087+ expectedTrimmed := strings .TrimSpace (expectedKnownHosts )
1088+ assert .Check (t , cmp .Equal (actualTrimmed , expectedTrimmed ), "Expected: %q, Got: %q" , expectedKnownHosts , actualKnownHosts )
1089+ }
10641090}
10651091
10661092func checkGitAuth (t * testing.T , m map [string ]* pb.Op , ops []* pb.Op , src * Source , expectedNumSecrets , expectedNumSSH int ) {
0 commit comments