Skip to content

Commit 0cac3ac

Browse files
authored
fix(misconf): fix infer type for null value (#7424)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
1 parent bf64003 commit 0cac3ac

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/iac/scanners/cloudformation/cftypes/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const (
1515
)
1616

1717
func TypeFromGoValue(value any) CfType {
18+
if value == nil {
19+
return Unknown
20+
}
1821
switch reflect.TypeOf(value).Kind() {
1922
case reflect.String:
2023
return String

pkg/iac/scanners/cloudformation/parser/parser_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,24 @@ func TestJsonWithNumbers(t *testing.T) {
419419
assert.Equal(t, 1, res[0].GetProperty("SomeIntProp").AsIntValue().Value())
420420
assert.Equal(t, 0, res[0].GetProperty("SomeFloatProp").AsIntValue().Value())
421421
}
422+
423+
func TestParameterIsNull(t *testing.T) {
424+
src := `---
425+
AWSTemplateFormatVersion: 2010-09-09
426+
427+
Parameters:
428+
Email:
429+
Type: String
430+
431+
Conditions:
432+
SubscribeEmail: !Not [!Equals [ !Ref Email, ""]]
433+
`
434+
435+
fsys := testutil.CreateFS(t, map[string]string{
436+
"main.yaml": src,
437+
})
438+
439+
files, err := New().ParseFS(context.TODO(), fsys, ".")
440+
require.NoError(t, err)
441+
require.Len(t, files, 1)
442+
}

0 commit comments

Comments
 (0)