[MM-62537] Fix: Integration action nil ptr dereference (#29986)

* guard against nil dereference; lock down with tests

* fix test name
This commit is contained in:
Christopher Poile 2025-01-28 13:46:12 -05:00 committed by GitHub
parent 95fe972d83
commit 87ea6d8b1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -466,7 +466,7 @@ func isDefaultInOptions(defaultValue string, options []*PostActionOptions) bool
}
for _, option := range options {
if defaultValue == option.Value {
if option != nil && defaultValue == option.Value {
return true
}
}

View file

@ -322,6 +322,22 @@ func TestOpenDialogRequestIsValid(t *testing.T) {
assert.ErrorContains(t, err, "invalid data source")
})
t.Run("should fail on wrong select default value, and not fail with nil dereference", func(t *testing.T) {
request := getBaseOpenDialogRequest()
request.Dialog.Elements = append(request.Dialog.Elements, DialogElement{
DisplayName: "Select element name",
Name: "select_element_name",
Type: "select",
DataSource: "",
Default: "default",
Options: []*PostActionOptions{
nil,
},
})
err := request.IsValid()
assert.ErrorContains(t, err, "default value \"default\" doesn't exist in options")
})
t.Run("should fail on wrong radio default value", func(t *testing.T) {
request := getBaseOpenDialogRequest()
request.Dialog.Elements = append(request.Dialog.Elements, DialogElement{
@ -339,6 +355,20 @@ func TestOpenDialogRequestIsValid(t *testing.T) {
err := request.IsValid()
assert.ErrorContains(t, err, "default value \"default\" doesn't exist in options")
})
t.Run("should fail on wrong radio default value, and not fail with nil dereference", func(t *testing.T) {
request := getBaseOpenDialogRequest()
request.Dialog.Elements = append(request.Dialog.Elements, DialogElement{
DisplayName: "Radio element name",
Name: "radio_element_name",
Type: "radio",
Default: "default",
Options: []*PostActionOptions{
nil,
},
})
err := request.IsValid()
assert.ErrorContains(t, err, "default value \"default\" doesn't exist in options")
})
t.Run("should pass radio default value", func(t *testing.T) {
request := getBaseOpenDialogRequest()
request.Dialog.Elements = append(request.Dialog.Elements, DialogElement{