Add example properties from azure integration tests. (#2659)

Remove trailing whitespace.
Clean up formatting and some rubocop issues.

Signed-off-by: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
Miah Johnson 2018-02-15 18:52:54 -08:00 committed by Jared Quick
parent 1e3df9d3bf
commit 75fb488d2c
10 changed files with 188 additions and 35 deletions

View file

@ -24,7 +24,7 @@ The options that can be passed to the resource are as follows.
* `group_name`, the Azure resource group to be tested. Example: 'MyResourceGroup' (required)
* `name`, the name of the Azure resource to test. Example: 'MyVM'
* `type`, the Azure resource type. Example: 'Microsoft.Compute/virtualMachines'
* `apiversion`, the API Version to use when querying the resource. Defaults to the latest version for the resoure type is used. Example: 2017-10-9
* `apiversion`, the API Version to use when querying the resource. Defaults to the latest version for the resoure type is used. Example: 2017-10-9
These options can also be set using the environment variables:
@ -68,7 +68,169 @@ Please see the integration tests for in depth examples of how this resource can
- [Generic Windows Internal VM NIC](../test/integration/verify/controls/generic_windows_internal_vm_nic.rb)
- [Generic Windows Internal VM](../test/integration/verify/controls/generic_windows_internal_vm.rb)
## Matchers
### Example Properties
- `properties.addressSpace.addressPrefixes`
`its('properties.addressSpace.addressPrefixes') { should include '10.1.1.0/24' }`
- `properties.creationData.createOption`
`its('properties.creationData.createOption') { should eq 'FromImage' }`
- `properties.creationData.imageReference.id`
`its('properties.creationData.imageReference.id') { should match 'Canonical' }`
- `properties.diskSizeGB`
`its('properties.diskSizeGB') { should be > 25 }`
- `properties.diskState`
`its('properties.diskState') { should cmp 'Attached' }`
- `properties.dnsSettings.appliedDnsServers.count`
`its('properties.dnsSettings.appliedDnsServers.count') { should eq 0 }`
- `properties.dnsSettings.dnsServers.count`
`its('properties.dnsSettings.dnsServers.count') { should eq 0 }`
- `properties.dnsSettings.domainNameLabel`
`its('properties.dnsSettings.domainNameLabel') { should match 'linux-external-1' }`
- `properties.enableAcceleratedNetworking`
`its('properties.enableAcceleratedNetworking') { should be false }`
- `properties.enableIPForwarding`
`its('properties.enableIPForwarding') { should be false }`
- `properties.encryption.keySource`
`its('properties.encryption.keySource') { should cmp 'Microsoft.Storage' }`
- `properties.encryption.services.blob.enabled`
`its('properties.encryption.services.blob.enabled') { should be true }`
- `properties.encryption.services.file.enabled`
`its('properties.encryption.services.file.enabled') { should be true }`
- `properties.hardwareProfile.vmSize`
`its('properties.hardwareProfile.vmSize') { should cmp 'Standard_DS2_v2' }`
- `properties.ipConfiguration.id`
`its('properties.ipConfiguration.id') { should match 'Inspec-NIC-2' }`
- `properties.ipConfigurations.count`
`its('properties.ipConfigurations.count') { should eq 1 }`
- `properties.networkProfile.networkInterfaces.count`
`its('properties.networkProfile.networkInterfaces.count') { should eq 1 }`
- `properties.osProfile.adminUsername`
`its('properties.osProfile.adminUsername') { should eq 'azure' }`
- `properties.osProfile.computerName`
`its('properties.osProfile.computerName') { should eq 'linux-external-1' }`
- `properties.osProfile.linuxConfiguration.disablePasswordAuthentication`
`its('properties.osProfile.linuxConfiguration.disablePasswordAuthentication') { should be false }`
- `properties.osProfile.windowsConfiguration.enableAutomaticUpdates`
`its('properties.osProfile.windowsConfiguration.enableAutomaticUpdates') { should be false }`
- `properties.osProfile.windowsConfiguration.provisionVMAgent`
`its('properties.osProfile.windowsConfiguration.provisionVMAgent') { should be true }`
- `properties.osType`
`its('properties.osType') { should cmp 'Linux' }`
- `properties.primaryLocation`
`its('properties.primaryLocation') { should cmp 'westeurope' }`
- `properties.provisioningState`
`its('properties.provisioningState') { should cmp 'Succeeded' }`
- `properties.publicIPAllocationMethod`
`its('properties.publicIPAllocationMethod') { should cmp 'Dynamic' }`
- `properties.statusOfPrimary`
`its('properties.statusOfPrimary') { should cmp 'available' }`
- `properties.storageProfile.dataDisks.count`
`its('properties.storageProfile.dataDisks.count') { should eq 1 }`
- `properties.storageProfile.imageReference.offer`
`its('properties.storageProfile.imageReference.offer') { should cmp 'UbuntuServer' }`
- `properties.storageProfile.imageReference.publisher`
`its('properties.storageProfile.imageReference.publisher') { should cmp 'Canonical' }`
- `properties.storageProfile.imageReference.sku`
`its('properties.storageProfile.imageReference.sku') { should cmp '16.04.0-LTS' }`
- `properties.storageProfile.osDisk.caching`
`its('properties.storageProfile.osDisk.caching') { should cmp 'ReadWrite' }`
- `properties.storageProfile.osDisk.createOption`
`its('properties.storageProfile.osDisk.createOption') { should cmp 'FromImage' }`
- `properties.storageProfile.osDisk.managedDisk.id`
`its('properties.storageProfile.osDisk.managedDisk.id') { should match 'Windows-Internal-OSDisk-MD' }`
- `properties.storageProfile.osDisk.managedDisk.storageAccountType`
`its('properties.storageProfile.osDisk.managedDisk.storageAccountType') { should cmp 'Standard_LRS' }`
- `properties.storageProfile.osDisk.name`
`its('properties.storageProfile.osDisk.name') { should cmp 'Windows-Internal-OSDisk-MD' }`
- `properties.storageProfile.osDisk.osType`
`its('properties.storageProfile.osDisk.osType') { should cmp 'Windows' }`
- `properties.subnets.count`
`its('properties.subnets.count') { should eq 1 }`
- `properties.supportsHttpsTrafficOnly`
`its('properties.supportsHttpsTrafficOnly') { should be false }`
- `properties.virtualMachine.id`
`its('properties.virtualMachine.id') { should match 'Linux-External-VM' }`
## Matchers
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).

View file

@ -7,8 +7,7 @@ control 'azure-generic-vm-linux-external-2.0' do
title 'Ensure External VM was built with the correct Image and has the correct properties'
# Ensure that the virtual machine has been created with the correct attributes
describe azure_generic_resource(group_name: 'Inspec-Azure',
name: 'Linux-External-VM') do
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Linux-External-VM') do
its('location') { should cmp 'westeurope' }
@ -43,5 +42,4 @@ control 'azure-generic-vm-linux-external-2.0' do
its('tags') { should include 'Description' }
its('Description_tag') { should match 'Externally facing' }
end
end

View file

@ -6,13 +6,12 @@ control 'azure-generic-vm-external-nic-2.0' do
title 'Ensure that the NIC for the external VM is correctly setup'
# Ensure that the virtual machine has been created with the correct attributes
describe azure_generic_resource(group_name: 'Inspec-Azure',
name: 'Inspec-NIC-2') do
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Inspec-NIC-2') do
# There should be no tags
it { should_not have_tags }
its('tags.count') { should eq 0 }
its('tags.count') { should eq 0 }
# The resources should be a network interface
its('type') { should cmp 'Microsoft.Network/networkInterfaces' }
@ -29,4 +28,4 @@ control 'azure-generic-vm-external-nic-2.0' do
its('properties.enableAcceleratedNetworking') { should be false }
its('properties.enableIPForwarding') { should be false }
end
end
end

View file

@ -7,8 +7,7 @@ control 'azure-generic-vm-linux-internal-2.0' do
title 'Ensure Internal VM was built with the correct Image and has the correct properties'
# Ensure that the virtual machine has been created with the correct attributes
describe azure_generic_resource(group_name: 'Inspec-Azure',
name: 'Linux-Internal-VM') do
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Linux-Internal-VM') do
its('location') { should cmp 'westeurope' }
@ -22,7 +21,7 @@ control 'azure-generic-vm-linux-internal-2.0' do
its('properties.storageProfile.osDisk.name') { should cmp 'Linux-Internal-OSDisk-MD' }
its('properties.storageProfile.osDisk.caching') { should cmp 'ReadWrite' }
# This machine has been setup with a Managed Disk for the OSDisk, ensure that
# This machine has been setup with a Managed Disk for the OSDisk, ensure that
# it is linked to the correct disk
its('properties.storageProfile.osDisk.managedDisk.id') { should match 'Linux-Internal-OSDisk-MD' }
@ -43,5 +42,4 @@ control 'azure-generic-vm-linux-internal-2.0' do
# There should be no tags on the machine
its('tags.count') { should eq 0 }
end
end

View file

@ -6,13 +6,12 @@ control 'azure-generic-vm-internal-nic-2.0' do
title 'Ensure that the NIC for the internal VM is correctly setup'
# Ensure that the virtual machine has been created with the correct attributes
describe azure_generic_resource(group_name: 'Inspec-Azure',
name: 'Inspec-NIC-1') do
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Inspec-NIC-1') do
# There should be no tags
it { should_not have_tags }
its('tags.count') { should eq 0 }
its('tags.count') { should eq 0 }
# The resources should be a network interface
its('type') { should cmp 'Microsoft.Network/networkInterfaces' }
@ -29,4 +28,4 @@ control 'azure-generic-vm-internal-nic-2.0' do
its('properties.enableAcceleratedNetworking') { should be false }
its('properties.enableIPForwarding') { should be false }
end
end
end

View file

@ -28,5 +28,4 @@ control 'azure-generic-managed-os-disk-1.0' do
# ensure the disk is attached
its('properties.diskState') { should cmp 'Attached' }
end
end
end

View file

@ -5,8 +5,7 @@ control 'azure-generic-network-security-group-1.0' do
impact 1.0
title 'Ensure that the NSG has been setup as expected'
describe azure_generic_resource(group_name: 'Inspec-Azure',
name: 'Inspec-NSG') do
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Inspec-NSG') do
# Check that the NSG is in the correct location
its('location') { should cmp 'westeurope' }
@ -18,4 +17,4 @@ control 'azure-generic-network-security-group-1.0' do
its('properties.provisioningState') { should eq 'Succeeded' }
end
end
end

View file

@ -9,8 +9,7 @@ control 'azure-generic-storage-account-2.0' do
# Get the storage account by type, this is because in the tests
# the storage account name is randomly generated so it cannot be known to perform
# these inspec tests
describe azure_generic_resource(group_name: 'Inspec-Azure',
type: 'Microsoft.Storage/storageAccounts') do
describe azure_generic_resource(group_name: 'Inspec-Azure', type: 'Microsoft.Storage/storageAccounts') do
its('total') { should be 1 }
# There should be no tags
@ -21,14 +20,14 @@ control 'azure-generic-storage-account-2.0' do
# Check that the blob and file services are enabled
its('properties.encryption.services.blob.enabled') { should be true }
its('properties.encryption.services.file.enabled') { should be true }
its('properties.encryption.keySource') { should cmp "Microsoft.Storage" }
its('properties.encryption.keySource') { should cmp 'Microsoft.Storage' }
its('properties.provisioningState') { should cmp "Succeeded" }
its('properties.provisioningState') { should cmp 'Succeeded' }
its("properties.primaryLocation") { should cmp "westeurope" }
its("properties.statusOfPrimary") { should cmp "available" }
its('properties.primaryLocation') { should cmp 'westeurope' }
its('properties.statusOfPrimary') { should cmp 'available' }
# Determine if it only supports HTTPS traffic
its('properties.supportsHttpsTrafficOnly') { should be false }
end
end
end

View file

@ -18,10 +18,10 @@ control 'azure-generic-virtual-network-2.0' do
# Ensure that the address prefix for the VNet is correct
# This will return an array so the `include` matcher needs to be used to
# see if the specified address prefix is present
its('properties.addressSpace.addressPrefixes') { should include '10.1.1.0/24'}
its('properties.addressSpace.addressPrefixes') { should include '10.1.1.0/24' }
# There should be one subnet
its('properties.subnets.count') { should eq 1 }
end
end

View file

@ -22,7 +22,7 @@ control 'azure-generic-vm-windows-internal-2.0' do
its('properties.storageProfile.osDisk.name') { should cmp 'Windows-Internal-OSDisk-MD' }
its('properties.storageProfile.osDisk.caching') { should cmp 'ReadWrite' }
# This machine has been setup with a Managed Disk for the OSDisk, ensure that
# This machine has been setup with a Managed Disk for the OSDisk, ensure that
# it is linked to the correct disk
its('properties.storageProfile.osDisk.managedDisk.id') { should match 'Windows-Internal-OSDisk-MD' }
its('properties.storageProfile.osDisk.managedDisk.storageAccountType') { should cmp 'Standard_LRS' }