Skip to content

Commit 0ee589d

Browse files
fix: boot setting validator (#581)
1 parent 2ee5507 commit 0ee589d

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

pkg/wsman/amt/boot/validator.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,12 @@ func ValidateParameters(parameters []TLVParameter) (bool, []string) {
254254

255255
// Check for mandatory parameters
256256
if !presentTypes[OCR_EFI_NETWORK_DEVICE_PATH] {
257-
valid = false
258-
259-
errors = append(errors, "missing mandatory parameter: URI to HTTPS Server")
260-
}
261-
262-
// Check for dependent parameters
263-
if presentTypes[OCR_EFI_FILE_DEVICE_PATH] && !presentTypes[OCR_EFI_DEVICE_PATH_LEN] {
264-
valid = false
257+
if !presentTypes[OCR_EFI_FILE_DEVICE_PATH] || !presentTypes[OCR_EFI_DEVICE_PATH_LEN] {
258+
valid = false
265259

266-
errors = append(errors,
267-
"missing device path length which is mandatory when file device path is provided")
260+
errors = append(errors,
261+
"missing file device path or device path length which is mandatory")
262+
}
268263
}
269264

270265
return valid, errors

pkg/wsman/amt/boot/validator_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,27 @@ func TestValidateParameters(t *testing.T) {
468468
},
469469
}
470470

471-
// Missing dependent parameter
472-
missingDependentParams := []TLVParameter{
471+
// Valid parameters with device file path
472+
deviceFileParams := []TLVParameter{
473473
{
474-
Type: OCR_EFI_NETWORK_DEVICE_PATH,
475-
Length: 22,
476-
Value: []byte("https://example.com/boot"),
474+
Type: OCR_EFI_DEVICE_PATH_LEN,
475+
Length: 2,
476+
Value: []byte{5, 0}, // Length of device path
477+
},
478+
{
479+
Type: OCR_EFI_FILE_DEVICE_PATH,
480+
Length: 5,
481+
Value: []byte("/boot"),
477482
},
483+
}
484+
485+
// Missing OCR_EFI_DEVICE_PATH_LEN
486+
missingDependentParams := []TLVParameter{
478487
{
479488
Type: OCR_EFI_FILE_DEVICE_PATH,
480489
Length: 5,
481490
Value: []byte("/boot"),
482491
},
483-
// Missing OCR_EFI_DEVICE_PATH_LEN
484492
}
485493

486494
// Invalid value for a parameter
@@ -521,6 +529,12 @@ func TestValidateParameters(t *testing.T) {
521529
expectValid: false,
522530
errorCount: 1,
523531
},
532+
{
533+
name: "Valid device file parameters",
534+
params: deviceFileParams,
535+
expectValid: true,
536+
errorCount: 0,
537+
},
524538
{
525539
name: "Missing dependent parameter",
526540
params: missingDependentParams,

0 commit comments

Comments
 (0)