Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misconf): fix infer type for null value #7424

Merged
merged 1 commit into from
Aug 31, 2024
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
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)
}