Skip to content

Commit

Permalink
fix(amt): TLS Settings Responses (#167)
Browse files Browse the repository at this point in the history
added prefix and namespace support TLSSettingsData for marhalling to XML
  • Loading branch information
tim-shockley authored Jan 4, 2024
1 parent 7653572 commit febf385
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 39 deletions.
81 changes: 46 additions & 35 deletions pkg/amt/tls/settingdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,51 @@ package tls
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"
)

const AMT_TLSSettingData = "AMT_TLSSettingData"

type PullResponseEnvelope struct {
XMLName xml.Name `xml:"Envelope"`
Header message.Header
Body PullResponseBody
}

type PullResponseBody struct {
PullResponse PullResponse
}

type PullResponse struct {
Items []TLSSettingData `xml:"Items>AMT_TLSSettingData"`
EndOfSequence string
}

type PutResponseEnvelope struct {
XMLName xml.Name `xml:"Envelope"`
Header message.Header
Body PutResponseBody
}

type PutResponseBody struct {
TLSSettingData TLSSettingData
}
type (
Response struct {
XMLName xml.Name `xml:"Envelope"`
Header message.Header `xml:"Header"`
Body Body `xml:"Body"`
}
Body struct {
XMLName xml.Name `xml:"Body"`
TlsSetting TlsSetting `xml:"AMT_TLSSettingData"`
EnumerateResponse common.EnumerateResponse
PullResponse PullResponse
}
TlsSetting struct {
AcceptNonSecureConnections bool
ElementName string
Enabled bool
InstanceID string
MutualAuthentication bool
NonSecureConnectionsSupported *bool
}
PullResponse struct {
TlsSettingItems []TlsSetting `xml:"Items>AMT_TLSSettingData"`
}
)

// TLSSettingData supports aliased namespace for the PUT call to AMT
// TLSSettings responses from AMT have different aliases, and the PUT call requires namespace
// PUT response -- <a:Body><g:AMT_TLSSettingData>
// PULL response -- <a:Body><g:PullResponse><g:Items><h:AMT_TLSSettingData>
type TLSSettingData struct {
models.SettingData
MutualAuthentication bool
Enabled bool
TrustedCN string
AcceptNonSecureConnections bool
NonSecureConnectionsSupported bool
XMLName xml.Name `xml:"h:AMT_TLSSettingData"`
H string `xml:"xmlns:h,attr"`
AcceptNonSecureConnections bool `xml:"h:AcceptNonSecureConnections"`
ElementName string `xml:"h:ElementName,omitempty"`
Enabled bool `xml:"h:Enabled"`
InstanceID string `xml:"h:InstanceID,omitempty"`
MutualAuthentication bool `xml:"h:MutualAuthentication"`
TrustedCN string `xml:"h:TrustedCN,omitempty"`
}

type SettingData struct {
base message.Base
}
Expand All @@ -61,17 +68,21 @@ func (TLSSettingData SettingData) Get() string {
return TLSSettingData.base.Get(nil)
}

// Enumerates the instances of this class
// Enumerate the instances of this class
func (TLSSettingData SettingData) Enumerate() string {
return TLSSettingData.base.Enumerate()
}

// Pulls instances of this class, following an Enumerate operation
// Pull instances of this class, following an Enumerate operation
func (TLSSettingData SettingData) Pull(enumerationContext string) string {
return TLSSettingData.base.Pull(enumerationContext)
}

// Put will change properties of the selected instance
func (TLSSettingData SettingData) Put(tlsSettingData TLSSettingData) string {
return TLSSettingData.base.Put(tlsSettingData, false, nil)
func (TLSSettingData SettingData) Put(data TLSSettingData) string {
selector := message.Selector{
Name: "InstanceID",
Value: data.InstanceID,
}
return TLSSettingData.base.Put(&data, true, &selector)
}
26 changes: 22 additions & 4 deletions pkg/amt/tls/settingdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,44 @@ func TestAMT_TLSSettingData(t *testing.T) {
resourceUriBase := "http://intel.com/wbem/wscim/1/amt-schema/1/"
wsmanMessageCreator := message.NewWSManMessageCreator(resourceUriBase)
elementUnderTest := NewTLSSettingData(wsmanMessageCreator)
data := TLSSettingData{
ElementName: `Intel(r) AMT LMS TLS Settings`,
InstanceID: `Intel(r) AMT LMS TLS Settings`,
AcceptNonSecureConnections: true,
Enabled: true,
MutualAuthentication: true,
}
expectedPutSelector := `<w:SelectorSet><w:Selector Name="InstanceID">Intel(r) AMT LMS TLS Settings</w:Selector></w:SelectorSet>`
expectedPutBody := `<h:AMT_TLSSettingData xmlns:h="http://intel.com/wbem/wscim/1/amt-schema/1/AMT_TLSSettingData">` +
`<h:AcceptNonSecureConnections>true</h:AcceptNonSecureConnections>` +
`<h:ElementName>Intel(r) AMT LMS TLS Settings</h:ElementName>` +
`<h:Enabled>true</h:Enabled>` +
`<h:InstanceID>Intel(r) AMT LMS TLS Settings</h:InstanceID>` +
`<h:MutualAuthentication>true</h:MutualAuthentication>` +
`</h:AMT_TLSSettingData>`

t.Run("amt_* Tests", func(t *testing.T) {
tests := []struct {
name string
method string
action string
extraHeader string
body string
responseFunc func() string
}{
//GETS
{"should create a valid AMT_TLSSettingData Get wsman message", "AMT_TLSSettingData", wsmantesting.GET, "", elementUnderTest.Get},
{"should create a valid AMT_TLSSettingData Get wsman message", "AMT_TLSSettingData", wsmantesting.GET, "", "", elementUnderTest.Get},
//ENUMERATES
{"should create a valid AMT_TLSSettingData Enumerate wsman message", "AMT_TLSSettingData", wsmantesting.ENUMERATE, wsmantesting.ENUMERATE_BODY, elementUnderTest.Enumerate},
{"should create a valid AMT_TLSSettingData Enumerate wsman message", "AMT_TLSSettingData", wsmantesting.ENUMERATE, "", wsmantesting.ENUMERATE_BODY, elementUnderTest.Enumerate},
//PULLS
{"should create a valid AMT_TLSSettingData Pull wsman message", "AMT_TLSSettingData", wsmantesting.PULL, wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }},
{"should create a valid AMT_TLSSettingData Pull wsman message", "AMT_TLSSettingData", wsmantesting.PULL, "", wsmantesting.PULL_BODY, func() string { return elementUnderTest.Pull(wsmantesting.EnumerationContext) }},
//PUT
{"should create a valid AMT_TLSSettingData Put wsman message", "AMT_TLSSettingData", wsmantesting.PUT, expectedPutSelector, expectedPutBody, func() string { return elementUnderTest.Put(data) }},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, "", test.body)
correctResponse := wsmantesting.ExpectedResponse(messageID, resourceUriBase, test.method, test.action, test.extraHeader, test.body)
messageID++
response := test.responseFunc()
if response != correctResponse {
Expand Down

0 comments on commit febf385

Please sign in to comment.