Skip to content

Commit

Permalink
fix(misconf): fix infer type for null value (#7424)
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io>
  • Loading branch information
nikpivkin authored Aug 31, 2024
1 parent bf64003 commit 0cac3ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/iac/scanners/cloudformation/cftypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
)

func TypeFromGoValue(value any) CfType {
if value == nil {
return Unknown
}
switch reflect.TypeOf(value).Kind() {
case reflect.String:
return String
Expand Down
21 changes: 21 additions & 0 deletions pkg/iac/scanners/cloudformation/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,24 @@ func TestJsonWithNumbers(t *testing.T) {
assert.Equal(t, 1, res[0].GetProperty("SomeIntProp").AsIntValue().Value())
assert.Equal(t, 0, res[0].GetProperty("SomeFloatProp").AsIntValue().Value())
}

func TestParameterIsNull(t *testing.T) {
src := `---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Email:
Type: String
Conditions:
SubscribeEmail: !Not [!Equals [ !Ref Email, ""]]
`

fsys := testutil.CreateFS(t, map[string]string{
"main.yaml": src,
})

files, err := New().ParseFS(context.TODO(), fsys, ".")
require.NoError(t, err)
require.Len(t, files, 1)
}

0 comments on commit 0cac3ac

Please sign in to comment.