diff --git a/arm-ttk/testcases/CreateUIDefinition/Password-Textboxes-Must-Be-Used-For-Password-Parameters.test.ps1 b/arm-ttk/testcases/CreateUIDefinition/Password-Textboxes-Must-Be-Used-For-Password-Parameters.test.ps1 index 5930aef6..1ca315b5 100644 --- a/arm-ttk/testcases/CreateUIDefinition/Password-Textboxes-Must-Be-Used-For-Password-Parameters.test.ps1 +++ b/arm-ttk/testcases/CreateUIDefinition/Password-Textboxes-Must-Be-Used-For-Password-Parameters.test.ps1 @@ -25,8 +25,17 @@ $passwordBoxes = $CreateUIDefinitionObject | foreach ($pwb in $passwordBoxes) { # Loop over each password box $controlName = $pwb.Name # and find the output it maps to. $theOutput = foreach ($out in $CreateUIDefinitionObject.parameters.outputs.psobject.properties) { - if (($out.Value -like "*steps(*$controlName*") -or ($out.Value -like "*basics(*$controlName*")) { - $out; break + $outputValueType = $out.Value.GetType().Name + if ($outputValueType -eq "PSCustomObject") { + $outputJson = $out.Value | ConvertTo-Json -Compress + if (($outputJson -like "*steps(*$controlName*") -or ($outputJson -like "*basics(*$controlName*")) { + $out; break + } + } + else { + if (($out.Value -like "*steps(*$controlName*") -or ($out.Value -like "*basics(*$controlName*")) { + $out; break + } } } @@ -39,13 +48,13 @@ foreach ($pwb in $passwordBoxes) { # Loop over each password box # If we couldn't find it, write an error. if (-not $MainTemplateParam) { - Write-Error "Password box $($pwb.Name) is missing from main template parameters "-TargetObject $pwb + Write-Error "Password box $($pwb.Name) linked to output $($theOutput.Name) is missing from main template parameters "-TargetObject $pwb continue } # If the main template parameter type is neither a Secure String nor a Secure Object if (($MainTemplateParam.type -ne 'SecureString') -and ($MainTemplateParam.type -ne 'SecureObject')) { # write an error. - Write-Error "PasswordBox controls must use secureString or secureObject parameter types. The Main template parameter '$($pwb.Name)' is a '$($MainTemplateParam.type)'" -TargetObject @($pwb, $MainTemplateParam) + Write-Error "PasswordBox controls must use secureString or secureObject parameter types. The Main template parameter '$($theOutput.Name)' linked to '$($pwb.Name)' is a '$($MainTemplateParam.type)'" -TargetObject @($pwb, $MainTemplateParam) } } \ No newline at end of file diff --git a/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/azuredeploy.json b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/azuredeploy.json new file mode 100644 index 00000000..7172fed1 --- /dev/null +++ b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/azuredeploy.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "Location." + } + }, + "certificates": { + "type": "object", + "defaultValue": [ + { + "password": "password" + } + ], + "metadata": { + "description": "Backend data." + } + } + }, + "variables": { + }, + "resources": [ + ], + "outputs": { + "location": { + "type": "string", + "value": "[parameters('location')]" + } + } +} diff --git a/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/createUiDefinition.json b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/createUiDefinition.json new file mode 100644 index 00000000..dae57d24 --- /dev/null +++ b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Fail/NotSecureObject/createUiDefinition.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#", + "handler": "Microsoft.Azure.CreateUIDef", + "version": "0.1.2-preview", + "parameters": { + "basics": [ + { + "name": "settings", + "label": "Settings", + "bladeTitle": "Settings", + "elements": [ + { + "type": "Microsoft.Common.Section", + "name": "section", + "label": "Section Settings", + "visible": "true", + "elements": [ + { + "type": "Microsoft.Common.PasswordBox", + "name": "passwordBox", + "label": { + "password": "Password", + "confirmPassword": "Confirm password" + }, + "toolTip": "Password for password box", + "visible": true, + "constraints": { + "required": true, + "regex": "^[\\S]{10,25}$", + "validationMessage": "Password must be between 10 and 25 characters." + }, + "options": { + "hideConfirmation": false + } + } + ] + } + ] + } + ], + "outputs": { + "Location": "[location()]", + "certificates": { + "0": { + "password": "[coalesce(steps('settings').section.passwordBox, 'NA')]" + } + } + } + } +} diff --git a/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/azuredeploy.json b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/azuredeploy.json new file mode 100644 index 00000000..ee603930 --- /dev/null +++ b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/azuredeploy.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "Location." + } + }, + "certificates": { + "type": "secureObject", + "defaultValue": [ + { + "password": "password" + } + ], + "metadata": { + "description": "Backend data." + } + } + }, + "variables": { + }, + "resources": [ + ], + "outputs": { + "location": { + "type": "string", + "value": "[parameters('location')]" + } + } +} \ No newline at end of file diff --git a/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/createUiDefinition.json b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/createUiDefinition.json new file mode 100644 index 00000000..1404cfb8 --- /dev/null +++ b/unit-tests/Password-Textboxes-Must-Be-Used-For-Password-Parameters/Pass/SecureObject/createUiDefinition.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#", + "handler": "Microsoft.Azure.CreateUIDef", + "version": "0.1.2-preview", + "parameters": { + "basics": [ + { + "name": "settings", + "label": "Settings", + "bladeTitle": "Settings", + "elements": [ + { + "type": "Microsoft.Common.Section", + "name": "section", + "label": "Section Settings", + "visible": "true", + "elements": [ + { + "type": "Microsoft.Common.PasswordBox", + "name": "passwordBox", + "label": { + "password": "Password", + "confirmPassword": "Confirm password" + }, + "toolTip": "Password for password box", + "visible": true, + "constraints": { + "required": true, + "regex": "^[\\S]{10,25}$", + "validationMessage": "Password must be between 10 and 25 characters." + }, + "options": { + "hideConfirmation": false + } + } + ] + } + ] + } + ], + "outputs": { + "Location": "[location()]", + "certificates": { + "0": { + "password": "[coalesce(steps('settings').section.passwordBox, 'NA')]" + } + } + } + } +} \ No newline at end of file