Skip to content

Commit

Permalink
fix(misconf): init frameworks before updating them (#7376)
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 23, 2024
1 parent 9ef05fc commit b65b32d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/iac/rego/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func NewStaticMetadata(pkgPath string, inputOpt InputOptions) *StaticMetadata {
}

func (sm *StaticMetadata) Update(meta map[string]any) error {
if sm.Frameworks == nil {
sm.Frameworks = make(map[framework.Framework][]string)
}

upd := func(field *string, key string) {
if raw, ok := meta[key]; ok {
Expand Down
11 changes: 11 additions & 0 deletions pkg/iac/rego/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func Test_UpdateStaticMetadata(t *testing.T) {
References: []string{"r", "r1_n", "r2_n"},
CloudFormation: &scan.EngineMetadata{},
Terraform: &scan.EngineMetadata{},
Frameworks: make(map[framework.Framework][]string),
}

assert.Equal(t, expected, sm)
Expand All @@ -114,6 +115,7 @@ func Test_UpdateStaticMetadata(t *testing.T) {
References: []string{"r", "r1_n", "r2_n"},
CloudFormation: &scan.EngineMetadata{},
Terraform: &scan.EngineMetadata{},
Frameworks: make(map[framework.Framework][]string),
}

assert.Equal(t, expected, sm)
Expand All @@ -131,10 +133,19 @@ func Test_UpdateStaticMetadata(t *testing.T) {
Deprecated: true,
CloudFormation: &scan.EngineMetadata{},
Terraform: &scan.EngineMetadata{},
Frameworks: make(map[framework.Framework][]string),
}

assert.Equal(t, expected, sm)
})

t.Run("frameworks is not initialized", func(t *testing.T) {
sm := StaticMetadata{}
err := sm.Update(map[string]any{
"frameworks": map[string]any{"all": []any{"a", "b", "c"}},
})
require.NoError(t, err)
})
}

func Test_NewEngineMetadata(t *testing.T) {
Expand Down

0 comments on commit b65b32d

Please sign in to comment.