diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index eede07c0d..22f1b5f10 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -193,11 +193,13 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact func filterLog(s string, u *url.URL) string { password, passwordSet := u.User.Password() - if passwordSet && password != "" { - return strings.Replace(s, password, "", -1) + if !passwordSet || password == "" { + return s } + encodedUserPassword := strings.Split(u.User.String(), ":") + encodedPassword := encodedUserPassword[len(encodedUserPassword)-1] - return s + return strings.Replace(s, encodedPassword, "", -1) } func (p *PostProcessor) BuildArgs(source, ovftool_uri string) ([]string, error) { diff --git a/post-processor/vsphere/post-processor_test.go b/post-processor/vsphere/post-processor_test.go index 8a14357d3..5cb8f707d 100644 --- a/post-processor/vsphere/post-processor_test.go +++ b/post-processor/vsphere/post-processor_test.go @@ -101,3 +101,30 @@ func TestGenerateURI_PasswordEscapes(t *testing.T) { } } } + +func TestFilterLogs(t *testing.T) { + + // Password is encoded, and contains a colon + ovftool_uri := fmt.Sprintf("vi://hostname/Datacenter/host/cluster") + + u, _ := url.Parse(ovftool_uri) + u.User = url.UserPassword("us:ername", "P@ssW:rd") + + logstring := "vi://us%3Aername:P%40ssW%3Ard@hostname/Datacenter/host/cluster" + outstring := filterLog(logstring, u) + expected := "vi://us%3Aername:@hostname/Datacenter/host/cluster" + if outstring != expected { + t.Fatalf("Should have successfully filtered encoded password. Expected: %s; recieved: %s", expected, outstring) + } + + // There is no password + u.User = url.UserPassword("us:ername", "") + + logstring = "vi://us%3Aername:@hostname/Datacenter/host/cluster" + outstring = filterLog(logstring, u) + expected = "vi://us%3Aername:@hostname/Datacenter/host/cluster" + if outstring != expected { + t.Fatalf("Should have ignored password filtering since it was not set. Expected: %s; recieved: %s", expected, outstring) + } + +}