From: Shengjing Zhu <zhsj@debian.org>
Date: Sun, 28 Jun 2020 14:23:37 +0800
Subject: build with new winrm

---
 namespaces.go | 24 ++++++++++++++++++++++++
 wsman.go      | 11 +++++------
 wsman_test.go | 19 +++++++++----------
 3 files changed, 38 insertions(+), 16 deletions(-)
 create mode 100644 namespaces.go

diff --git a/namespaces.go b/namespaces.go
new file mode 100644
index 0000000..7816c8b
--- /dev/null
+++ b/namespaces.go
@@ -0,0 +1,24 @@
+package winrmtest
+
+import (
+	"github.com/masterzen/simplexml/dom"
+	"github.com/masterzen/xmlpath"
+)
+
+var (
+	NS_SOAP_ENV    = dom.Namespace{"env", "http://www.w3.org/2003/05/soap-envelope"}
+	NS_ADDRESSING  = dom.Namespace{"a", "http://schemas.xmlsoap.org/ws/2004/08/addressing"}
+	NS_WSMAN_DMTF  = dom.Namespace{"w", "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"}
+	NS_WSMAN_MSFT  = dom.Namespace{"p", "http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd"}
+	NS_WIN_SHELL   = dom.Namespace{"rsp", "http://schemas.microsoft.com/wbem/wsman/1/windows/shell"}
+)
+
+func getAllNamespaces() []xmlpath.Namespace {
+	var ns = []dom.Namespace{NS_WIN_SHELL, NS_ADDRESSING, NS_WSMAN_DMTF, NS_WSMAN_MSFT, NS_SOAP_ENV}
+
+	var xmlpathNs = make([]xmlpath.Namespace, 0, 4)
+	for _, namespace := range ns {
+		xmlpathNs = append(xmlpathNs, xmlpath.Namespace{Prefix: namespace.Prefix, Uri: namespace.Uri})
+	}
+	return xmlpathNs
+}
diff --git a/wsman.go b/wsman.go
index c6d1c24..cba3b23 100644
--- a/wsman.go
+++ b/wsman.go
@@ -8,9 +8,8 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/masterzen/winrm/soap"
+	"github.com/gofrs/uuid"
 	"github.com/masterzen/xmlpath"
-	"github.com/satori/go.uuid"
 )
 
 type wsman struct {
@@ -25,7 +24,7 @@ type command struct {
 }
 
 func (w *wsman) HandleCommand(m MatcherFunc, f CommandFunc) string {
-	id := uuid.NewV4().String()
+	id := uuid.Must(uuid.NewV4()).String()
 	w.commands = append(w.commands, &command{
 		id:      id,
 		matcher: m,
@@ -132,7 +131,7 @@ func (w *wsman) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 
 func readAction(env *xmlpath.Node) string {
 	xpath, err := xmlpath.CompileWithNamespace(
-		"//a:Action", soap.GetAllNamespaces())
+		"//a:Action", getAllNamespaces())
 
 	if err != nil {
 		return ""
@@ -144,7 +143,7 @@ func readAction(env *xmlpath.Node) string {
 
 func readCommand(env *xmlpath.Node) string {
 	xpath, err := xmlpath.CompileWithNamespace(
-		"//rsp:Command", soap.GetAllNamespaces())
+		"//rsp:Command", getAllNamespaces())
 
 	if err != nil {
 		return ""
@@ -159,7 +158,7 @@ func readCommand(env *xmlpath.Node) string {
 
 func readCommandIDFromDesiredStream(env *xmlpath.Node) string {
 	xpath, err := xmlpath.CompileWithNamespace(
-		"//rsp:DesiredStream/@CommandId", soap.GetAllNamespaces())
+		"//rsp:DesiredStream/@CommandId", getAllNamespaces())
 
 	if err != nil {
 		return ""
diff --git a/wsman_test.go b/wsman_test.go
index e9e4999..53e6a70 100644
--- a/wsman_test.go
+++ b/wsman_test.go
@@ -8,9 +8,8 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/masterzen/winrm/soap"
+	"github.com/gofrs/uuid"
 	"github.com/masterzen/xmlpath"
-	"github.com/satori/go.uuid"
 )
 
 func Test_creating_a_shell(t *testing.T) {
@@ -45,7 +44,7 @@ func Test_creating_a_shell(t *testing.T) {
 	}
 
 	xpath, _ := xmlpath.CompileWithNamespace(
-		"//rsp:ShellId", soap.GetAllNamespaces())
+		"//rsp:ShellId", getAllNamespaces())
 
 	if _, found := xpath.String(env); !found {
 		t.Error("Expected a Shell identifier.")
@@ -80,7 +79,7 @@ func Test_executing_a_command(t *testing.T) {
 	}
 
 	xpath, _ := xmlpath.CompileWithNamespace(
-		"//rsp:CommandId", soap.GetAllNamespaces())
+		"//rsp:CommandId", getAllNamespaces())
 
 	result, _ := xpath.String(env)
 	if result != id {
@@ -103,7 +102,7 @@ func Test_executing_a_regex_command(t *testing.T) {
 			<env:Body>
 				<rsp:CommandLine><rsp:Command>"echo %d >> C:\file.cmd"</rsp:Command></rsp:CommandLine>
 			</env:Body>
-		</env:Envelope>`, uuid.NewV4().String())))
+		</env:Envelope>`, uuid.Must(uuid.NewV4()).String())))
 
 	w.ServeHTTP(res, req)
 	if res.Code != http.StatusOK {
@@ -116,7 +115,7 @@ func Test_executing_a_regex_command(t *testing.T) {
 	}
 
 	xpath, _ := xmlpath.CompileWithNamespace(
-		"//rsp:CommandId", soap.GetAllNamespaces())
+		"//rsp:CommandId", getAllNamespaces())
 
 	result, _ := xpath.String(env)
 	if result != id {
@@ -152,7 +151,7 @@ func Test_receiving_command_results(t *testing.T) {
 		t.Error("Couldn't compile the SOAP response.")
 	}
 
-	xpath, _ := xmlpath.CompileWithNamespace("//rsp:ReceiveResponse", soap.GetAllNamespaces())
+	xpath, _ := xmlpath.CompileWithNamespace("//rsp:ReceiveResponse", getAllNamespaces())
 	iter := xpath.Iter(env)
 	if !iter.Next() {
 		t.Error("Expected a ReceiveResponse element.")
@@ -160,7 +159,7 @@ func Test_receiving_command_results(t *testing.T) {
 
 	xresp := iter.Node()
 	xpath, _ = xmlpath.CompileWithNamespace(
-		fmt.Sprintf("rsp:Stream[@CommandId='%s']", id), soap.GetAllNamespaces())
+		fmt.Sprintf("rsp:Stream[@CommandId='%s']", id), getAllNamespaces())
 	iter = xpath.Iter(xresp)
 
 	if !iter.Next() || !nodeHasAttribute(iter.Node(), "Name", "stdout") || iter.Node().String() != "dGFjb3M=" {
@@ -177,13 +176,13 @@ func Test_receiving_command_results(t *testing.T) {
 
 	xpath, _ = xmlpath.CompileWithNamespace(
 		"//rsp:CommandState[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done']",
-		soap.GetAllNamespaces())
+		getAllNamespaces())
 
 	if _, found := xpath.String(env); !found {
 		t.Error("Expected CommandState=\"Done\"")
 	}
 
-	xpath, _ = xmlpath.CompileWithNamespace("//rsp:CommandState/rsp:ExitCode", soap.GetAllNamespaces())
+	xpath, _ = xmlpath.CompileWithNamespace("//rsp:CommandState/rsp:ExitCode", getAllNamespaces())
 	if code, _ := xpath.String(env); code != "0" {
 		t.Errorf("Expected ExitCode=0 but found \"%s\"\n", code)
 	}
