mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
2d8fcd9bf4
Co-authored-by: Malte Poll <mp@edgeless.systems> Co-authored-by: katexochen <katexochen@users.noreply.github.com> Co-authored-by: Daniel Weiße <dw@edgeless.systems> Co-authored-by: Thomas Tendyck <tt@edgeless.systems> Co-authored-by: Benedict Schlueter <bs@edgeless.systems> Co-authored-by: leongross <leon.gross@rub.de> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
112 lines
4.6 KiB
Go
112 lines
4.6 KiB
Go
package azure
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFirewallPermissions(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
scaleSet := ScaleSet{
|
|
Name: "name",
|
|
NamePrefix: "constellation-",
|
|
Location: "UK South",
|
|
InstanceType: "Standard_D2s_v3",
|
|
Count: 3,
|
|
Username: "constellation",
|
|
SubnetID: "subnet-id",
|
|
NetworkSecurityGroup: "network-security-group",
|
|
Password: "password",
|
|
Image: "image",
|
|
UserAssignedIdentity: "user-identity",
|
|
}
|
|
|
|
scaleSetAzure := scaleSet.Azure()
|
|
|
|
require.NotNil(scaleSetAzure.Name)
|
|
assert.Equal(scaleSet.Name, *scaleSetAzure.Name)
|
|
require.NotNil(scaleSetAzure.Location)
|
|
assert.Equal(scaleSet.Location, *scaleSetAzure.Location)
|
|
|
|
require.NotNil(scaleSetAzure.SKU)
|
|
require.NotNil(scaleSetAzure.SKU.Name)
|
|
assert.Equal(scaleSet.InstanceType, *scaleSetAzure.SKU.Name)
|
|
|
|
require.NotNil(scaleSetAzure.SKU.Capacity)
|
|
assert.Equal(scaleSet.Count, *scaleSetAzure.SKU.Capacity)
|
|
|
|
require.NotNil(scaleSetAzure.Properties)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.OSProfile)
|
|
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.ComputerNamePrefix)
|
|
assert.Equal(scaleSet.NamePrefix, *scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.ComputerNamePrefix)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.AdminUsername)
|
|
assert.Equal(scaleSet.Username, *scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.AdminUsername)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.AdminPassword)
|
|
assert.Equal(scaleSet.Password, *scaleSetAzure.Properties.VirtualMachineProfile.OSProfile.AdminPassword)
|
|
|
|
// Verify image
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.StorageProfile)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.StorageProfile.ImageReference)
|
|
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID)
|
|
assert.Equal(scaleSet.Image, *scaleSetAzure.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID)
|
|
|
|
// Verify network
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.NetworkProfile)
|
|
require.Len(scaleSetAzure.Properties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations, 1)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0])
|
|
|
|
networkConfig := scaleSetAzure.Properties.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0]
|
|
|
|
require.NotNil(networkConfig.Name)
|
|
assert.Equal(scaleSet.Name, *networkConfig.Name)
|
|
|
|
require.NotNil(networkConfig.Properties)
|
|
require.Len(networkConfig.Properties.IPConfigurations, 1)
|
|
require.NotNil(networkConfig.Properties.IPConfigurations[0])
|
|
|
|
ipConfig := networkConfig.Properties.IPConfigurations[0]
|
|
|
|
require.NotNil(ipConfig.Name)
|
|
assert.Equal(scaleSet.Name, *ipConfig.Name)
|
|
|
|
require.NotNil(ipConfig.Properties)
|
|
require.NotNil(ipConfig.Properties.Subnet)
|
|
|
|
require.NotNil(ipConfig.Properties.Subnet.ID)
|
|
assert.Equal(scaleSet.SubnetID, *ipConfig.Properties.Subnet.ID)
|
|
|
|
require.NotNil(networkConfig.Properties.NetworkSecurityGroup)
|
|
assert.Equal(scaleSet.NetworkSecurityGroup, *networkConfig.Properties.NetworkSecurityGroup.ID)
|
|
|
|
// Verify vTPM
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile.SecurityType)
|
|
assert.Equal(armcompute.SecurityTypesTrustedLaunch, *scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile.SecurityType)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile.UefiSettings)
|
|
require.NotNil(scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile.UefiSettings.VTpmEnabled)
|
|
assert.True(*scaleSetAzure.Properties.VirtualMachineProfile.SecurityProfile.UefiSettings.VTpmEnabled)
|
|
|
|
// Verify UserAssignedIdentity
|
|
require.NotNil(scaleSetAzure.Identity)
|
|
require.NotNil(scaleSetAzure.Identity.Type)
|
|
assert.Equal(armcompute.ResourceIdentityTypeUserAssigned, *scaleSetAzure.Identity.Type)
|
|
require.Len(scaleSetAzure.Identity.UserAssignedIdentities, 1)
|
|
assert.Contains(scaleSetAzure.Identity.UserAssignedIdentities, scaleSet.UserAssignedIdentity)
|
|
}
|
|
|
|
func TestGeneratePassword(t *testing.T) {
|
|
assert := assert.New(t)
|
|
require := require.New(t)
|
|
|
|
pw, err := GeneratePassword()
|
|
require.NoError(err)
|
|
assert.Len(pw, 20)
|
|
}
|