Skip to content

Commit 260a94e

Browse files
committed
validate packer connection type data
1 parent 51b7de3 commit 260a94e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

provisioner/communication.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ func (provisioner *Provisioner) determineCommunication(ui packer.Ui) ([]string,
1717
// declare communication args
1818
var args []string
1919

20-
// determine communication type enum by packer data
21-
connectionType, err := connectionType(provisioner.generatedData["ConnType"].(string)).New()
22-
if err != nil {
23-
// do not log the enum returned error because it is only a symptom of the packer data issue
24-
ui.Error("packer is unable to resolve the communicator connection type")
20+
// determine communication type string by packer data
21+
connectionString, ok := provisioner.generatedData["ConnType"].(string)
22+
if !ok || len(connectionString) == 0 {
23+
ui.Error("packer is unable to determine the communicator connection type from available data")
2524
return nil, errors.New("unknown communicator connection type")
2625
}
26+
// convert to enum
27+
connectionType, err := connectionType(connectionString).New()
28+
if err != nil {
29+
ui.Error("packer is using an unsupported connection type")
30+
return nil, err
31+
}
2732

2833
ui.Sayf("testinfra communicating via %s connection type", connectionType)
2934

provisioner/communication_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,15 @@ func TestProvisionerDetermineCommunication(test *testing.T) {
156156
}
157157

158158
_, err = provisioner.determineCommunication(ui)
159-
if err == nil || err.Error() != "unknown communicator connection type" {
159+
if err == nil || err.Error() != "invalid connection enum" {
160160
test.Error("determineCommunication function did not fail on unsupported connection type")
161161
}
162+
163+
delete(provisioner.generatedData, "ConnType")
164+
_, err = provisioner.determineCommunication(ui)
165+
if err == nil || err.Error() != "unknown communicator connection type" {
166+
test.Error("determineCommunication function did not fail on missing connection type")
167+
}
162168
}
163169

164170
// test provisioner determineUserAddr properly determines user and instance address

0 commit comments

Comments
 (0)