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

* guard against nil dereference; lock down with tests

* fix test name
Этот коммит содержится в:
Christopher Poile
2025-01-28 13:46:12 -05:00
коммит произвёл GitHub
родитель 95fe972d83
Коммит 87ea6d8b1c
2 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@@ -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
}
}

Просмотреть файл

@@ -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{