2015-04-09 14:58:00 -05:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProvisioner_connInfo(t *testing.T) {
|
|
|
|
r := &terraform.InstanceState{
|
|
|
|
Ephemeral: terraform.EphemeralState{
|
|
|
|
ConnInfo: map[string]string{
|
2015-11-12 14:39:41 -06:00
|
|
|
"type": "ssh",
|
|
|
|
"user": "root",
|
|
|
|
"password": "supersecret",
|
|
|
|
"private_key": "someprivatekeycontents",
|
|
|
|
"host": "127.0.0.1",
|
|
|
|
"port": "22",
|
|
|
|
"timeout": "30s",
|
2015-06-22 11:34:02 -05:00
|
|
|
|
|
|
|
"bastion_host": "127.0.1.1",
|
2015-04-09 14:58:00 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-04-10 13:34:46 -05:00
|
|
|
conf, err := parseConnectionInfo(r)
|
2015-04-09 14:58:00 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.User != "root" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.Password != "supersecret" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
2015-11-12 14:39:41 -06:00
|
|
|
if conf.PrivateKey != "someprivatekeycontents" {
|
2015-04-09 14:58:00 -05:00
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.Host != "127.0.0.1" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.Port != 22 {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.Timeout != "30s" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.ScriptPath != DefaultScriptPath {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
2015-06-22 11:34:02 -05:00
|
|
|
if conf.BastionHost != "127.0.1.1" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.BastionPort != 22 {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.BastionUser != "root" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
if conf.BastionPassword != "supersecret" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
2015-11-12 14:39:41 -06:00
|
|
|
if conf.BastionPrivateKey != "someprivatekeycontents" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-03 17:45:24 -05:00
|
|
|
func TestProvisioner_connInfoIpv6(t *testing.T) {
|
|
|
|
r := &terraform.InstanceState{
|
|
|
|
Ephemeral: terraform.EphemeralState{
|
|
|
|
ConnInfo: map[string]string{
|
|
|
|
"type": "ssh",
|
|
|
|
"user": "root",
|
|
|
|
"password": "supersecret",
|
|
|
|
"private_key": "someprivatekeycontents",
|
|
|
|
"host": "::1",
|
|
|
|
"port": "22",
|
|
|
|
"timeout": "30s",
|
|
|
|
|
|
|
|
"bastion_host": "::1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
conf, err := parseConnectionInfo(r)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Host != "[::1]" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.BastionHost != "[::1]" {
|
|
|
|
t.Fatalf("bad %v", conf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvisioner_connInfoHostname(t *testing.T) {
|
|
|
|
r := &terraform.InstanceState{
|
|
|
|
Ephemeral: terraform.EphemeralState{
|
|
|
|
ConnInfo: map[string]string{
|
|
|
|
"type": "ssh",
|
|
|
|
"user": "root",
|
|
|
|
"password": "supersecret",
|
|
|
|
"private_key": "someprivatekeycontents",
|
|
|
|
"host": "example.com",
|
|
|
|
"port": "22",
|
|
|
|
"timeout": "30s",
|
|
|
|
|
|
|
|
"bastion_host": "example.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
conf, err := parseConnectionInfo(r)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Host != "example.com" {
|
|
|
|
t.Fatalf("bad: %v", conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.BastionHost != "example.com" {
|
|
|
|
t.Fatalf("bad %v", conf)
|
|
|
|
}
|
|
|
|
}
|