github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/internal/adapters/arm/compute/adapt_test.go (about)

     1  package compute
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/khulnasoft-lab/defsec/pkg/scanners/azure"
     7  	"github.com/khulnasoft-lab/defsec/pkg/types"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func Test_AdaptLinuxVM(t *testing.T) {
    15  
    16  	input := azure.Deployment{
    17  		Resources: []azure.Resource{
    18  			{
    19  				Type: azure.NewValue("Microsoft.Compute/virtualMachines", types.NewTestMetadata()),
    20  				Properties: azure.NewValue(map[string]azure.Value{
    21  					"osProfile": azure.NewValue(map[string]azure.Value{
    22  						"linuxConfiguration": azure.NewValue(map[string]azure.Value{
    23  							"disablePasswordAuthentication": azure.NewValue(true, types.NewTestMetadata()),
    24  						}, types.NewTestMetadata()),
    25  					}, types.NewTestMetadata()),
    26  				}, types.NewTestMetadata()),
    27  			},
    28  		},
    29  	}
    30  
    31  	output := Adapt(input)
    32  
    33  	require.Len(t, output.LinuxVirtualMachines, 1)
    34  	require.Len(t, output.WindowsVirtualMachines, 0)
    35  
    36  	linuxVM := output.LinuxVirtualMachines[0]
    37  	assert.True(t, linuxVM.OSProfileLinuxConfig.DisablePasswordAuthentication.IsTrue())
    38  
    39  }
    40  
    41  func Test_AdaptWindowsVM(t *testing.T) {
    42  
    43  	input := azure.Deployment{
    44  		Resources: []azure.Resource{
    45  			{
    46  				Type: azure.NewValue("Microsoft.Compute/virtualMachines", types.NewTestMetadata()),
    47  				Properties: azure.NewValue(map[string]azure.Value{
    48  					"osProfile": azure.NewValue(map[string]azure.Value{
    49  						"windowsConfiguration": azure.NewValue(map[string]azure.Value{}, types.NewTestMetadata()),
    50  					}, types.NewTestMetadata()),
    51  				}, types.NewTestMetadata()),
    52  			},
    53  		},
    54  	}
    55  
    56  	output := Adapt(input)
    57  
    58  	require.Len(t, output.LinuxVirtualMachines, 0)
    59  	require.Len(t, output.WindowsVirtualMachines, 1)
    60  }