Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure Defender to E2E testing #28

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testing/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ settings.json
tmp/
bin/*
!bin/connectedk8s-1.0.0-py3-none-any.whl
!bin/k8s_extension-0.2.0-py3-none-any.whl
!bin/k8s_extension-0.3.0-py3-none-any.whl
!bin/k8s_extension_private-0.1.0-py3-none-any.whl
!bin/connectedk8s-values.yaml
*.xml
Binary file removed testing/bin/k8s_extension-0.2.0-py3-none-any.whl
Binary file not shown.
Binary file added testing/bin/k8s_extension-0.3.0-py3-none-any.whl
Binary file not shown.
4 changes: 2 additions & 2 deletions testing/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"arcClusterName": "<arcClusterName>",

"extensionVersion": {
"k8s-extension": "0.2.0",
"k8s-extension": "0.3.0",
"k8s-extension-private": "0.1.0",
"connectedk8s": "0.3.5"
"connectedk8s": "1.0.0"
}
}
93 changes: 93 additions & 0 deletions testing/test/extensions/public/AzureDefender.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Describe 'Azure Defender Testing' {
BeforeAll {
$extensionType = "microsoft.azuredefender.kubernetes"
$extensionName = "microsoft.azuredefender.kubernetes"
$extensionAgentNamespace = "azuredefender"

. $PSScriptRoot/../../helper/Constants.ps1
. $PSScriptRoot/../../helper/Helper.ps1
}

It 'Creates the extension and checks that it onboards correctly' {
$output = az $Env:K8sExtensionName create -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters --extension-type $extensionType -n $extensionName
$? | Should -BeTrue

$output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue

$isAutoUpgradeMinorVersion = ($output | ConvertFrom-Json).autoUpgradeMinorVersion
$isAutoUpgradeMinorVersion.ToString() -eq "True" | Should -BeTrue

# Loop and retry until the extension installs
$n = 0
do
{
# Only check the extension config, not the pod since this doesn't bring up pods
if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) {
break
}
Start-Sleep -Seconds 10
$n += 1
} while ($n -le $MAX_RETRY_ATTEMPTS)
$n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
}

It "Performs a show on the extension" {
$output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue
$output | Should -Not -BeNullOrEmpty
}

It "Runs an update on the extension on the cluster" {
Set-ItResult -Skipped -Because "Update is not a valid scenario for now"

# az $Env:K8sExtensionName update -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName --auto-upgrade-minor-version false
# $? | Should -BeTrue

# $output = az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
# $? | Should -BeTrue

# $isAutoUpgradeMinorVersion = ($output | ConvertFrom-Json).autoUpgradeMinorVersion
# $isAutoUpgradeMinorVersion.ToString() -eq "False" | Should -BeTrue

# # Loop and retry until the extension config updates
# $n = 0
# do
# {
# $isAutoUpgradeMinorVersion = (Get-ExtensionData $extensionName).spec.autoUpgradeMinorVersion
# if (!$isAutoUpgradeMinorVersion) { #autoUpgradeMinorVersion doesn't exist in ExtensionConfig CRD if false
# if (Get-ExtensionStatus $extensionName -eq $SUCCESS_MESSAGE) {
# if (Get-PodStatus $extensionAgentName -Namespace $extensionAgentNamespace -eq $POD_RUNNING) {
# break
# }
# }
# }
# Start-Sleep -Seconds 10
# $n += 1
# } while ($n -le $MAX_RETRY_ATTEMPTS)
# $n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
}

It "Lists the extensions on the cluster" {
$output = az $Env:K8sExtensionName list -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters
$? | Should -BeTrue

$extensionExists = $output | ConvertFrom-Json | Where-Object { $_.extensionType -eq $extensionType }
$extensionExists | Should -Not -BeNullOrEmpty
}

It "Deletes the extension from the cluster" {
az $Env:K8sExtensionName delete -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeTrue

# Extension should not be found on the cluster
az $Env:K8sExtensionName show -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters -n $extensionName
$? | Should -BeFalse
}

It "Performs another list after the delete" {
$output = az $Env:K8sExtensionName list -c $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --cluster-type connectedClusters
$extensionExists = $output | ConvertFrom-Json | Where-Object { $_.extensionType -eq $extensionName }
$extensionExists | Should -BeNullOrEmpty
}
}