Azure / arm-ttk

Azure Resource Manager Template Toolkit
https://aka.ms/arm-ttk
MIT License
441 stars 188 forks source link

Bug with "PasswordBoxes-Must-Have-Min-Length" test #742

Closed galiacheng closed 1 year ago

galiacheng commented 1 year ago

The test failed when PasswordBoxes has length that is less than min length, reporting error like PasswordBox 'dbAdminPassword' regex is invalid: A parameter cannot be found that matches parameter name 'TargetObject'.

Expected result is a warning, but not a failure.

To reproduce the error:

  1. Test case createUiDefinition.json
    {
    "$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": "dbAdminPassword",
                "type": "Microsoft.Common.PasswordBox",
                "label": {
                    "password": "Password",
                    "confirmPassword": "Confirm password"
                },
                "toolTip": "Admin password for the database",
                "constraints": {
                    "required": true,
                    "regex": "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)[A-Za-z\\d\\$\\&\\+\\,:\\=\\?@#|'.\\^\\*!\\-_~/'\\[\\]\\{\\}\"]{8,}$",
                    "validationMessage": "The password must contain at least 8 characters, with at least 1 uppercase letter, 1 lowercase letter and 1 number, and special characters, but should not contain > < ( ) % ; \\."
                },
                "options": {
                    "hideConfirmation": false
                },
                "visible": true
            }
        ],
        "steps": []
    }
    }

    mainTemplate.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "dbAdminPassword": {
            "type": "secureObject"
        }
    },
    "resources": [

    ],
    "outputs": {
        "dbAdminPassword": {
            "type": "secureObject",
            "value": "[parameters('dbAdminPassword')]"
        }
    }
}

Command to run the test case:

sh Test-AzTemplate.sh -TemplatePath $testcasePath -Test PasswordBoxes-Must-Have-Min-Length

Actual result:

Validating createUiDefinition.json                                                                                         
  PasswordBoxes Must Have Min Length                                                                                              
    [-] PasswordBoxes Must Have Min Length (118 ms)                                                                               
        PasswordBox 'dbAdminPassword' regex is invalid: A parameter cannot be found that matches parameter name 'TargetObj        
ect'. Line: 9, Column: 18  

Expected result: a warning.

Validating createUiDefinition.json                                                                                                
  PasswordBoxes Must Have Min Length                                                                                                     
    [?] PasswordBoxes Must Have Min Length (91 ms)                                                                                       
        PasswordBox 'dbAdminPassword' regex does not have a minimum length of 12 
galiacheng commented 1 year ago

The exception is caused by line 50 in arm-ttk/testcases/CreateUIDefinition/PasswordBoxes-Must-Have-Min-Length.test.ps1.

If I changed line 50 in arm-ttk/testcases/CreateUIDefinition/PasswordBoxes-Must-Have-Min-Length.test.ps1

from

Write-Warning "PasswordBox '$($pwb.Name)' regex does not have a minimum length of $PasswordMinLength" -TargetObject $pwb

to

Write-Warning "PasswordBox '$($pwb.Name)' regex does not have a minimum length of $PasswordMinLength"

The error is resolved.