github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/internal/adapters/cloudformation/aws/elb/adapt_test.go (about)

     1  package elb
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/aquasecurity/defsec/pkg/providers/aws/elb"
     8  	"github.com/aquasecurity/defsec/pkg/types"
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/parser"
    12  	"github.com/aquasecurity/trivy-iac/test/testutil"
    13  )
    14  
    15  func TestAdapt(t *testing.T) {
    16  	tests := []struct {
    17  		name     string
    18  		source   string
    19  		expected elb.ELB
    20  	}{
    21  		{
    22  			name: "LoadBalancer",
    23  			source: `AWSTemplateFormatVersion: "2010-09-09"
    24  Resources:
    25    LoadBalancer:
    26      Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    27      DependsOn:
    28        - ALBLogsBucketPermission
    29      Properties:
    30        Name: "k8s-dev"
    31        IpAddressType: ipv4
    32        LoadBalancerAttributes:
    33          - Key: routing.http2.enabled
    34            Value: "true"
    35          - Key: deletion_protection.enabled
    36            Value: "true"
    37          - Key: routing.http.drop_invalid_header_fields.enabled
    38            Value: "true"
    39          - Key: access_logs.s3.enabled
    40            Value: "true"
    41        Tags:
    42          - Key: ingress.k8s.aws/resource
    43            Value: LoadBalancer
    44          - Key: elbv2.k8s.aws/cluster
    45            Value: "biomage-dev"
    46        Type: application
    47  `,
    48  			expected: elb.ELB{
    49  				LoadBalancers: []elb.LoadBalancer{
    50  					{
    51  						Metadata:                types.NewTestMetadata(),
    52  						Type:                    types.String("application", types.NewTestMetadata()),
    53  						DropInvalidHeaderFields: types.Bool(true, types.NewTestMetadata()),
    54  					},
    55  				},
    56  			},
    57  		},
    58  	}
    59  
    60  	for _, tt := range tests {
    61  		t.Run(tt.name, func(t *testing.T) {
    62  			fs := testutil.CreateFS(t, map[string]string{
    63  				"template.yaml": tt.source,
    64  			})
    65  
    66  			p := parser.New()
    67  			fctx, err := p.ParseFile(context.TODO(), fs, "template.yaml")
    68  			require.NoError(t, err)
    69  
    70  			testutil.AssertDefsecEqual(t, tt.expected, Adapt(*fctx))
    71  		})
    72  	}
    73  }