-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8617507
commit a36a45a
Showing
6 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
arm-ttk/testcases/deploymentTemplate/URIs-Should-Be-Properly-Constructed.test.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
unit-tests/URIs-Should-Be-Properly-Constructed/Fail/URI-Using-Concat.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]" | ||
} | ||
] | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
unit-tests/URIs-Should-Be-Properly-Constructed/Fail/URI-Using-Format.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]" | ||
} | ||
] | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
unit-tests/URIs-Should-Be-Properly-Constructed/Pass/Concat-in-URL.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]" | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
unit-tests/URIs-Should-Be-Properly-Constructed/Pass/MarketplaceSample.path.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
..\..\Common\Pass\100-marketplace-sample |
6 changes: 6 additions & 0 deletions
6
unit-tests/URIs-Should-Be-Properly-Constructed/URIs-Should-Be-Properly-Constructed.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|