Skip to content
Merged
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
15 changes: 5 additions & 10 deletions pkg/wsman/amt/boot/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,12 @@ func ValidateParameters(parameters []TLVParameter) (bool, []string) {

// Check for mandatory parameters
if !presentTypes[OCR_EFI_NETWORK_DEVICE_PATH] {
valid = false

errors = append(errors, "missing mandatory parameter: URI to HTTPS Server")
}

// Check for dependent parameters
if presentTypes[OCR_EFI_FILE_DEVICE_PATH] && !presentTypes[OCR_EFI_DEVICE_PATH_LEN] {
valid = false
if !presentTypes[OCR_EFI_FILE_DEVICE_PATH] || !presentTypes[OCR_EFI_DEVICE_PATH_LEN] {
valid = false

errors = append(errors,
"missing device path length which is mandatory when file device path is provided")
errors = append(errors,
"missing file device path or device path length which is mandatory")
}
}

return valid, errors
Expand Down
26 changes: 20 additions & 6 deletions pkg/wsman/amt/boot/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,27 @@ func TestValidateParameters(t *testing.T) {
},
}

// Missing dependent parameter
missingDependentParams := []TLVParameter{
// Valid parameters with device file path
deviceFileParams := []TLVParameter{
{
Type: OCR_EFI_NETWORK_DEVICE_PATH,
Length: 22,
Value: []byte("https://example.com/boot"),
Type: OCR_EFI_DEVICE_PATH_LEN,
Length: 2,
Value: []byte{5, 0}, // Length of device path
},
{
Type: OCR_EFI_FILE_DEVICE_PATH,
Length: 5,
Value: []byte("/boot"),
},
}

// Missing OCR_EFI_DEVICE_PATH_LEN
missingDependentParams := []TLVParameter{
{
Type: OCR_EFI_FILE_DEVICE_PATH,
Length: 5,
Value: []byte("/boot"),
},
// Missing OCR_EFI_DEVICE_PATH_LEN
}

// Invalid value for a parameter
Expand Down Expand Up @@ -521,6 +529,12 @@ func TestValidateParameters(t *testing.T) {
expectValid: false,
errorCount: 1,
},
{
name: "Valid device file parameters",
params: deviceFileParams,
expectValid: true,
errorCount: 0,
},
{
name: "Missing dependent parameter",
params: missingDependentParams,
Expand Down
Loading