-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudformation): fix panic when use pseudo-parameters NoValue or …
…NotificationARNs (#1395) * fix(cloudformation): fix panic when use pseudo-parameters NoValue or NotificationARNs * fix typo
- Loading branch information
Showing
5 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
package parser | ||
|
||
var pseudoParameters = map[string]interface{}{ | ||
"AWS::AccountId": "123456789012", | ||
"AWS::NotificationARNs": []string{"notification::arn::1", "notification::arn::2"}, | ||
"AWS::NoValue": nil, | ||
"AWS::Partition": "aws", | ||
"AWS::Region": "eu-west-1", | ||
"AWS::StackId": "arn:aws:cloudformation:eu-west-1:stack/ID", | ||
"AWS::StackName": "cfsec-test-stack", | ||
import "github.com/aquasecurity/defsec/pkg/scanners/cloudformation/cftypes" | ||
|
||
type pseudoParameter struct { | ||
t cftypes.CfType | ||
val interface{} | ||
raw interface{} | ||
} | ||
|
||
var pseudoParameters = map[string]pseudoParameter{ | ||
"AWS::AccountId": {t: cftypes.String, val: "123456789012"}, | ||
"AWS::NotificationARNs": { | ||
t: cftypes.List, | ||
val: []*Property{ | ||
{ | ||
Inner: PropertyInner{ | ||
Type: cftypes.String, | ||
Value: "notification::arn::1", | ||
}, | ||
}, | ||
{ | ||
Inner: PropertyInner{ | ||
Type: cftypes.String, | ||
Value: "notification::arn::2", | ||
}, | ||
}, | ||
}, | ||
raw: []string{"notification::arn::1", "notification::arn::2"}, | ||
}, | ||
"AWS::NoValue": {t: cftypes.String, val: ""}, | ||
"AWS::Partition": {t: cftypes.String, val: "aws"}, | ||
"AWS::Region": {t: cftypes.String, val: "eu-west-1"}, | ||
"AWS::StackId": {t: cftypes.String, val: "arn:aws:cloudformation:eu-west-1:stack/ID"}, | ||
"AWS::StackName": {t: cftypes.String, val: "cfsec-test-stack"}, | ||
"AWS::URLSuffix": {t: cftypes.String, val: "amazonaws.com"}, | ||
} | ||
|
||
func (p pseudoParameter) getRawValue() interface{} { | ||
switch p.t { | ||
case cftypes.List: | ||
return p.raw | ||
default: | ||
return p.val | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
pkg/scanners/cloudformation/parser/pseudo_parameters_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package parser | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Raw(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
key string | ||
expected interface{} | ||
}{ | ||
{ | ||
name: "parameter with a string type value", | ||
key: "AWS::AccountId", | ||
expected: "123456789012", | ||
}, | ||
{ | ||
name: "a parameter with a list type value", | ||
key: "AWS::NotificationARNs", | ||
expected: []string{"notification::arn::1", "notification::arn::2"}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if val, ok := pseudoParameters[tt.key]; ok { | ||
assert.Equal(t, tt.expected, val.getRawValue()) | ||
} else { | ||
t.Fatal("unexpected parameter key") | ||
} | ||
}) | ||
} | ||
} |