Skip to content

Commit

Permalink
Fixing #417: Re-adding URI format test (#564)
Browse files Browse the repository at this point in the history
* Fixing #417:  Re-adding URI format test and ensuring that functions are allowed within a uri

* Fixing unknown api version in deployments (false negative)

* Delete URI-Using-Concat.json

Co-authored-by: James Brundage <@github.com>
Co-authored-by: Brian Moore <bmoore@microsoft.com>
  • Loading branch information
StartAutomating and bmoore-msft authored Jan 14, 2022
1 parent 8617507 commit a36a45a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.Synopsis
Ensures that URIs are properly constructed
.Description
Ensures that properties named URI or URL are properly constructed, and do not use and -FunctionNotAllowedInUri
#>
param(
# The template object
[Parameter(Mandatory = $true, Position = 0)]
[PSObject]
$TemplateObject,

# A list of functions not allowed in the uri. By default, format and concat.
[string[]]
$FunctionNotAllowedInUri = @('format', 'concat')
)

# commenting out the test due to # 417
$foundObjects = Find-JsonContent -InputObject $TemplateObject -Key 'ur[il]$' -Match

foreach ($found in $foundObjects) { # Walk over each found object
foreach ($prop in $found.psobject.properties) { # then walk thru each property
if ($prop.Name -notmatch 'ur[il]$') { continue } # skipping ones that are not uri/url
if (-not $prop.value | ?<ARM_Template_Expression>) { continue } # and ones that do not contain an expression.



# If the value contained expressions, but not the function uri
$foundBadFunction = $prop.Value | ?<ARM_Template_Function> -FunctionName ($FunctionNotAllowedInUri -join '|')
$foundUriFunction = $prop.Value | ?<ARM_Template_Function> -FunctionName uri
if (
($foundBadFunction -and -not $foundUriFunction) -or
$foundBadFunction.Index -lt $foundUriFunction.Index
) {
Write-Error "Function'$($foundBadFunction.Groups['FunctionName'].Value)' found within '$($prop.Name)" -TargetObject $found -ErrorId "URI.Improperly.Constructed"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"resources": [
{
"aUri": "[concat('foo', 'bar')]"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"resources": [
{
"aUri": "[format('foo {0}', 'bar')]"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"outputs": {
"ServerUrl": {
"type": "string",
"value": "[uri(concat('http://', reference(variables('publicIPAddressName')).dnsSettings.fqdn), 'somepath')]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
..\..\Common\Pass\100-marketplace-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#requires -module arm-ttk
. $PSScriptRoot\..\arm-ttk.test.functions.ps1
Test-TTK $psScriptRoot
return

0 comments on commit a36a45a

Please sign in to comment.