SSH creates a fully functional SSH service which you can SSH into for testing purposes.
(t *testing.T)
| 31 | |
| 32 | // SSH creates a fully functional SSH service which you can SSH into for testing purposes. |
| 33 | func SSH(t *testing.T) SSHHelper { |
| 34 | t.Helper() |
| 35 | |
| 36 | username := "ubuntu" |
| 37 | password := "ubuntu" |
| 38 | files := dockerBuildRootFiles(sshBuildRoot, "ssh") |
| 39 | cnt := containerFromBuild( |
| 40 | t, "ssh", files, nil, []string{ |
| 41 | fmt.Sprintf("SSH_USERNAME=%s", username), |
| 42 | fmt.Sprintf("SSH_PASSWORD=%s", password), |
| 43 | }, |
| 44 | map[string]string{ |
| 45 | "22/tcp": "", |
| 46 | }, |
| 47 | ) |
| 48 | |
| 49 | hostKey := cnt.extractFile("/etc/ssh/ssh_host_rsa_key") |
| 50 | signer, err := ssh.ParsePrivateKey(hostKey) |
| 51 | if err != nil { |
| 52 | t.Fatalf("failed to parse SSH host key (%v)", err) |
| 53 | } |
| 54 | |
| 55 | return &sshHelper{ |
| 56 | username: username, |
| 57 | password: password, |
| 58 | hostKey: hostKey, |
| 59 | signer: signer, |
| 60 | fingerprint: ssh.FingerprintSHA256(signer.PublicKey()), |
| 61 | cnt: cnt, |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | type sshHelper struct { |
| 66 | username string |