@@ -220,11 +220,11 @@ func TestSSHFlagHandling(t *testing.T) {
220
220
221
221
expectedSSHConfig := fmt .Sprintf (`Host github.com
222
222
HostName github.com
223
- IdentityFile %s
224
223
Port 22
225
- ` , filepath .Join (os .Getenv ("HOME" ), ".ssh" , "id_foo" ))
226
- if string (b ) != expectedSSHConfig {
227
- t .Errorf ("got: %v, wanted: %v" , string (b ), expectedSSHConfig )
224
+ IdentityFile %s/.ssh/id_foo
225
+ ` , credentials .VolumePath )
226
+ if d := cmp .Diff (expectedSSHConfig , string (b )); d != "" {
227
+ t .Errorf ("ssh_config diff: %s" , d )
228
228
}
229
229
230
230
b , err = ioutil .ReadFile (filepath .Join (credentials .VolumePath , ".ssh" , "known_hosts" ))
@@ -283,8 +283,10 @@ func TestSSHFlagHandlingThrice(t *testing.T) {
283
283
fs := flag .NewFlagSet ("test" , flag .ContinueOnError )
284
284
flags (fs )
285
285
err := fs .Parse ([]string {
286
+ // Two secrets target github.com, and both will end up in the
287
+ // ssh config.
286
288
"-ssh-git=foo=github.com" ,
287
- "-ssh-git=bar=gitlab .com" ,
289
+ "-ssh-git=bar=github .com" ,
288
290
"-ssh-git=baz=gitlab.example.com:2222" ,
289
291
})
290
292
if err != nil {
@@ -303,21 +305,16 @@ func TestSSHFlagHandlingThrice(t *testing.T) {
303
305
304
306
expectedSSHConfig := fmt .Sprintf (`Host github.com
305
307
HostName github.com
306
- IdentityFile %s
307
- Port 22
308
- Host gitlab.com
309
- HostName gitlab.com
310
- IdentityFile %s
311
308
Port 22
309
+ IdentityFile %s/.ssh/id_foo
310
+ IdentityFile %s/.ssh/id_bar
312
311
Host gitlab.example.com
313
312
HostName gitlab.example.com
314
- IdentityFile %s
315
313
Port 2222
316
- ` , filepath .Join (os .Getenv ("HOME" ), ".ssh" , "id_foo" ),
317
- filepath .Join (os .Getenv ("HOME" ), ".ssh" , "id_bar" ),
318
- filepath .Join (os .Getenv ("HOME" ), ".ssh" , "id_baz" ))
319
- if string (b ) != expectedSSHConfig {
320
- t .Errorf ("got: %v, wanted: %v" , string (b ), expectedSSHConfig )
314
+ IdentityFile %s/.ssh/id_baz
315
+ ` , credentials .VolumePath , credentials .VolumePath , credentials .VolumePath )
316
+ if d := cmp .Diff (expectedSSHConfig , string (b )); d != "" {
317
+ t .Errorf ("ssh_config diff: %s" , d )
321
318
}
322
319
323
320
b , err = ioutil .ReadFile (filepath .Join (credentials .VolumePath , ".ssh" , "known_hosts" ))
@@ -327,8 +324,8 @@ Host gitlab.example.com
327
324
expectedSSHKnownHosts := `ssh-rsa aaaa
328
325
ssh-rsa bbbb
329
326
ssh-rsa cccc`
330
- if string (b ) != expectedSSHKnownHosts {
331
- t .Errorf ("got: %v, wanted : %v " , string ( b ), expectedSSHKnownHosts )
327
+ if d := cmp . Diff ( expectedSSHKnownHosts , string (b )); d != "" {
328
+ t .Errorf ("known_hosts diff : %s " , d )
332
329
}
333
330
334
331
b , err = ioutil .ReadFile (filepath .Join (credentials .VolumePath , ".ssh" , "id_foo" ))
@@ -370,31 +367,12 @@ func TestSSHFlagHandlingMissingFiles(t *testing.T) {
370
367
}
371
368
// No ssh-privatekey files yields an error.
372
369
373
- cfg := sshGitConfig {entries : make (map [string ]sshEntry )}
370
+ cfg := sshGitConfig {entries : make (map [string ][] sshEntry )}
374
371
if err := cfg .Set ("not-found=github.com" ); err == nil {
375
372
t .Error ("Set(); got success, wanted error." )
376
373
}
377
374
}
378
375
379
- func TestSSHFlagHandlingURLCollision (t * testing.T ) {
380
- credentials .VolumePath , _ = ioutil .TempDir ("" , "" )
381
- dir := credentials .VolumeName ("foo" )
382
- if err := os .MkdirAll (dir , os .ModePerm ); err != nil {
383
- t .Fatalf ("os.MkdirAll(%s) = %v" , dir , err )
384
- }
385
- if err := ioutil .WriteFile (filepath .Join (dir , corev1 .SSHAuthPrivateKey ), []byte ("bar" ), 0777 ); err != nil {
386
- t .Fatalf ("ioutil.WriteFile(ssh-privatekey) = %v" , err )
387
- }
388
-
389
- cfg := sshGitConfig {entries : make (map [string ]sshEntry )}
390
- if err := cfg .Set ("foo=github.com" ); err != nil {
391
- t .Fatalf ("First Set() = %v" , err )
392
- }
393
- if err := cfg .Set ("bar=github.com" ); err == nil {
394
- t .Error ("Second Set(); got success, wanted error." )
395
- }
396
- }
397
-
398
376
func TestBasicMalformedValues (t * testing.T ) {
399
377
tests := []string {
400
378
"bar=baz=blah" ,
0 commit comments