Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"guid\": \"143e4567-e89b-12d3-a456-426614174000\",\r\n \"friendlyName\": \"friendlyName\",\r\n \"hostname\": \"hostname\",\r\n \"tags\": [],\r\n \"mpsusername\": \"admin\",\r\n \"deviceInfo\": {\r\n \"fwVersion\": \"16.1.30\",\r\n \"fwBuild\": \"3400\",\r\n \"fwSku\": \"11\",\r\n \"currentMode\": \"Admin\",\r\n \"features\": \"SOL,IDER,KVM\",\r\n \"ipAddress\": \"10.0.0.12\",\r\n \"lastUpdated\": \"2026-05-21T00:00:00Z\",\r\n \"tlsMode\": \"TLS 1.2\",\r\n \"upid\": {\r\n \"oemPlatformIdType\": \"Not Set (0)\",\r\n \"oemId\": \"\",\r\n \"csmeId\": \"4A45A39C5ED9462082510000\"\r\n },\r\n \"amtEnabledInBIOS\": true,\r\n \"meInterfaceVersion\": \"16.1.25.2124\",\r\n \"dhcpEnabled\": true,\r\n \"certHashes\": [\r\n \"a1b2c3\",\r\n \"d4e5f6\"\r\n ],\r\n \"lmsInstalled\": true,\r\n \"lmsVersion\": \"2410.5.0.0\",\r\n \"osName\": \"linux\",\r\n \"osVersion\": \"6.8.0-51-generic\",\r\n \"osDistro\": \"Ubuntu 24.04 LTS\",\r\n \"cpuModel\": \"Intel(R) Core(TM) Ultra 7 165H\",\r\n \"osIpAddress\": \"10.49.76.163\",\r\n \"ethernetAdapterCount\": 2,\r\n \"monitorConnected\": true,\r\n \"ieee8021xEnabled\": false\r\n }\r\n}",
"raw": "{\r\n \"guid\": \"143e4567-e89b-12d3-a456-426614174000\",\r\n \"friendlyName\": \"friendlyName\",\r\n \"hostname\": \"hostname\",\r\n \"tags\": [],\r\n \"mpsusername\": \"admin\",\r\n \"deviceInfo\": {\r\n \"fwVersion\": \"16.1.30\",\r\n \"fwBuild\": \"3400\",\r\n \"fwSku\": \"11\",\r\n \"discovered\": true,\r\n \"currentMode\": \"Admin\",\r\n \"features\": \"SOL,IDER,KVM\",\r\n \"ipAddress\": \"10.0.0.12\",\r\n \"lastUpdated\": \"2026-05-21T00:00:00Z\",\r\n \"tlsMode\": \"TLS 1.2\",\r\n \"upid\": {\r\n \"oemPlatformIdType\": \"Not Set (0)\",\r\n \"oemId\": \"\",\r\n \"csmeId\": \"4A45A39C5ED9462082510000\"\r\n },\r\n \"amtEnabledInBIOS\": true,\r\n \"meInterfaceVersion\": \"16.1.25.2124\",\r\n \"dhcpEnabled\": true,\r\n \"certHashes\": [\r\n \"a1b2c3\",\r\n \"d4e5f6\"\r\n ],\r\n \"lmsInstalled\": true,\r\n \"lmsVersion\": \"2410.5.0.0\",\r\n \"osName\": \"linux\",\r\n \"osVersion\": \"6.8.0-51-generic\",\r\n \"osDistro\": \"Ubuntu 24.04 LTS\",\r\n \"cpuModel\": \"Intel(R) Core(TM) Ultra 7 165H\",\r\n \"osIpAddress\": \"10.49.76.163\",\r\n \"ethernetAdapterCount\": 2,\r\n \"monitorConnected\": true,\r\n \"ieee8021xEnabled\": false\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down
16 changes: 11 additions & 5 deletions internal/controller/httpapi/v1/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,21 @@ func TestDevicesUpdatePartialPatchTracksDeviceInfoSubfields(t *testing.T) {
t.Parallel()

guid := testDeviceGUID
discovered := true

incoming := &dto.Device{
GUID: guid,
DeviceInfo: &dto.DeviceInfo{
FWVersion: "16.1.30",
FWVersion: "16.1.30",
Discovered: &discovered,
},
}

expectedFields := map[string]bool{
"guid": true,
"deviceinfo": true,
"deviceinfo.fwversion": true,
"guid": true,
"deviceinfo": true,
"deviceinfo.fwversion": true,
"deviceinfo.discovered": true,
}

devicesFeature, engine := devicesTest(t)
Expand All @@ -466,7 +469,7 @@ func TestDevicesUpdatePartialPatchTracksDeviceInfoSubfields(t *testing.T) {
Update(context.Background(), incoming, expectedFields).
Return(incoming, nil)

body := []byte(`{"guid":"` + guid + `","deviceInfo":{"fwVersion":"16.1.30"}}`)
body := []byte(`{"guid":"` + guid + `","deviceInfo":{"fwVersion":"16.1.30","discovered":true}}`)

req, err := http.NewRequestWithContext(context.Background(), http.MethodPatch, "/api/v1/devices", bytes.NewBuffer(body))
require.NoError(t, err)
Expand All @@ -481,6 +484,7 @@ func TestDevicesInsertAcceptsFullDeviceInfo(t *testing.T) {
t.Parallel()

lmsInstalled := false
discovered := true
amtEnabledInBIOS := true
dhcpEnabled := true
ethernetAdapterCount := 2
Expand All @@ -494,6 +498,7 @@ func TestDevicesInsertAcceptsFullDeviceInfo(t *testing.T) {
FWVersion: "16.1.30",
FWBuild: "3400",
FWSku: "11",
Discovered: &discovered,
CurrentMode: "Admin",
Features: "SOL,IDER,KVM",
IPAddress: "10.0.0.12",
Expand Down Expand Up @@ -534,6 +539,7 @@ func TestDevicesInsertAcceptsFullDeviceInfo(t *testing.T) {
"fwVersion":"16.1.30",
"fwBuild":"3400",
"fwSku":"11",
"discovered":true,
"currentMode":"Admin",
"features":"SOL,IDER,KVM",
"ipAddress":"10.0.0.12",
Expand Down
1 change: 1 addition & 0 deletions internal/entity/dto/v1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DeviceInfo struct {
FWVersion string `json:"fwVersion"`
FWBuild string `json:"fwBuild"`
FWSku string `json:"fwSku"`
Discovered *bool `json:"discovered,omitempty"`
CurrentMode string `json:"currentMode"`
Features string `json:"features"`
IPAddress string `json:"ipAddress"`
Expand Down
4 changes: 4 additions & 0 deletions internal/entity/dto/v1/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestDeviceInfoJSONRoundTrip(t *testing.T) {
amtEnabled := true
dhcpEnabled := true
lmsInstalled := true
discovered := true
ethernetAdapterCount := 2
monitorConnected := true
ieee8021xEnabled := false
Expand All @@ -23,6 +24,7 @@ func TestDeviceInfoJSONRoundTrip(t *testing.T) {
FWVersion: "16.1.30",
FWBuild: "3400",
FWSku: "11",
Discovered: &discovered,
CurrentMode: "Admin",
Features: "SOL,IDER,KVM",
IPAddress: "10.0.0.12",
Expand Down Expand Up @@ -59,6 +61,8 @@ func TestDeviceInfoJSONRoundTrip(t *testing.T) {
require.Equal(t, info.MEInterfaceVersion, decoded.MEInterfaceVersion)
require.Equal(t, info.CertHashes, decoded.CertHashes)
require.Equal(t, info.LMSVersion, decoded.LMSVersion)
require.NotNil(t, decoded.Discovered)
require.Equal(t, *info.Discovered, *decoded.Discovered)
require.NotNil(t, decoded.LMSInstalled)
require.Equal(t, *info.LMSInstalled, *decoded.LMSInstalled)
}
8 changes: 6 additions & 2 deletions internal/usecase/devices/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,15 @@ func TestUpdatePartial(t *testing.T) {
MEBXPassword: ptr("encrypted-mebx"),
}

// Client sends only guid, tenantId and a new hostname.
// Client sends guid, a new hostname, and a partial deviceInfo update.
discovered := true
incoming := &dto.Device{
GUID: "device-guid-123",
TenantID: "tenant-id-456",
Hostname: "new-hostname",
DeviceInfo: &dto.DeviceInfo{
FWVersion: "16.1.30",
Discovered: &discovered,
IPAddress: "10.0.0.55",
LMSInstalled: boolPtr(true),
},
Expand All @@ -776,13 +778,14 @@ func TestUpdatePartial(t *testing.T) {
"hostname": true,
"deviceinfo": true,
"deviceinfo.fwversion": true,
"deviceinfo.discovered": true,
"deviceinfo.ipaddress": true,
"deviceinfo.lmsinstalled": true,
}

// After merge + dtoToEntity (MockCrypto re-encrypts plaintext to "encrypted"):
// Only fields without omitempty tag are included in JSON for zero values.
expectedDeviceInfoJSON := `{"fwVersion":"16.1.30","fwBuild":"3400","fwSku":"","currentMode":"","features":"","ipAddress":"10.0.0.55","lmsInstalled":true}`
expectedDeviceInfoJSON := `{"fwVersion":"16.1.30","fwBuild":"3400","fwSku":"","discovered":true,"currentMode":"","features":"","ipAddress":"10.0.0.55","lmsInstalled":true}`
expectedEntity := &entity.Device{
GUID: "device-guid-123",
TenantID: "tenant-id-456",
Expand All @@ -803,6 +806,7 @@ func TestUpdatePartial(t *testing.T) {
DeviceInfo: &dto.DeviceInfo{
FWVersion: "16.1.30",
FWBuild: "3400",
Discovered: boolPtr(true),
IPAddress: "10.0.0.55",
LMSInstalled: boolPtr(true),
},
Expand Down
1 change: 1 addition & 0 deletions internal/usecase/devices/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ var deviceInfoFieldSetters = map[string]func(dst, src *dto.DeviceInfo){
"fwversion": func(dst, src *dto.DeviceInfo) { dst.FWVersion = src.FWVersion },
"fwbuild": func(dst, src *dto.DeviceInfo) { dst.FWBuild = src.FWBuild },
"fwsku": func(dst, src *dto.DeviceInfo) { dst.FWSku = src.FWSku },
"discovered": func(dst, src *dto.DeviceInfo) { dst.Discovered = src.Discovered },
"currentmode": func(dst, src *dto.DeviceInfo) { dst.CurrentMode = src.CurrentMode },
"features": func(dst, src *dto.DeviceInfo) { dst.Features = src.Features },
"ipaddress": func(dst, src *dto.DeviceInfo) { dst.IPAddress = src.IPAddress },
Expand Down
Loading