Add 'winrm_use_ntlm' configuration directive for NTLM authentication support

This commit is contained in:
Lee Spottiswood 2017-06-07 12:08:12 +01:00
parent 07c09fee32
commit 8473a1148c
2 changed files with 30 additions and 0 deletions

View File

@ -42,6 +42,7 @@ type Config struct {
WinRMTimeout time.Duration `mapstructure:"winrm_timeout"`
WinRMUseSSL bool `mapstructure:"winrm_use_ssl"`
WinRMInsecure bool `mapstructure:"winrm_insecure"`
WinRMUseNTLM bool `mapstructure:"winrm_use_ntlm"`
WinRMTransportDecorator func() winrm.Transporter
}
@ -187,6 +188,10 @@ func (c *Config) prepareWinRM(ctx *interpolate.Context) []error {
c.WinRMTimeout = 30 * time.Minute
}
if c.WinRMUseNTLM == true {
c.WinRMTransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} }
}
var errs []error
if c.WinRMUser == "" {
errs = append(errs, errors.New("winrm_username must be specified."))

View File

@ -1,9 +1,11 @@
package communicator
import (
"reflect"
"testing"
"github.com/hashicorp/packer/template/interpolate"
"github.com/masterzen/winrm"
)
func testConfig() *Config {
@ -101,6 +103,29 @@ func TestConfig_winrm_port_ssl(t *testing.T) {
}
func TestConfig_winrm_use_ntlm(t *testing.T) {
c := &Config{
Type: "winrm",
WinRMUser: "admin",
WinRMUseNTLM: true,
}
if err := c.Prepare(testContext(t)); len(err) > 0 {
t.Fatalf("bad: %#v", err)
}
if c.WinRMTransportDecorator == nil {
t.Fatalf("WinRMTransportDecorator not set.")
}
expected := &winrm.ClientNTLM{}
actual := c.WinRMTransportDecorator()
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("WinRMTransportDecorator isn't ClientNTLM.")
}
}
func TestConfig_winrm(t *testing.T) {
c := &Config{
Type: "winrm",