(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestRunCommandWithFingerprint(t *testing.T) { |
| 53 | // wrong fingerprint |
| 54 | sshConf := &MakeConfig{ |
| 55 | Server: "localhost", |
| 56 | User: "drone-scp", |
| 57 | Port: "22", |
| 58 | KeyPath: "./tests/.ssh/id_rsa", |
| 59 | Fingerprint: "wrong", |
| 60 | } |
| 61 | |
| 62 | outStr, errStr, isTimeout, err := sshConf.Run("whoami", 10) |
| 63 | assert.Equal(t, "", outStr) |
| 64 | assert.Equal(t, "", errStr) |
| 65 | assert.False(t, isTimeout) |
| 66 | assert.Error(t, err) |
| 67 | |
| 68 | hostKey, err := getHostPublicKeyFile("/etc/ssh/ssh_host_rsa_key.pub") |
| 69 | assert.NoError(t, err) |
| 70 | |
| 71 | sshConf = &MakeConfig{ |
| 72 | Server: "localhost", |
| 73 | User: "drone-scp", |
| 74 | Port: "22", |
| 75 | KeyPath: "./tests/.ssh/id_rsa", |
| 76 | Fingerprint: ssh.FingerprintSHA256(hostKey), |
| 77 | } |
| 78 | |
| 79 | outStr, errStr, isTimeout, err = sshConf.Run("whoami") |
| 80 | assert.Equal(t, "drone-scp\n", outStr) |
| 81 | assert.Equal(t, "", errStr) |
| 82 | assert.True(t, isTimeout) |
| 83 | assert.NoError(t, err) |
| 84 | } |
| 85 | |
| 86 | func TestPrivateKeyAndPassword(t *testing.T) { |
| 87 | // provide password and ssh private key |
nothing calls this directly
no test coverage detected