github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/resource_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_GetProperty_PropIsFunction(t *testing.T) {
    11  	resource := Resource{
    12  		Inner: ResourceInner{
    13  			Type: "AWS::S3::Bucket",
    14  			Properties: map[string]*Property{
    15  				"BucketName": {
    16  					Inner: PropertyInner{
    17  						Type:  cftypes.String,
    18  						Value: "mybucket",
    19  					},
    20  				},
    21  				"VersioningConfiguration": {
    22  					Inner: PropertyInner{
    23  						Type: cftypes.Map,
    24  						Value: map[string]*Property{
    25  							"Fn::If": {
    26  								Inner: PropertyInner{
    27  									Type: cftypes.List,
    28  									Value: []*Property{
    29  										{
    30  											Inner: PropertyInner{
    31  												Type:  cftypes.Bool,
    32  												Value: false,
    33  											},
    34  										},
    35  										{
    36  											Inner: PropertyInner{
    37  												Type: cftypes.Map,
    38  												Value: map[string]*Property{
    39  													"Status": {
    40  														Inner: PropertyInner{
    41  															Type:  cftypes.String,
    42  															Value: "Enabled",
    43  														},
    44  													},
    45  												},
    46  											},
    47  										},
    48  										{
    49  											Inner: PropertyInner{
    50  												Type: cftypes.Map,
    51  												Value: map[string]*Property{
    52  													"Status": {
    53  														Inner: PropertyInner{
    54  															Type:  cftypes.String,
    55  															Value: "Suspended",
    56  														},
    57  													},
    58  												},
    59  											},
    60  										},
    61  									},
    62  								},
    63  							},
    64  						},
    65  					},
    66  				},
    67  			},
    68  		},
    69  	}
    70  
    71  	prop := resource.GetProperty("VersioningConfiguration.Status")
    72  	require.NotNil(t, prop)
    73  	require.True(t, prop.IsString())
    74  	require.Equal(t, "Suspended", prop.AsString())
    75  }