Skip to content

Commit 21aee44

Browse files
committed
Change resourceId() to url encode name so names can contain arbitrary characters
1 parent e59d9e4 commit 21aee44

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

dsc/tests/dsc_functions.tests.ps1

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Describe 'tests for function expressions' {
123123
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject2'))]"; expected = [pscustomobject]@{
124124
shared = [pscustomobject]@{ value = 42; flag = $true }
125125
level = 1
126-
}
126+
}
127127
}
128128
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject3'))]"; expected = [pscustomobject]@{ level = 1 } }
129129
@{ expression = "[intersection(parameters('nestedObject1'), parameters('nestedObject2'), parameters('nestedObject4'))]"; expected = [pscustomobject]@{ level = 1 } }
@@ -948,10 +948,10 @@ Describe 'tests for function expressions' {
948948
@{ testInput = ' ' }
949949
) {
950950
param($testInput)
951-
951+
952952
$expected = [Uri]::EscapeDataString($testInput)
953953
$expression = "[uriComponent('$($testInput -replace "'", "''")')]"
954-
954+
955955
$config_yaml = @"
956956
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
957957
resources:
@@ -963,13 +963,13 @@ Describe 'tests for function expressions' {
963963
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
964964
$out.results[0].result.actualState.output | Should -BeExactly $expected
965965
}
966-
966+
967967
It 'uriComponent function works with concat' {
968968
$input1 = 'hello'
969969
$input2 = ' '
970970
$input3 = 'world'
971971
$expected = [Uri]::EscapeDataString($input1 + $input2 + $input3)
972-
972+
973973
$config_yaml = @"
974974
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
975975
resources:
@@ -995,10 +995,10 @@ Describe 'tests for function expressions' {
995995
@{ testInput = '100%25' }
996996
) {
997997
param($testInput)
998-
998+
999999
$expected = [Uri]::UnescapeDataString($testInput)
10001000
$expression = "[uriComponentToString('$($testInput -replace "'", "''")')]"
1001-
1001+
10021002
$config_yaml = @"
10031003
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
10041004
resources:
@@ -1010,11 +1010,11 @@ Describe 'tests for function expressions' {
10101010
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
10111011
$out.results[0].result.actualState.output | Should -BeExactly $expected
10121012
}
1013-
1013+
10141014
It 'uriComponentToString function works with round-trip encoding' {
10151015
$original = 'hello world'
10161016
$expected = $original
1017-
1017+
10181018
$config_yaml = @"
10191019
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
10201020
resources:
@@ -1026,11 +1026,11 @@ Describe 'tests for function expressions' {
10261026
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
10271027
$out.results[0].result.actualState.output | Should -BeExactly $expected
10281028
}
1029-
1029+
10301030
It 'uriComponentToString function works with nested round-trip' {
10311031
$original = 'user+tag@example.com'
10321032
$expected = $original
1033-
1033+
10341034
$config_yaml = @"
10351035
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
10361036
resources:
@@ -1042,13 +1042,13 @@ Describe 'tests for function expressions' {
10421042
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
10431043
$out.results[0].result.actualState.output | Should -BeExactly $expected
10441044
}
1045-
1045+
10461046
It 'uriComponentToString function works with concat' {
10471047
$input1 = 'hello'
10481048
$input2 = '%20'
10491049
$input3 = 'world'
10501050
$expected = [Uri]::UnescapeDataString($input1 + $input2 + $input3)
1051-
1051+
10521052
$config_yaml = @"
10531053
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
10541054
resources:
@@ -1077,7 +1077,7 @@ Describe 'tests for function expressions' {
10771077
@{ data = @{ nested = @{ value = 123 } }; accessor = '.nested.value'; expected = 123 }
10781078
) {
10791079
param($data, $accessor, $expected)
1080-
1080+
10811081
$jsonString = ConvertTo-Json -Compress -InputObject $data
10821082
$expression = "[json(''$($jsonString)'')$accessor]"
10831083

@@ -1152,7 +1152,7 @@ Describe 'tests for function expressions' {
11521152
@{ base = 'http://192.168.1.1/'; relative = 'api/v1'; expected = 'http://192.168.1.1/api/v1' }
11531153
) {
11541154
param($base, $relative, $expected)
1155-
1155+
11561156
$expression = "[uri('$($base -replace "'", "''")','$($relative -replace "'", "''")')]"
11571157
$config_yaml = @"
11581158
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
@@ -1188,4 +1188,20 @@ Describe 'tests for function expressions' {
11881188
$errorContent = Get-Content $TestDrive/error.log -Raw
11891189
$errorContent | Should -Match ([regex]::Escape($expectedError))
11901190
}
1191+
1192+
It 'resourceId allows for arbitrary characters in names including unicode' {
1193+
$name = 'My Resource @123/!#$%^&*()[]{}-+=;`~'
1194+
$config_yaml = @"
1195+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
1196+
resources:
1197+
- name: "$name"
1198+
type: Microsoft.DSC.Debug/Echo
1199+
properties:
1200+
output: "[resourceId('Microsoft.DSC.Debug/Echo', '$name')]"
1201+
"@
1202+
$out = dsc config get -i $config_yaml | ConvertFrom-Json
1203+
$LASTEXITCODE | Should -Be 0
1204+
$expected = "Microsoft.DSC.Debug/Echo:$([Uri]::EscapeDataString($name))"
1205+
$out.results[0].result.actualState.output | Should -BeExactly $expected
1206+
}
11911207
}

0 commit comments

Comments
 (0)