Skip to content

Commit a36a45a

Browse files
Fixing #417: Re-adding URI format test (#564)
* 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 <[email protected]>
1 parent 8617507 commit a36a45a

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<#
2+
.Synopsis
3+
Ensures that URIs are properly constructed
4+
.Description
5+
Ensures that properties named URI or URL are properly constructed, and do not use and -FunctionNotAllowedInUri
6+
#>
7+
param(
8+
# The template object
9+
[Parameter(Mandatory = $true, Position = 0)]
10+
[PSObject]
11+
$TemplateObject,
12+
13+
# A list of functions not allowed in the uri. By default, format and concat.
14+
[string[]]
15+
$FunctionNotAllowedInUri = @('format', 'concat')
16+
)
17+
18+
# commenting out the test due to # 417
19+
$foundObjects = Find-JsonContent -InputObject $TemplateObject -Key 'ur[il]$' -Match
20+
21+
foreach ($found in $foundObjects) { # Walk over each found object
22+
foreach ($prop in $found.psobject.properties) { # then walk thru each property
23+
if ($prop.Name -notmatch 'ur[il]$') { continue } # skipping ones that are not uri/url
24+
if (-not $prop.value | ?<ARM_Template_Expression>) { continue } # and ones that do not contain an expression.
25+
26+
27+
28+
# If the value contained expressions, but not the function uri
29+
$foundBadFunction = $prop.Value | ?<ARM_Template_Function> -FunctionName ($FunctionNotAllowedInUri -join '|')
30+
$foundUriFunction = $prop.Value | ?<ARM_Template_Function> -FunctionName uri
31+
if (
32+
($foundBadFunction -and -not $foundUriFunction) -or
33+
$foundBadFunction.Index -lt $foundUriFunction.Index
34+
) {
35+
Write-Error "Function'$($foundBadFunction.Groups['FunctionName'].Value)' found within '$($prop.Name)" -TargetObject $found -ErrorId "URI.Improperly.Constructed"
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"resources": [
4+
{
5+
"aUri": "[concat('foo', 'bar')]"
6+
}
7+
]
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"resources": [
4+
{
5+
"aUri": "[format('foo {0}', 'bar')]"
6+
}
7+
]
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"outputs": {
4+
"ServerUrl": {
5+
"type": "string",
6+
"value": "[uri(concat('http://', reference(variables('publicIPAddressName')).dnsSettings.fqdn), 'somepath')]"
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
..\..\Common\Pass\100-marketplace-sample
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#requires -module arm-ttk
3+
. $PSScriptRoot\..\arm-ttk.test.functions.ps1
4+
Test-TTK $psScriptRoot
5+
return
6+

0 commit comments

Comments
 (0)