github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/fn_condition_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/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_resolve_condition_value(t *testing.T) {
    12  
    13  	fctx := new(FileContext)
    14  	fctx.Conditions = map[string]Property{
    15  		"SomeCondition": {
    16  			ctx: fctx,
    17  			Inner: PropertyInner{
    18  				Type: cftypes.Map,
    19  				Value: map[string]*Property{
    20  					"Fn::Equals": {
    21  						ctx: fctx,
    22  						Inner: PropertyInner{
    23  							Type: cftypes.List,
    24  							Value: []*Property{
    25  								{
    26  									Inner: PropertyInner{
    27  										Type:  cftypes.String,
    28  										Value: "some val",
    29  									},
    30  								},
    31  								{
    32  									Inner: PropertyInner{
    33  										Type:  cftypes.String,
    34  										Value: "some val",
    35  									},
    36  								},
    37  							},
    38  						},
    39  					},
    40  				},
    41  			},
    42  		},
    43  		"EnableVersioning": {
    44  			ctx: fctx,
    45  			Inner: PropertyInner{
    46  				Type: cftypes.Map,
    47  				Value: map[string]*Property{
    48  					"Condition": {
    49  						Inner: PropertyInner{
    50  							Type:  cftypes.String,
    51  							Value: "SomeCondition",
    52  						},
    53  					},
    54  				},
    55  			},
    56  		},
    57  	}
    58  
    59  	property := &Property{
    60  		ctx: fctx,
    61  		Inner: PropertyInner{
    62  			Type: cftypes.Map,
    63  			Value: map[string]*Property{
    64  				"Fn::If": {
    65  					ctx: fctx,
    66  					Inner: PropertyInner{
    67  						Type: cftypes.List,
    68  						Value: []*Property{
    69  							{
    70  								Inner: PropertyInner{
    71  									Type:  cftypes.String,
    72  									Value: "EnableVersioning",
    73  								},
    74  							},
    75  							{
    76  								Inner: PropertyInner{
    77  									Type:  cftypes.String,
    78  									Value: "Enabled",
    79  								},
    80  							},
    81  							{
    82  								Inner: PropertyInner{
    83  									Type:  cftypes.String,
    84  									Value: "Suspended",
    85  								},
    86  							},
    87  						},
    88  					},
    89  				},
    90  			},
    91  		},
    92  	}
    93  
    94  	resolvedProperty, success := ResolveIntrinsicFunc(property)
    95  	require.True(t, success)
    96  
    97  	assert.Equal(t, "Enabled", resolvedProperty.AsString())
    98  }