From 6fca57c7243e0f5ea804c71e505a9c08c96f50ca Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 11 Oct 2023 16:51:29 -0700 Subject: [PATCH 1/4] feat(amt): adds execute support to remoteaccess --- pkg/amt/remoteaccess/policyappliestomps.go | 80 +++++++++++- .../remoteaccess/policyappliestomps_test.go | 121 +++++++++++------- pkg/amt/remoteaccess/policyrule.go | 83 +++++++++++- pkg/amt/remoteaccess/policyrule_test.go | 63 +++++++-- pkg/amt/remoteaccess/service.go | 88 +++++++++++-- pkg/amt/remoteaccess/service_test.go | 105 +++++++++------ .../remoteaccess/policyappliestomps/get.xml | 47 +++++++ .../amt/remoteaccess/policyrule/get.xml | 29 +++++ .../amt/remoteaccess/service/get.xml | 27 ++++ 9 files changed, 532 insertions(+), 111 deletions(-) create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml diff --git a/pkg/amt/remoteaccess/policyappliestomps.go b/pkg/amt/remoteaccess/policyappliestomps.go index cde2fb0c..271254fe 100644 --- a/pkg/amt/remoteaccess/policyappliestomps.go +++ b/pkg/amt/remoteaccess/policyappliestomps.go @@ -7,13 +7,33 @@ package remoteaccess import ( "encoding/xml" + "encoding/json" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessPolicyAppliesToMPS = "AMT_RemoteAccessPolicyAppliesToMPS" +type ( + Response struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + Body Body `xml:"Body"` + } + Body struct { + XMLName xml.Name `xml:"Body"` + PolicyApplies PolicyApplies `xml:"AMT_RemoteAccessPolicyAppliesToMPS"` + + EnumerateResponse common.EnumerateResponse + } + PolicyApplies struct{ + + } +) type RemoteAccessPolicyAppliesToMPS struct { XMLName xml.Name `xml:"h:AMT_RemoteAccessPolicyAppliesToMPS"` H string `xml:"xmlns:h,attr"` @@ -60,6 +80,22 @@ const ( type PolicyAppliesToMPS struct { base message.Base + client wsman.WSManClient +} + +func (w *Response) JSON() string { + jsonOutput, err := json.Marshal(w.Body) + if err != nil { + return "" + } + return string(jsonOutput) +} + +func NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) PolicyAppliesToMPS { + return PolicyAppliesToMPS{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessPolicyAppliesToMPS, client), + client: client, + } } func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessageCreator) PolicyAppliesToMPS { @@ -68,16 +104,50 @@ func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessage } } + // Get retrieves the representation of the instance -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() string { - return RemoteAccessPolicyAppliesToMPS.base.Get(nil) +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyAppliesToMPS.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessPolicyAppliesToMPS.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return } + // Enumerates the instances of this class -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() string { - return RemoteAccessPolicyAppliesToMPS.base.Enumerate() -} +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyAppliesToMPS.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessPolicyAppliesToMPS.base.Execute(response.Message) + if err != nil { + return + } + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return +} // Pulls instances of this class, following an Enumerate operation func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string { return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext) diff --git a/pkg/amt/remoteaccess/policyappliestomps_test.go b/pkg/amt/remoteaccess/policyappliestomps_test.go index b3c6c3c4..04057c4b 100644 --- a/pkg/amt/remoteaccess/policyappliestomps_test.go +++ b/pkg/amt/remoteaccess/policyappliestomps_test.go @@ -6,12 +6,14 @@ package remoteaccess import ( + "encoding/xml" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -19,8 +21,12 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator) - + // client := wsmantesting.MockClient{ + // PackageUnderTest: "amt/general", + // } + client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + + elementUnderTest := NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator, client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { name string @@ -28,57 +34,84 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { action string body string extraHeader string - responseFunc func() string + responseFunc func() (Response, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Get wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.GET, "", "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessPolicyAppliesToMPS Get wsman message", + "AMT_RemoteAccessPolicyAppliesToMPS", + wsmantesting.GET, + "", + "", + func() (Response, error) { + //client.CurrentMessage = "Get" + return elementUnderTest.Get() + }, + Body{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Enumerate wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, "", elementUnderTest.Enumerate}, + /*{ + "should create a valid AMT_RemoteAccessPolicyAppliesToMPS Enumerate wsman message", + "AMT_RemoteAccessPolicyAppliesToMPS", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + "", + func() (Response, error) { + //client.CurrentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + Body{}, + },*/ //PULLS - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Pull wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Put wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PUT, `testtesttesttesttest1test1testtesttest02`, "", func() string { - rapatmps := RemoteAccessPolicyAppliesToMPS{ - PolicySetAppliesToElement: PolicySetAppliesToElement{ - ManagedElement: models.ManagedElement{ - Caption: "test", - Description: "test", - ElementName: "test", - }, - PolicySet: PolicySet{ - Enabled: 1, - PolicyDecisionStrategy: PolicyDecisionStrategyFirstMatching, - PolicyRoles: []string{"test"}, - Policy: Policy{ - ManagedElement: models.ManagedElement{ - Caption: "test", - Description: "test", - ElementName: "test", - }, - CommonName: "test", - PolicyKeywords: []string{"test"}, - }, - }, - }, - MPSType: BothMPS, - OrderOfAccess: 0, - } + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Pull wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Put wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PUT, `testtesttesttesttest1test1testtesttest02`, "", func() string { + // rapatmps := RemoteAccessPolicyAppliesToMPS{ + // PolicySetAppliesToElement: PolicySetAppliesToElement{ + // ManagedElement: models.ManagedElement{ + // Caption: "test", + // Description: "test", + // ElementName: "test", + // }, + // PolicySet: PolicySet{ + // Enabled: 1, + // PolicyDecisionStrategy: PolicyDecisionStrategyFirstMatching, + // PolicyRoles: []string{"test"}, + // Policy: Policy{ + // ManagedElement: models.ManagedElement{ + // Caption: "test", + // Description: "test", + // ElementName: "test", + // }, + // CommonName: "test", + // PolicyKeywords: []string{"test"}, + // }, + // }, + // }, + // MPSType: BothMPS, + // OrderOfAccess: 0, + // } - return elementUnderTest.Put(&rapatmps) - }}, - //{"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Create wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Delete wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.DELETE, "", "Instance", func() string { - return elementUnderTest.Delete("Instance") - }}, + // return elementUnderTest.Put(&rapatmps) + // }}, + // //{"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Create wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Delete wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.DELETE, "", "Instance", func() string { + // return elementUnderTest.Delete("Instance") + // }}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, test.extraHeader, test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.Body) }) } }) diff --git a/pkg/amt/remoteaccess/policyrule.go b/pkg/amt/remoteaccess/policyrule.go index 0336c758..9efb6e6d 100644 --- a/pkg/amt/remoteaccess/policyrule.go +++ b/pkg/amt/remoteaccess/policyrule.go @@ -6,11 +6,35 @@ package remoteaccess import ( + "encoding/json" + "encoding/xml" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessPolicyRule = "AMT_RemoteAccessPolicyRule" +type ( + ResponseRule struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + BodyRule BodyRule `xml:"BodyRule"` + } + BodyRule struct { + XMLName xml.Name `xml:"BodyRule"` + RemotePolicyRule RemotePolicyRule `xml:"AMT_RemoteAccessPolicyRule"` + + EnumerateResponse common.EnumerateResponse + } + RemotePolicyRule struct { + + } +) + type RemoteAccessPolicyRule struct { Trigger Trigger TunnelLifeTime int @@ -28,6 +52,22 @@ const ( type PolicyRule struct { base message.Base + client wsman.WSManClient +} + +func (w *ResponseRule) JSONRule() string { + jsonOutput, err := json.Marshal(w.BodyRule) + if err != nil { + return "" + } + return string(jsonOutput) +} + +func NewPolicyRuleWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) PolicyRule { + return PolicyRule{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessPolicyRule, client), + client: client, + } } func NewRemoteAccessPolicyRule(wsmanMessageCreator *message.WSManMessageCreator) PolicyRule { @@ -37,15 +77,50 @@ func NewRemoteAccessPolicyRule(wsmanMessageCreator *message.WSManMessageCreator) } // Get retrieves the representation of the instance -func (RemoteAccessPolicyRule PolicyRule) Get() string { - return RemoteAccessPolicyRule.base.Get(nil) +func (RemoteAccessPolicyRule PolicyRule) Get() (response ResponseRule, err error) { + response = ResponseRule{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyRule.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessPolicyRule.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return } + // Enumerates the instances of this class -func (RemoteAccessPolicyRule PolicyRule) Enumerate() string { - return RemoteAccessPolicyRule.base.Enumerate() +func (RemoteAccessPolicyRule PolicyRule) Enumerate() (response ResponseRule, err error) { + response = ResponseRule{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyRule.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessPolicyRule.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } + // Pulls instances of this class, following an Enumerate operation func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string { return RemoteAccessPolicyRule.base.Pull(enumerationContext) diff --git a/pkg/amt/remoteaccess/policyrule_test.go b/pkg/amt/remoteaccess/policyrule_test.go index aa4017bd..01953f3e 100644 --- a/pkg/amt/remoteaccess/policyrule_test.go +++ b/pkg/amt/remoteaccess/policyrule_test.go @@ -6,11 +6,14 @@ package remoteaccess import ( + "encoding/xml" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -18,7 +21,12 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessPolicyRule(wsmanMessageCreator) + // client := wsmantesting.MockClient{ + // PackageUnderTest: "amt/general", + // } + client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + + elementUnderTest := NewPolicyRuleWithClient(wsmanMessageCreator, client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { @@ -27,28 +35,57 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) { action string body string extraHeader string - responseFunc func() string + responseFunc func() (ResponseRule, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessPolicyRule Get wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.GET, "", "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessPolicyRule Get wsman message", + "AMT_RemoteAccessPolicyRule", + wsmantesting.GET, + "", + "", + func() (ResponseRule, error) { + //client.CurrentMessage = "Get" + return elementUnderTest.Get() + }, + BodyRule{ + XMLName: xml.Name{Space: "", Local: ""}, + RemotePolicyRule: RemotePolicyRule{ + + }, + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessPolicyRule Enumerate wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, "", elementUnderTest.Enumerate}, + /*{ + "should create a valid AMT_RemoteAccessPolicyRule Enumerate wsman message", + "AMT_RemoteAccessPolicyRule", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + "", + func() (ResponseRule, error) { + //client.CurrentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + Body{}, + },*/ //PULLS - {"should create a valid AMT_RemoteAccessPolicyRule Pull wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + //{"should create a valid AMT_RemoteAccessPolicyRule Pull wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, //DELETE - {"should create a valid AMT_RemoteAccessPolicyRule Delete wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.DELETE, "", "Instance", func() string { - return elementUnderTest.Delete("Instance") - }}, + //{"should create a valid AMT_RemoteAccessPolicyRule Delete wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.DELETE, "", "Instance", func() string { + //return elementUnderTest.Delete("Instance") + //}}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, test.extraHeader, test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.BodyRule) }) } }) diff --git a/pkg/amt/remoteaccess/service.go b/pkg/amt/remoteaccess/service.go index 563422b4..47dcd240 100644 --- a/pkg/amt/remoteaccess/service.go +++ b/pkg/amt/remoteaccess/service.go @@ -6,16 +6,38 @@ package remoteaccess import ( - "fmt" + //"fmt" + + "encoding/json" + "encoding/xml" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/amt/actions" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessService = "AMT_RemoteAccessService" +type ( + ResponseStomps struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + BodyStomps BodyStomps `xml:"BodyStomps"` + } + BodyStomps struct { + XMLName xml.Name `xml:"BodyStomps"` + RemoteAccess RemoteAccess `xml:"AMT_RemoteAccessService"` + + EnumerateResponse common.EnumerateResponse + } + RemoteAccess struct { + } +) type Service struct { base message.Base + client wsman.WSManClient } type MPServer struct { AccessInfo string @@ -42,6 +64,21 @@ const ( UsernamePasswordAuthentication MPServerAuthMethod = 2 ) +func (w *ResponseStomps) JSONStomps() string { + jsonOutput, err := json.Marshal(w.BodyStomps) + if err != nil { + return "" + } + return string(jsonOutput) +} + +func NewRemoteAccessServiceWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) Service { + return Service{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessService, client), + client: client, + } +} + func NewRemoteAccessService(wsmanMessageCreator *message.WSManMessageCreator) Service { return Service{ base: message.NewBase(wsmanMessageCreator, AMT_RemoteAccessService), @@ -49,20 +86,53 @@ func NewRemoteAccessService(wsmanMessageCreator *message.WSManMessageCreator) Se } // Get retrieves the representation of the instance -func (RemoteAccessService Service) Get() string { - return RemoteAccessService.base.Get(nil) -} +func (RemoteAccessService Service) Get() (response ResponseStomps, err error) { + response = ResponseStomps{ + Message: &wsman.Message{ + XMLInput: RemoteAccessService.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessService.base.Execute(response.Message) + if err != nil { + return + } + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return +} // Enumerates the instances of this class -func (RemoteAccessService Service) Enumerate() string { - return RemoteAccessService.base.Enumerate() +func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err error) { + response = ResponseStomps{ + Message: &wsman.Message{ + XMLInput: RemoteAccessService.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessService.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } + // Pulls instances of this class, following an Enumerate operation func (RemoteAccessService Service) Pull(enumerationContext string) string { return RemoteAccessService.base.Pull(enumerationContext) } -func (r Service) AddMPS(mpServer MPServer) string { +/*func (r Service) AddMPS(mpServer MPServer) string { header := r.base.WSManMessageCreator.CreateHeader(string(actions.AddMps), AMT_RemoteAccessService, nil, "", "") body := fmt.Sprintf(`%s%d%d%d%s%s%s`, r.base.WSManMessageCreator.ResourceURIBase, AMT_RemoteAccessService, mpServer.AccessInfo, mpServer.InfoFormat, mpServer.Port, mpServer.AuthMethod, mpServer.Username, mpServer.Password, mpServer.CommonName) return r.base.WSManMessageCreator.CreateXML(header, body) @@ -78,4 +148,4 @@ func (r Service) AddRemoteAccessPolicyRule(remoteAccessPolicyRule RemoteAccessPo r.base.WSManMessageCreator.ResourceURIBase, "AMT_ManagementPresenceRemoteSAP", selector.Name, selector.Value) return r.base.WSManMessageCreator.CreateXML(header, body) -} +}*/ diff --git a/pkg/amt/remoteaccess/service_test.go b/pkg/amt/remoteaccess/service_test.go index 4c50f70e..4354c2fa 100644 --- a/pkg/amt/remoteaccess/service_test.go +++ b/pkg/amt/remoteaccess/service_test.go @@ -6,13 +6,15 @@ package remoteaccess import ( - "fmt" + //"fmt" + "encoding/xml" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/amt/actions" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -20,56 +22,87 @@ func TestAMT_AlarmClockService(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessService(wsmanMessageCreator) + // client := wsmantesting.MockClient{ + // PackageUnderTest: "amt/general", + // } + client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + elementUnderTest := NewRemoteAccessServiceWithClient(wsmanMessageCreator, client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { name string method string action string body string - responseFunc func() string + responseFunc func() (ResponseStomps, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessService Get wsman message", "AMT_RemoteAccessService", wsmantesting.GET, "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessService Get wsman message", + "AMT_RemoteAccessService", + wsmantesting.GET, + "", + func() (ResponseStomps, error) { + //client.CurrentMessage = "Get" + return elementUnderTest.Get() + }, + BodyStomps{ + XMLName: xml.Name{Space: "", Local: ""}, + RemoteAccess: RemoteAccess{ + + }, + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessService Enumerate wsman message", "AMT_RemoteAccessService", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, elementUnderTest.Enumerate}, + /*{ + "should create a valid AMT_RemoteAccessService Enumerate wsman message", + "AMT_RemoteAccessService", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + func() (ResponseStomps, error) { + //client.CurrentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + BodyStomps{}, + },*/ //PULLS - {"should create a valid AMT_RemoteAccessService Pull wsman message", "AMT_RemoteAccessService", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessService AddMPS wsman message", "AMT_RemoteAccessService", string(actions.AddMps), fmt.Sprintf(`%s%d%d%d%s%s%s`, resourceUriBase, AMT_RemoteAccessService, "AccessInfo", 1, 2, 3, "Username", "Password", "CommonName"), func() string { - mpsServer := MPServer{ - AccessInfo: "AccessInfo", - InfoFormat: 1, - Port: 2, - AuthMethod: 3, - Username: "Username", - Password: "Password", - CommonName: "CommonName", - } - return elementUnderTest.AddMPS(mpsServer) - }}, - {"should create a valid AMT_RemoteAccessPolicyRule wsman message", "AMT_RemoteAccessService", string(actions.AddRemoteAccessPolicyRule), fmt.Sprintf(`%d%d%s
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
%s%strue
`, resourceUriBase, AMT_RemoteAccessService, 2, 0, "0300", "http://intel.com/wbem/wscim/1/amt-schema/1/", "AMT_ManagementPresenceRemoteSAP"), func() string { - remoteAccessPolicyRule := RemoteAccessPolicyRule{ - Trigger: 2, - TunnelLifeTime: 0, - ExtendedData: "0300", - } - selector := message.Selector{ - Name: "myselector", - Value: "true", - } - return elementUnderTest.AddRemoteAccessPolicyRule(remoteAccessPolicyRule, selector) - }}, + // {"should create a valid AMT_RemoteAccessService Pull wsman message", "AMT_RemoteAccessService", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessService AddMPS wsman message", "AMT_RemoteAccessService", string(actions.AddMps), fmt.Sprintf(`%s%d%d%d%s%s%s`, resourceUriBase, AMT_RemoteAccessService, "AccessInfo", 1, 2, 3, "Username", "Password", "CommonName"), func() string { + // mpsServer := MPServer{ + // AccessInfo: "AccessInfo", + // InfoFormat: 1, + // Port: 2, + // AuthMethod: 3, + // Username: "Username", + // Password: "Password", + // CommonName: "CommonName", + // } + // return elementUnderTest.AddMPS(mpsServer) + // }}, + // {"should create a valid AMT_RemoteAccessPolicyRule wsman message", "AMT_RemoteAccessService", string(actions.AddRemoteAccessPolicyRule), fmt.Sprintf(`%d%d%s
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
%s%strue
`, resourceUriBase, AMT_RemoteAccessService, 2, 0, "0300", "http://intel.com/wbem/wscim/1/amt-schema/1/", "AMT_ManagementPresenceRemoteSAP"), func() string { + // remoteAccessPolicyRule := RemoteAccessPolicyRule{ + // Trigger: 2, + // TunnelLifeTime: 0, + // ExtendedData: "0300", + // } + // selector := message.Selector{ + // Name: "myselector", + // Value: "true", + // } + // return elementUnderTest.AddRemoteAccessPolicyRule(remoteAccessPolicyRule, selector) + // }}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.BodyStomps) }) } }) diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml new file mode 100644 index 00000000..c34d3e43 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml @@ -0,0 +1,47 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003A7 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyAppliesToMPS + + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_ManagementPresenceRemoteSAP + + AMT_ManagementPresenceRemoteSAP + Intel(r) AMT:Management Presence Server 0 + CIM_ComputerSystem + Intel(r) AMT + + + + 2 + 0 + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyRule + + AMT_RemoteAccessPolicyRule + Periodic + CIM_ComputerSystem + Intel(r) AMT + + + + + + \ No newline at end of file diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml new file mode 100644 index 00000000..26105f9b --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml @@ -0,0 +1,29 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003B7 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyRule + + + + AMT_RemoteAccessPolicyRule + Inte(r) AMT:Remote Access Policy + AAAAAAAAABk= + Periodic + CIM_ComputerSystem + Intel(r) AMT + 2 + 0 + + + diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml new file mode 100644 index 00000000..80d83f21 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml @@ -0,0 +1,27 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003BC + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessService + + + + AMT_RemoteAccessService + Intel(r) AMT Remote Access Service + Intel(r) AMT Remote Access Service + CIM_ComputerSystem + Intel(r) AMT + + + \ No newline at end of file From 4cd5f6307af3f339ab70ef63aa07ed691391db78 Mon Sep 17 00:00:00 2001 From: Zaid Date: Wed, 11 Oct 2023 16:51:29 -0700 Subject: [PATCH 2/4] feat(amt): adds execute support to remoteaccess --- pkg/amt/remoteaccess/policyappliestomps.go | 83 ++++++++- .../remoteaccess/policyappliestomps_test.go | 167 +++++++++++++----- pkg/amt/remoteaccess/policyrule.go | 90 +++++++++- pkg/amt/remoteaccess/policyrule_test.go | 112 ++++++++++-- pkg/amt/remoteaccess/service.go | 92 +++++++++- pkg/amt/remoteaccess/service_test.go | 152 ++++++++++++---- .../remoteaccess/policyappliestomps/get.xml | 47 +++++ .../amt/remoteaccess/policyrule/enumerate.xml | 22 +++ .../amt/remoteaccess/policyrule/get.xml | 29 +++ .../amt/remoteaccess/service/enumerate.xml | 22 +++ .../amt/remoteaccess/service/get.xml | 27 +++ 11 files changed, 730 insertions(+), 113 deletions(-) create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/policyrule/enumerate.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/service/enumerate.xml create mode 100644 pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml diff --git a/pkg/amt/remoteaccess/policyappliestomps.go b/pkg/amt/remoteaccess/policyappliestomps.go index cde2fb0c..bb280120 100644 --- a/pkg/amt/remoteaccess/policyappliestomps.go +++ b/pkg/amt/remoteaccess/policyappliestomps.go @@ -7,13 +7,36 @@ package remoteaccess import ( "encoding/xml" + "encoding/json" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessPolicyAppliesToMPS = "AMT_RemoteAccessPolicyAppliesToMPS" +type ( + Response struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + Body Body `xml:"Body"` + } + Body struct { + XMLName xml.Name `xml:"Body"` + PolicyApplies PolicyApplies `xml:"AMT_RemoteAccessPolicyAppliesToMPS"` + + EnumerateResponse common.EnumerateResponse + } + PolicyApplies struct{ + CreationClassName string + Name string + SystemCreationClassName string + SystemName string + } +) type RemoteAccessPolicyAppliesToMPS struct { XMLName xml.Name `xml:"h:AMT_RemoteAccessPolicyAppliesToMPS"` H string `xml:"xmlns:h,attr"` @@ -60,6 +83,22 @@ const ( type PolicyAppliesToMPS struct { base message.Base + client wsman.WSManClient +} + +func (w *Response) JSON() string { + jsonOutput, err := json.Marshal(w.Body) + if err != nil { + return "" + } + return string(jsonOutput) +} + +func NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) PolicyAppliesToMPS { + return PolicyAppliesToMPS{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessPolicyAppliesToMPS, client), + client: client, + } } func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessageCreator) PolicyAppliesToMPS { @@ -68,16 +107,50 @@ func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessage } } + // Get retrieves the representation of the instance -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() string { - return RemoteAccessPolicyAppliesToMPS.base.Get(nil) +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyAppliesToMPS.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessPolicyAppliesToMPS.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return } + // Enumerates the instances of this class -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() string { - return RemoteAccessPolicyAppliesToMPS.base.Enumerate() -} +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response Response, err error) { + response = Response{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyAppliesToMPS.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessPolicyAppliesToMPS.base.Execute(response.Message) + if err != nil { + return + } + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return +} // Pulls instances of this class, following an Enumerate operation func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string { return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext) diff --git a/pkg/amt/remoteaccess/policyappliestomps_test.go b/pkg/amt/remoteaccess/policyappliestomps_test.go index b3c6c3c4..4a1f2d1d 100644 --- a/pkg/amt/remoteaccess/policyappliestomps_test.go +++ b/pkg/amt/remoteaccess/policyappliestomps_test.go @@ -6,21 +6,63 @@ package remoteaccess import ( + "encoding/xml" + "fmt" + "io" + "os" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" ) +type MockClientApply struct { +} + +const ( + EnvelopeResponseApply = `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous0` + GetBodyApply = `AMT_AuthorizationServiceIntel(r) AMT Authorization ServiceIntel(r) AMT Alarm Clock ServiceCIM_ComputerSystemManagedSystem` +) + +//var currentMessageApply = "" + +func (c *MockClientApply) Post(msg string) ([]byte, error) { + // read an xml file from disk: + xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyappliestomps/" + strings.ToLower(currentMessage) + ".xml") + if err != nil { + fmt.Println("Error opening file:", err) + return nil, err + } + defer xmlFile.Close() + // read file into string + xmlData, err := io.ReadAll(xmlFile) + if err != nil { + fmt.Println("Error reading file:", err) + return nil, err + } + // strip carriage returns and new line characters + xmlData = []byte(strings.ReplaceAll(string(xmlData), "\r\n", "")) + + // Simulate a successful response for testing. + return []byte(xmlData), nil +} func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator) - + // client := wsmantesting.MockClient{ + // PackageUnderTest: "amt/general", + // } + client := MockClientApply{} + //client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + + elementUnderTest := NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator, &client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { name string @@ -28,57 +70,94 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { action string body string extraHeader string - responseFunc func() string + responseFunc func() (Response, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Get wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.GET, "", "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessPolicyAppliesToMPS Get wsman message", + "AMT_RemoteAccessPolicyAppliesToMPS", + wsmantesting.GET, + "", + "", + func() (Response, error) { + currentMessage = "Get" + return elementUnderTest.Get() + }, + Body{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + PolicyApplies: PolicyApplies{ + CreationClassName: "", + Name: "", + SystemCreationClassName: "", + SystemName: "", + }, + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Enumerate wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, "", elementUnderTest.Enumerate}, - //PULLS - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Pull wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Put wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PUT, `testtesttesttesttest1test1testtesttest02`, "", func() string { - rapatmps := RemoteAccessPolicyAppliesToMPS{ - PolicySetAppliesToElement: PolicySetAppliesToElement{ - ManagedElement: models.ManagedElement{ - Caption: "test", - Description: "test", - ElementName: "test", - }, - PolicySet: PolicySet{ - Enabled: 1, - PolicyDecisionStrategy: PolicyDecisionStrategyFirstMatching, - PolicyRoles: []string{"test"}, - Policy: Policy{ - ManagedElement: models.ManagedElement{ - Caption: "test", - Description: "test", - ElementName: "test", - }, - CommonName: "test", - PolicyKeywords: []string{"test"}, - }, - }, + { + "should create a valid AMT_RemoteAccessPolicyAppliesToMPS Enumerate wsman message", + "AMT_RemoteAccessPolicyAppliesToMPS", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + "", + func() (Response, error) { + currentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + Body{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + EnumerateResponse: common.EnumerateResponse{ + EnumerationContext: "CE000000-0000-0000-0000-000000000000", }, - MPSType: BothMPS, - OrderOfAccess: 0, - } + }, + }, + //PULLS + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Pull wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Put wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PUT, `testtesttesttesttest1test1testtesttest02`, "", func() string { + // rapatmps := RemoteAccessPolicyAppliesToMPS{ + // PolicySetAppliesToElement: PolicySetAppliesToElement{ + // ManagedElement: models.ManagedElement{ + // Caption: "test", + // Description: "test", + // ElementName: "test", + // }, + // PolicySet: PolicySet{ + // Enabled: 1, + // PolicyDecisionStrategy: PolicyDecisionStrategyFirstMatching, + // PolicyRoles: []string{"test"}, + // Policy: Policy{ + // ManagedElement: models.ManagedElement{ + // Caption: "test", + // Description: "test", + // ElementName: "test", + // }, + // CommonName: "test", + // PolicyKeywords: []string{"test"}, + // }, + // }, + // }, + // MPSType: BothMPS, + // OrderOfAccess: 0, + // } - return elementUnderTest.Put(&rapatmps) - }}, - //{"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Create wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Delete wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.DELETE, "", "Instance", func() string { - return elementUnderTest.Delete("Instance") - }}, + // return elementUnderTest.Put(&rapatmps) + // }}, + // //{"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Create wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessPolicyAppliesToMPS Delete wsman message", "AMT_RemoteAccessPolicyAppliesToMPS", wsmantesting.DELETE, "", "Instance", func() string { + // return elementUnderTest.Delete("Instance") + // }}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, test.extraHeader, test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + //println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.Body) }) } }) diff --git a/pkg/amt/remoteaccess/policyrule.go b/pkg/amt/remoteaccess/policyrule.go index 0336c758..6737ab76 100644 --- a/pkg/amt/remoteaccess/policyrule.go +++ b/pkg/amt/remoteaccess/policyrule.go @@ -6,11 +6,42 @@ package remoteaccess import ( + "encoding/json" + "encoding/xml" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessPolicyRule = "AMT_RemoteAccessPolicyRule" +type ( + ResponseRule struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + BodyRule BodyRule `xml:"Body"` + } + BodyRule struct { + XMLName xml.Name `xml:"Body"` + RemotePolicyRule RemotePolicyRule `xml:"AMT_RemoteAccessPolicyRule"` + + EnumerateResponse common.EnumerateResponse + } + RemotePolicyRule struct { + CreationClassName string + ElementName string + ExtendedData string + PolicyRuleName string + SystemCreationClassName string + SystemName string + Trigger int + TunnelLifeTime int + } +) + type RemoteAccessPolicyRule struct { Trigger Trigger TunnelLifeTime int @@ -28,6 +59,22 @@ const ( type PolicyRule struct { base message.Base + clientPolicy wsman.WSManClient +} + +func (w *ResponseRule) JSONRule() string { + jsonOutput, err := json.Marshal(w.BodyRule) + if err != nil { + return "" + } + return string(jsonOutput) +} + +func NewPolicyRuleWithClient(wsmanMessageCreator *message.WSManMessageCreator, clientPolicy wsman.WSManClient) PolicyRule { + return PolicyRule{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessPolicyRule, clientPolicy), + clientPolicy: clientPolicy, + } } func NewRemoteAccessPolicyRule(wsmanMessageCreator *message.WSManMessageCreator) PolicyRule { @@ -37,15 +84,50 @@ func NewRemoteAccessPolicyRule(wsmanMessageCreator *message.WSManMessageCreator) } // Get retrieves the representation of the instance -func (RemoteAccessPolicyRule PolicyRule) Get() string { - return RemoteAccessPolicyRule.base.Get(nil) +func (RemoteAccessPolicyRule PolicyRule) Get() (response ResponseRule, err error) { + response = ResponseRule{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyRule.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessPolicyRule.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return } + // Enumerates the instances of this class -func (RemoteAccessPolicyRule PolicyRule) Enumerate() string { - return RemoteAccessPolicyRule.base.Enumerate() +func (RemoteAccessPolicyRule PolicyRule) Enumerate() (response ResponseRule, err error) { + response = ResponseRule{ + Message: &wsman.Message{ + XMLInput: RemoteAccessPolicyRule.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessPolicyRule.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } + // Pulls instances of this class, following an Enumerate operation func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string { return RemoteAccessPolicyRule.base.Pull(enumerationContext) diff --git a/pkg/amt/remoteaccess/policyrule_test.go b/pkg/amt/remoteaccess/policyrule_test.go index aa4017bd..955947ca 100644 --- a/pkg/amt/remoteaccess/policyrule_test.go +++ b/pkg/amt/remoteaccess/policyrule_test.go @@ -6,19 +6,62 @@ package remoteaccess import ( + "encoding/xml" + "fmt" + "io" + "os" + "strings" "testing" - "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) +type MockClientPolicy struct { +} + +const ( + EnvelopeResponsePolicy = `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous0` + GetBodyPolicy = `AMT_RemoteAccessPolicyRuleIntel(r) AMT Remote Access Policy RuleIntel(r) AMT Remote Access Policy RuleCIM_ComputerSystemManagedSystem` +) + +//var currentMessage = "" + +func (c *MockClientPolicy) Post(msg string) ([]byte, error) { + // read an xml file from disk: + xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyrule/" + strings.ToLower(currentMessage) + ".xml") + if err != nil { + fmt.Println("Error opening file:", err) + return nil, err + } + defer xmlFile.Close() + // read file into string + xmlData, err := io.ReadAll(xmlFile) + if err != nil { + fmt.Println("Error reading file:", err) + return nil, err + } + // strip carriage returns and new line characters + xmlData = []byte(strings.ReplaceAll(string(xmlData), "\r\n", "")) + + // Simulate a successful response for testing. + return []byte(xmlData), nil +} func TestAMT_RemoteAccessPolicyRule(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessPolicyRule(wsmanMessageCreator) + // client := wsmantesting.MockClient{ + // PackageUnderTest: "amt/general", + // } + clientPolicy := MockClientPolicy{} + //client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + + elementUnderTest := NewPolicyRuleWithClient(wsmanMessageCreator, &clientPolicy) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { @@ -27,28 +70,69 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) { action string body string extraHeader string - responseFunc func() string + responseFunc func() (ResponseRule, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessPolicyRule Get wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.GET, "", "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessPolicyRule Get wsman message", + "AMT_RemoteAccessPolicyRule", + wsmantesting.GET, + "", + "", + func() (ResponseRule, error) { + currentMessage = "Get" + return elementUnderTest.Get() + }, + BodyRule{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + RemotePolicyRule: RemotePolicyRule{ + CreationClassName: "AMT_RemoteAccessPolicyRule", + ElementName: "Inte(r) AMT:Remote Access Policy", + ExtendedData: "AAAAAAAAABk=", + PolicyRuleName: "Periodic", + SystemCreationClassName: "CIM_ComputerSystem", + SystemName: "Intel(r) AMT", + Trigger: 2, + TunnelLifeTime: 0, + }, + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessPolicyRule Enumerate wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, "", elementUnderTest.Enumerate}, + { + "should create a valid AMT_RemoteAccessPolicyRule Enumerate wsman message", + "AMT_RemoteAccessPolicyRule", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + "", + func() (ResponseRule, error) { + currentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + BodyRule{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + EnumerateResponse: common.EnumerateResponse{ + EnumerationContext: "D3000000-0000-0000-0000-000000000000", + }, + }, + }, //PULLS - {"should create a valid AMT_RemoteAccessPolicyRule Pull wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + //{"should create a valid AMT_RemoteAccessPolicyRule Pull wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.PULL, wsmantesting.PULL_BODY, "", func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, //DELETE - {"should create a valid AMT_RemoteAccessPolicyRule Delete wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.DELETE, "", "Instance", func() string { - return elementUnderTest.Delete("Instance") - }}, + //{"should create a valid AMT_RemoteAccessPolicyRule Delete wsman message", "AMT_RemoteAccessPolicyRule", wsmantesting.DELETE, "", "Instance", func() string { + //return elementUnderTest.Delete("Instance") + //}}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, test.extraHeader, test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + //println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.BodyRule) }) } }) diff --git a/pkg/amt/remoteaccess/service.go b/pkg/amt/remoteaccess/service.go index 563422b4..96ce5c54 100644 --- a/pkg/amt/remoteaccess/service.go +++ b/pkg/amt/remoteaccess/service.go @@ -6,16 +6,43 @@ package remoteaccess import ( - "fmt" + //"fmt" + + "encoding/json" + "encoding/xml" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/amt/actions" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) const AMT_RemoteAccessService = "AMT_RemoteAccessService" +type ( + ResponseStomps struct { + *wsman.Message + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + BodyStomps BodyStomps `xml:"Body"` + } + BodyStomps struct { + XMLName xml.Name `xml:"Body"` + RemoteAccess RemoteAccess `xml:"AMT_RemoteAccessService"` + + EnumerateResponse common.EnumerateResponse + } + RemoteAccess struct { + CreationClassName string + ElementName string + Name string + SystemCreationClassName string + SystemName string + } +) type Service struct { base message.Base + client wsman.WSManClient } type MPServer struct { AccessInfo string @@ -42,27 +69,74 @@ const ( UsernamePasswordAuthentication MPServerAuthMethod = 2 ) +func (w *ResponseStomps) JSONStomps() string { + jsonOutput, err := json.Marshal(w.BodyStomps) + if err != nil { + return "" + } + return string(jsonOutput) +} + func NewRemoteAccessService(wsmanMessageCreator *message.WSManMessageCreator) Service { return Service{ base: message.NewBase(wsmanMessageCreator, AMT_RemoteAccessService), } } -// Get retrieves the representation of the instance -func (RemoteAccessService Service) Get() string { - return RemoteAccessService.base.Get(nil) +func NewRemoteAccessServiceWithClient(wsmanMessageCreator *message.WSManMessageCreator, client wsman.WSManClient) Service { + return Service{ + base: message.NewBaseWithClient(wsmanMessageCreator, AMT_RemoteAccessService, client), + client: client, + } } +// Get retrieves the representation of the instance +func (RemoteAccessService Service) Get() (response ResponseStomps, err error) { + response = ResponseStomps{ + Message: &wsman.Message{ + XMLInput: RemoteAccessService.base.Get(nil), + }, + } + // send the message to AMT + err = RemoteAccessService.base.Execute(response.Message) + if err != nil { + return + } + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + return +} // Enumerates the instances of this class -func (RemoteAccessService Service) Enumerate() string { - return RemoteAccessService.base.Enumerate() +func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err error) { + response = ResponseStomps{ + Message: &wsman.Message{ + XMLInput: RemoteAccessService.base.Enumerate(), + }, + } + // send the message to AMT + err = RemoteAccessService.base.Execute(response.Message) + if err != nil { + return + } + + // put the xml response into the go struct + err = xml.Unmarshal([]byte(response.XMLOutput), &response) + if err != nil { + return + } + + return } + // Pulls instances of this class, following an Enumerate operation func (RemoteAccessService Service) Pull(enumerationContext string) string { return RemoteAccessService.base.Pull(enumerationContext) } -func (r Service) AddMPS(mpServer MPServer) string { +/*func (r Service) AddMPS(mpServer MPServer) string { header := r.base.WSManMessageCreator.CreateHeader(string(actions.AddMps), AMT_RemoteAccessService, nil, "", "") body := fmt.Sprintf(`%s%d%d%d%s%s%s`, r.base.WSManMessageCreator.ResourceURIBase, AMT_RemoteAccessService, mpServer.AccessInfo, mpServer.InfoFormat, mpServer.Port, mpServer.AuthMethod, mpServer.Username, mpServer.Password, mpServer.CommonName) return r.base.WSManMessageCreator.CreateXML(header, body) @@ -78,4 +152,4 @@ func (r Service) AddRemoteAccessPolicyRule(remoteAccessPolicyRule RemoteAccessPo r.base.WSManMessageCreator.ResourceURIBase, "AMT_ManagementPresenceRemoteSAP", selector.Name, selector.Value) return r.base.WSManMessageCreator.CreateXML(header, body) -} +}*/ diff --git a/pkg/amt/remoteaccess/service_test.go b/pkg/amt/remoteaccess/service_test.go index 4c50f70e..a59d80b4 100644 --- a/pkg/amt/remoteaccess/service_test.go +++ b/pkg/amt/remoteaccess/service_test.go @@ -6,70 +6,148 @@ package remoteaccess import ( + "encoding/xml" "fmt" + "io" + "os" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/amt/actions" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" + //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) -func TestAMT_AlarmClockService(t *testing.T) { + +type MockClient struct { +} + +const ( + EnvelopeResponse = `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous0` + GetBody = `AMT_RemoteAccessServiceIntel(r) AMT Remote Access ServiceIntel(r) AMT Remote Access ServiceCIM_ComputerSystemManagedSystem` +) + +var currentMessage = "" + +func (c *MockClient) Post(msg string) ([]byte, error) { + // read an xml file from disk: + xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/service/" + strings.ToLower(currentMessage) + ".xml") + if err != nil { + fmt.Println("Error opening file:", err) + return nil, err + } + defer xmlFile.Close() + // read file into string + xmlData, err := io.ReadAll(xmlFile) + if err != nil { + fmt.Println("Error reading file:", err) + return nil, err + } + // strip carriage returns and new line characters + xmlData = []byte(strings.ReplaceAll(string(xmlData), "\r\n", "")) + + // Simulate a successful response for testing. + return []byte(xmlData), nil +} + +func TestAMT_RemoteAccessService(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - elementUnderTest := NewRemoteAccessService(wsmanMessageCreator) - + /*client := wsmantesting.MockClient{ + PackageUnderTest: "amt/remoteaccess", + }*/ + client := MockClient{} + //client := wsman.NewServiceWithClient("http://localhost:16992/wsman", "admin", "Intel123!", true) + elementUnderTest := NewRemoteAccessServiceWithClient(wsmanMessageCreator, &client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { name string method string action string body string - responseFunc func() string + responseFunc func() (ResponseStomps, error) + expectedResponse interface{} }{ //GETS - {"should create a valid AMT_RemoteAccessService Get wsman message", "AMT_RemoteAccessService", wsmantesting.GET, "", elementUnderTest.Get}, + { + "should create a valid AMT_RemoteAccessService Get wsman message", + "AMT_RemoteAccessService", + wsmantesting.GET, + "", + func() (ResponseStomps, error) { + currentMessage = "Get" + return elementUnderTest.Get() + }, + BodyStomps{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + RemoteAccess: RemoteAccess{ + CreationClassName: "AMT_RemoteAccessService", + ElementName: "Intel(r) AMT Remote Access Service", + Name: "Intel(r) AMT Remote Access Service", + SystemCreationClassName: "CIM_ComputerSystem", + SystemName: "Intel(r) AMT", + }, + }, + }, //ENUMERATES - {"should create a valid AMT_RemoteAccessService Enumerate wsman message", "AMT_RemoteAccessService", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, elementUnderTest.Enumerate}, + { + "should create a valid AMT_RemoteAccessService Enumerate wsman message", + "AMT_RemoteAccessService", + wsmantesting.ENUMERATE, + wsmantesting.ENUMERATE_BODY, + func() (ResponseStomps, error) { + currentMessage = "Enumerate" + return elementUnderTest.Enumerate() + }, + BodyStomps{ + XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, + EnumerateResponse: common.EnumerateResponse{ + EnumerationContext: "D3000000-0000-0000-0000-000000000000", + }, + }, + }, //PULLS - {"should create a valid AMT_RemoteAccessService Pull wsman message", "AMT_RemoteAccessService", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, - {"should create a valid AMT_RemoteAccessService AddMPS wsman message", "AMT_RemoteAccessService", string(actions.AddMps), fmt.Sprintf(`%s%d%d%d%s%s%s`, resourceUriBase, AMT_RemoteAccessService, "AccessInfo", 1, 2, 3, "Username", "Password", "CommonName"), func() string { - mpsServer := MPServer{ - AccessInfo: "AccessInfo", - InfoFormat: 1, - Port: 2, - AuthMethod: 3, - Username: "Username", - Password: "Password", - CommonName: "CommonName", - } - return elementUnderTest.AddMPS(mpsServer) - }}, - {"should create a valid AMT_RemoteAccessPolicyRule wsman message", "AMT_RemoteAccessService", string(actions.AddRemoteAccessPolicyRule), fmt.Sprintf(`%d%d%s
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
%s%strue
`, resourceUriBase, AMT_RemoteAccessService, 2, 0, "0300", "http://intel.com/wbem/wscim/1/amt-schema/1/", "AMT_ManagementPresenceRemoteSAP"), func() string { - remoteAccessPolicyRule := RemoteAccessPolicyRule{ - Trigger: 2, - TunnelLifeTime: 0, - ExtendedData: "0300", - } - selector := message.Selector{ - Name: "myselector", - Value: "true", - } - return elementUnderTest.AddRemoteAccessPolicyRule(remoteAccessPolicyRule, selector) - }}, + // {"should create a valid AMT_RemoteAccessService Pull wsman message", "AMT_RemoteAccessService", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }}, + // {"should create a valid AMT_RemoteAccessService AddMPS wsman message", "AMT_RemoteAccessService", string(actions.AddMps), fmt.Sprintf(`%s%d%d%d%s%s%s`, resourceUriBase, AMT_RemoteAccessService, "AccessInfo", 1, 2, 3, "Username", "Password", "CommonName"), func() string { + // mpsServer := MPServer{ + // AccessInfo: "AccessInfo", + // InfoFormat: 1, + // Port: 2, + // AuthMethod: 3, + // Username: "Username", + // Password: "Password", + // CommonName: "CommonName", + // } + // return elementUnderTest.AddMPS(mpsServer) + // }}, + // {"should create a valid AMT_RemoteAccessPolicyRule wsman message", "AMT_RemoteAccessService", string(actions.AddRemoteAccessPolicyRule), fmt.Sprintf(`%d%d%s
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
%s%strue
`, resourceUriBase, AMT_RemoteAccessService, 2, 0, "0300", "http://intel.com/wbem/wscim/1/amt-schema/1/", "AMT_ManagementPresenceRemoteSAP"), func() string { + // remoteAccessPolicyRule := RemoteAccessPolicyRule{ + // Trigger: 2, + // TunnelLifeTime: 0, + // ExtendedData: "0300", + // } + // selector := message.Selector{ + // Name: "myselector", + // Value: "true", + // } + // return elementUnderTest.AddRemoteAccessPolicyRule(remoteAccessPolicyRule, selector) + // }}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) + expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ - response := test.responseFunc() - if response != correctResponse { - assert.Equal(t, correctResponse, response) - } + response, err := test.responseFunc() + //println(response.XMLOutput) + assert.NoError(t, err) + assert.Equal(t, expectedXMLInput, response.XMLInput) + assert.Equal(t, test.expectedResponse, response.BodyStomps) }) } }) diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml new file mode 100644 index 00000000..c34d3e43 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/policyappliestomps/get.xml @@ -0,0 +1,47 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003A7 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyAppliesToMPS + + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_ManagementPresenceRemoteSAP + + AMT_ManagementPresenceRemoteSAP + Intel(r) AMT:Management Presence Server 0 + CIM_ComputerSystem + Intel(r) AMT + + + + 2 + 0 + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyRule + + AMT_RemoteAccessPolicyRule + Periodic + CIM_ComputerSystem + Intel(r) AMT + + + + + + \ No newline at end of file diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/enumerate.xml b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/enumerate.xml new file mode 100644 index 00000000..3bbb20f2 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/enumerate.xml @@ -0,0 +1,22 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse + uuid:00000000-8086-8086-8086-000000000322 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyRule + + + + D3000000-0000-0000-0000-000000000000 + + + \ No newline at end of file diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml new file mode 100644 index 00000000..26105f9b --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/policyrule/get.xml @@ -0,0 +1,29 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003B7 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessPolicyRule + + + + AMT_RemoteAccessPolicyRule + Inte(r) AMT:Remote Access Policy + AAAAAAAAABk= + Periodic + CIM_ComputerSystem + Intel(r) AMT + 2 + 0 + + + diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/service/enumerate.xml b/pkg/wsmantesting/responses/amt/remoteaccess/service/enumerate.xml new file mode 100644 index 00000000..8e000fa0 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/service/enumerate.xml @@ -0,0 +1,22 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse + uuid:00000000-8086-8086-8086-000000000322 + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessService + + + + D3000000-0000-0000-0000-000000000000 + + + \ No newline at end of file diff --git a/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml b/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml new file mode 100644 index 00000000..80d83f21 --- /dev/null +++ b/pkg/wsmantesting/responses/amt/remoteaccess/service/get.xml @@ -0,0 +1,27 @@ + + + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + 0 + http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse + uuid:00000000-8086-8086-8086-0000000003BC + http://intel.com/wbem/wscim/1/amt-schema/1/AMT_RemoteAccessService + + + + AMT_RemoteAccessService + Intel(r) AMT Remote Access Service + Intel(r) AMT Remote Access Service + CIM_ComputerSystem + Intel(r) AMT + + + \ No newline at end of file From cf5244358a260cef403a46ea9b8a8ac88b495e22 Mon Sep 17 00:00:00 2001 From: Zaid Date: Mon, 30 Oct 2023 15:38:09 -0700 Subject: [PATCH 3/4] feat(amt): adds execute support for remote --- pkg/amt/remoteaccess/policyappliestomps.go | 60 +++++++++---------- .../remoteaccess/policyappliestomps_test.go | 22 ++----- pkg/amt/remoteaccess/policyrule.go | 29 +++++---- pkg/amt/remoteaccess/policyrule_test.go | 10 ---- pkg/amt/remoteaccess/service.go | 27 ++++----- pkg/amt/remoteaccess/service_test.go | 19 ++---- 6 files changed, 68 insertions(+), 99 deletions(-) diff --git a/pkg/amt/remoteaccess/policyappliestomps.go b/pkg/amt/remoteaccess/policyappliestomps.go index 6a32d32c..e6899f98 100644 --- a/pkg/amt/remoteaccess/policyappliestomps.go +++ b/pkg/amt/remoteaccess/policyappliestomps.go @@ -18,13 +18,13 @@ import ( const AMT_RemoteAccessPolicyAppliesToMPS = "AMT_RemoteAccessPolicyAppliesToMPS" type ( - Response struct { + ResponseApplies struct { *wsman.Message - XMLName xml.Name `xml:"Envelope"` - Header message.Header `xml:"Header"` - Body Body `xml:"Body"` + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + BodyApplies BodyApplies `xml:"Body"` } - Body struct { + BodyApplies struct { XMLName xml.Name `xml:"Body"` PolicyApplies PolicyApplies `xml:"AMT_RemoteAccessPolicyAppliesToMPS"` @@ -86,8 +86,8 @@ type PolicyAppliesToMPS struct { client wsman.WSManClient } -func (w *Response) JSON() string { - jsonOutput, err := json.Marshal(w.Body) +func (w *ResponseApplies) JSON() string { + jsonOutput, err := json.Marshal(w.BodyApplies) if err != nil { return "" } @@ -108,8 +108,8 @@ func NewRemoteAccessPolicyAppliesToMPS(wsmanMessageCreator *message.WSManMessage } // Get retrieves the representation of the instance -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Response, err error) { - response = Response{ +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response ResponseApplies, err error) { + response = ResponseApplies{ Message: &wsman.Message{ XMLInput: RemoteAccessPolicyAppliesToMPS.base.Get(nil), }, @@ -129,8 +129,8 @@ func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Get() (response Respons } // Enumerates the instances of this class -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response Response, err error) { - response = Response{ +func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response ResponseApplies, err error) { + response = ResponseApplies{ Message: &wsman.Message{ XMLInput: RemoteAccessPolicyAppliesToMPS.base.Enumerate(), }, @@ -151,22 +151,22 @@ func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Enumerate() (response R } // Pulls instances of this class, following an Enumerate operation -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string { - return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext) -} - -// Put will change properties of the selected instance -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Put(remoteAccessPolicyAppliesToMPS *RemoteAccessPolicyAppliesToMPS) string { - return RemoteAccessPolicyAppliesToMPS.base.Put(remoteAccessPolicyAppliesToMPS, false, nil) -} - -// Delete removes a the specified instance -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Delete(handle string) string { - selector := message.Selector{Name: "Name", Value: handle} - return RemoteAccessPolicyAppliesToMPS.base.Delete(selector) -} - -// Creates a new instance of this class -func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Create(remoteAccessPolicyAppliesToMPS RemoteAccessPolicyAppliesToMPS) string { - return RemoteAccessPolicyAppliesToMPS.base.Create(remoteAccessPolicyAppliesToMPS, nil) -} +// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Pull(enumerationContext string) string { +// return RemoteAccessPolicyAppliesToMPS.base.Pull(enumerationContext) +// } + +// // Put will change properties of the selected instance +// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Put(remoteAccessPolicyAppliesToMPS *RemoteAccessPolicyAppliesToMPS) string { +// return RemoteAccessPolicyAppliesToMPS.base.Put(remoteAccessPolicyAppliesToMPS, false, nil) +// } + +// // Delete removes a the specified instance +// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Delete(handle string) string { +// selector := message.Selector{Name: "Name", Value: handle} +// return RemoteAccessPolicyAppliesToMPS.base.Delete(selector) +// } + +// // Creates a new instance of this class +// func (RemoteAccessPolicyAppliesToMPS PolicyAppliesToMPS) Create(remoteAccessPolicyAppliesToMPS RemoteAccessPolicyAppliesToMPS) string { +// return RemoteAccessPolicyAppliesToMPS.base.Create(remoteAccessPolicyAppliesToMPS, nil) +// } diff --git a/pkg/amt/remoteaccess/policyappliestomps_test.go b/pkg/amt/remoteaccess/policyappliestomps_test.go index 56f9ade6..98112690 100644 --- a/pkg/amt/remoteaccess/policyappliestomps_test.go +++ b/pkg/amt/remoteaccess/policyappliestomps_test.go @@ -16,8 +16,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -30,8 +28,6 @@ const ( GetBodyApply = `AMT_AuthorizationServiceIntel(r) AMT Authorization ServiceIntel(r) AMT Alarm Clock ServiceCIM_ComputerSystemManagedSystem` ) -//var currentMessageApply = "" - func (c *MockClientApply) Post(msg string) ([]byte, error) { // read an xml file from disk: xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyappliestomps/" + strings.ToLower(currentMessage) + ".xml") @@ -56,12 +52,7 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - // client := wsmantesting.MockClient{ - // PackageUnderTest: "amt/general", - // } client := MockClientApply{} - //client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) - elementUnderTest := NewRemoteAccessPolicyAppliesToMPSWithClient(wsmanMessageCreator, &client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { @@ -70,7 +61,7 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { action string body string extraHeader string - responseFunc func() (Response, error) + responseFunc func() (ResponseApplies, error) expectedResponse interface{} }{ //GETS @@ -80,11 +71,11 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { wsmantesting.GET, "", "", - func() (Response, error) { + func() (ResponseApplies, error) { currentMessage = "Get" return elementUnderTest.Get() }, - Body{ + BodyApplies{ XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, PolicyApplies: PolicyApplies{ CreationClassName: "", @@ -101,11 +92,11 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, "", - func() (Response, error) { + func() (ResponseApplies, error) { currentMessage = "Enumerate" return elementUnderTest.Enumerate() }, - Body{ + BodyApplies{ XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, EnumerateResponse: common.EnumerateResponse{ EnumerationContext: "CE000000-0000-0000-0000-000000000000", @@ -154,10 +145,9 @@ func TestAMT_RemoteAccessPolicyAppliesToMPS(t *testing.T) { expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ response, err := test.responseFunc() - //println(response.XMLOutput) assert.NoError(t, err) assert.Equal(t, expectedXMLInput, response.XMLInput) - assert.Equal(t, test.expectedResponse, response.Body) + assert.Equal(t, test.expectedResponse, response.BodyApplies) }) } }) diff --git a/pkg/amt/remoteaccess/policyrule.go b/pkg/amt/remoteaccess/policyrule.go index 0495a98e..ac55d995 100644 --- a/pkg/amt/remoteaccess/policyrule.go +++ b/pkg/amt/remoteaccess/policyrule.go @@ -10,7 +10,6 @@ import ( "encoding/xml" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) @@ -127,17 +126,17 @@ func (RemoteAccessPolicyRule PolicyRule) Enumerate() (response ResponseRule, err } // Pulls instances of this class, following an Enumerate operation -func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string { - return RemoteAccessPolicyRule.base.Pull(enumerationContext) -} - -// Put will change properties of the selected instance -func (RemoteAccessPolicyRule PolicyRule) Put(remoteAccessPolicyRule RemoteAccessPolicyRule) string { - return RemoteAccessPolicyRule.base.Put(remoteAccessPolicyRule, false, nil) -} - -// Delete removes a the specified instance -func (RemoteAccessPolicyRule PolicyRule) Delete(handle string) string { - selector := message.Selector{Name: "PolicyRuleName", Value: handle} - return RemoteAccessPolicyRule.base.Delete(selector) -} +// func (RemoteAccessPolicyRule PolicyRule) Pull(enumerationContext string) string { +// return RemoteAccessPolicyRule.base.Pull(enumerationContext) +// } + +// // Put will change properties of the selected instance +// func (RemoteAccessPolicyRule PolicyRule) Put(remoteAccessPolicyRule RemoteAccessPolicyRule) string { +// return RemoteAccessPolicyRule.base.Put(remoteAccessPolicyRule, false, nil) +// } + +// // Delete removes a the specified instance +// func (RemoteAccessPolicyRule PolicyRule) Delete(handle string) string { +// selector := message.Selector{Name: "PolicyRuleName", Value: handle} +// return RemoteAccessPolicyRule.base.Delete(selector) +// } diff --git a/pkg/amt/remoteaccess/policyrule_test.go b/pkg/amt/remoteaccess/policyrule_test.go index fb88b918..e465d0b3 100644 --- a/pkg/amt/remoteaccess/policyrule_test.go +++ b/pkg/amt/remoteaccess/policyrule_test.go @@ -16,8 +16,6 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -29,8 +27,6 @@ const ( GetBodyPolicy = `AMT_RemoteAccessPolicyRuleIntel(r) AMT Remote Access Policy RuleIntel(r) AMT Remote Access Policy RuleCIM_ComputerSystemManagedSystem` ) -//var currentMessage = "" - func (c *MockClientPolicy) Post(msg string) ([]byte, error) { // read an xml file from disk: xmlFile, err := os.Open("../../wsmantesting/responses/amt/remoteaccess/policyrule/" + strings.ToLower(currentMessage) + ".xml") @@ -55,12 +51,7 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - // client := wsmantesting.MockClient{ - // PackageUnderTest: "amt/general", - // } clientPolicy := MockClientPolicy{} - //client := wsman.NewClient("http://localhost:16992/wsman", "admin", "Intel123!", true) - elementUnderTest := NewPolicyRuleWithClient(wsmanMessageCreator, &clientPolicy) t.Run("amt_* Tests", func(t *testing.T) { @@ -129,7 +120,6 @@ func TestAMT_RemoteAccessPolicyRule(t *testing.T) { expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ response, err := test.responseFunc() - //println(response.XMLOutput) assert.NoError(t, err) assert.Equal(t, expectedXMLInput, response.XMLInput) assert.Equal(t, test.expectedResponse, response.BodyRule) diff --git a/pkg/amt/remoteaccess/service.go b/pkg/amt/remoteaccess/service.go index aad44dd3..78aab944 100644 --- a/pkg/amt/remoteaccess/service.go +++ b/pkg/amt/remoteaccess/service.go @@ -6,13 +6,10 @@ package remoteaccess import ( - //"fmt" - "encoding/json" "encoding/xml" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" ) @@ -20,13 +17,13 @@ import ( const AMT_RemoteAccessService = "AMT_RemoteAccessService" type ( - ResponseStomps struct { + Response struct { *wsman.Message XMLName xml.Name `xml:"Envelope"` Header message.Header `xml:"Header"` - BodyStomps BodyStomps `xml:"Body"` + Body Body `xml:"Body"` } - BodyStomps struct { + Body struct { XMLName xml.Name `xml:"Body"` RemoteAccess RemoteAccess `xml:"AMT_RemoteAccessService"` @@ -69,8 +66,8 @@ const ( UsernamePasswordAuthentication MPServerAuthMethod = 2 ) -func (w *ResponseStomps) JSONStomps() string { - jsonOutput, err := json.Marshal(w.BodyStomps) +func (w *Response) JSONStomps() string { + jsonOutput, err := json.Marshal(w.Body) if err != nil { return "" } @@ -91,8 +88,8 @@ func NewRemoteAccessServiceWithClient(wsmanMessageCreator *message.WSManMessageC } // Get retrieves the representation of the instance -func (RemoteAccessService Service) Get() (response ResponseStomps, err error) { - response = ResponseStomps{ +func (RemoteAccessService Service) Get() (response Response, err error) { + response = Response{ Message: &wsman.Message{ XMLInput: RemoteAccessService.base.Get(nil), }, @@ -112,8 +109,8 @@ func (RemoteAccessService Service) Get() (response ResponseStomps, err error) { } // Enumerates the instances of this class -func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err error) { - response = ResponseStomps{ +func (RemoteAccessService Service) Enumerate() (response Response, err error) { + response = Response{ Message: &wsman.Message{ XMLInput: RemoteAccessService.base.Enumerate(), }, @@ -134,9 +131,9 @@ func (RemoteAccessService Service) Enumerate() (response ResponseStomps, err err } // Pulls instances of this class, following an Enumerate operation -func (RemoteAccessService Service) Pull(enumerationContext string) string { - return RemoteAccessService.base.Pull(enumerationContext) -} +// func (RemoteAccessService Service) Pull(enumerationContext string) string { +// return RemoteAccessService.base.Pull(enumerationContext) +// } /*func (r Service) AddMPS(mpServer MPServer) string { header := r.base.WSManMessageCreator.CreateHeader(string(actions.AddMps), AMT_RemoteAccessService, nil, "", "") diff --git a/pkg/amt/remoteaccess/service_test.go b/pkg/amt/remoteaccess/service_test.go index 86d4cc38..43dd8ee6 100644 --- a/pkg/amt/remoteaccess/service_test.go +++ b/pkg/amt/remoteaccess/service_test.go @@ -16,8 +16,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/open-amt-cloud-toolkit/go-wsman-messages/internal/message" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/cim/models" - //"github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/common" "github.com/open-amt-cloud-toolkit/go-wsman-messages/pkg/wsmantesting" ) @@ -57,11 +55,7 @@ func TestAMT_RemoteAccessService(t *testing.T) { messageID := 0 resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/" wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase) - /*client := wsmantesting.MockClient{ - PackageUnderTest: "amt/remoteaccess", - }*/ client := MockClient{} - //client := wsman.NewServiceWithClient("http://localhost:16992/wsman", "admin", "Intel123!", true) elementUnderTest := NewRemoteAccessServiceWithClient(wsmanMessageCreator, &client) t.Run("amt_* Tests", func(t *testing.T) { tests := []struct { @@ -69,7 +63,7 @@ func TestAMT_RemoteAccessService(t *testing.T) { method string action string body string - responseFunc func() (ResponseStomps, error) + responseFunc func() (Response, error) expectedResponse interface{} }{ //GETS @@ -78,11 +72,11 @@ func TestAMT_RemoteAccessService(t *testing.T) { "AMT_RemoteAccessService", wsmantesting.GET, "", - func() (ResponseStomps, error) { + func() (Response, error) { currentMessage = "Get" return elementUnderTest.Get() }, - BodyStomps{ + Body{ XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, RemoteAccess: RemoteAccess{ CreationClassName: "AMT_RemoteAccessService", @@ -99,11 +93,11 @@ func TestAMT_RemoteAccessService(t *testing.T) { "AMT_RemoteAccessService", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, - func() (ResponseStomps, error) { + func() (Response, error) { currentMessage = "Enumerate" return elementUnderTest.Enumerate() }, - BodyStomps{ + Body{ XMLName: xml.Name{Space: "http://www.w3.org/2003/05/soap-envelope", Local: "Body"}, EnumerateResponse: common.EnumerateResponse{ EnumerationContext: "D3000000-0000-0000-0000-000000000000", @@ -143,10 +137,9 @@ func TestAMT_RemoteAccessService(t *testing.T) { expectedXMLInput := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body) messageID++ response, err := test.responseFunc() - //println(response.XMLOutput) assert.NoError(t, err) assert.Equal(t, expectedXMLInput, response.XMLInput) - assert.Equal(t, test.expectedResponse, response.BodyStomps) + assert.Equal(t, test.expectedResponse, response.Body) }) } }) From a3a53010ba5b667a54d6ca16bef8e47a507603a1 Mon Sep 17 00:00:00 2001 From: Zaid Date: Mon, 30 Oct 2023 15:40:47 -0700 Subject: [PATCH 4/4] feat(amt): adds execute support for remote --- pkg/amt/remoteaccess/policyappliestomps.go | 4 ++-- pkg/amt/remoteaccess/service.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/amt/remoteaccess/policyappliestomps.go b/pkg/amt/remoteaccess/policyappliestomps.go index e6899f98..3a628a94 100644 --- a/pkg/amt/remoteaccess/policyappliestomps.go +++ b/pkg/amt/remoteaccess/policyappliestomps.go @@ -20,8 +20,8 @@ const AMT_RemoteAccessPolicyAppliesToMPS = "AMT_RemoteAccessPolicyAppliesToMPS" type ( ResponseApplies struct { *wsman.Message - XMLName xml.Name `xml:"Envelope"` - Header message.Header `xml:"Header"` + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` BodyApplies BodyApplies `xml:"Body"` } BodyApplies struct { diff --git a/pkg/amt/remoteaccess/service.go b/pkg/amt/remoteaccess/service.go index 78aab944..196afc47 100644 --- a/pkg/amt/remoteaccess/service.go +++ b/pkg/amt/remoteaccess/service.go @@ -19,9 +19,9 @@ const AMT_RemoteAccessService = "AMT_RemoteAccessService" type ( Response struct { *wsman.Message - XMLName xml.Name `xml:"Envelope"` - Header message.Header `xml:"Header"` - Body Body `xml:"Body"` + XMLName xml.Name `xml:"Envelope"` + Header message.Header `xml:"Header"` + Body Body `xml:"Body"` } Body struct { XMLName xml.Name `xml:"Body"`