Skip to content

Commit b549209

Browse files
committed
Re-record tests
1 parent 886184b commit b549209

File tree

35 files changed

+13395
-8833
lines changed

35 files changed

+13395
-8833
lines changed

src/Resources/ResourceManager/Components/Constants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ public static class Constants
8787
/// <summary>
8888
/// The default policy definition API version.
8989
/// </summary>
90-
public static readonly string PolicyDefinitionApiVersion = "2019-09-01";
90+
public static readonly string PolicyDefinitionApiVersion = "2020-09-01";
9191

9292
/// <summary>
9393
/// The default policy set definition API version.
9494
/// </summary>
95-
public static readonly string PolicySetDefintionApiVersion = "2019-09-01";
95+
public static readonly string PolicySetDefintionApiVersion = "2020-09-01";
9696

9797
/// <summary>
9898
/// The default policy assignment API version.
9999
/// </summary>
100-
public static readonly string PolicyAssignmentApiVersion = "2019-09-01";
100+
public static readonly string PolicyAssignmentApiVersion = "2020-09-01";
101101

102102
/// <summary>
103103
/// The default policy exemption API version.

src/Resources/ResourceManager/Implementation/Policy/PsNonComplianceMessage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
/// </summary>
99
public class PsNonComplianceMessage
1010
{
11+
/// <summary>
12+
/// Creates an instance of <see cref="PsNonComplianceMessage"/>.
13+
/// </summary>
14+
public PsNonComplianceMessage()
15+
{
16+
}
17+
1118
/// <summary>
1219
/// Creates an instance of <see cref="PsNonComplianceMessage"/> from the equivalent model representation.
1320
/// </summary>

src/Resources/Resources.Test/ScenarioTests/PolicyTests.ps1

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,23 +382,66 @@ function Test-PolicyAssignmentCRUD
382382
$rg = New-AzResourceGroup -Name $rgname -Location "west us"
383383
$policy = New-AzPolicyDefinition -Name $policyName -Policy "$TestOutputRoot\SamplePolicyDefinition.json" -Description $description
384384

385+
$nonComplianceMessages = @(@{ Message = "General message" })
386+
385387
# assign the policy definition to the resource group, get the assignment back and validate
386-
$actual = New-AzPolicyAssignment -Name testPA -PolicyDefinition $policy -Scope $rg.ResourceId -Description $description
388+
$actual = New-AzPolicyAssignment -Name testPA -PolicyDefinition $policy -Scope $rg.ResourceId -Description $description -NonComplianceMessage $nonComplianceMessages
387389
$expected = Get-AzPolicyAssignment -Name testPA -Scope $rg.ResourceId
388390
Assert-AreEqual $expected.Name $actual.Name
389391
Assert-AreEqual Microsoft.Authorization/policyAssignments $actual.ResourceType
390392
Assert-AreEqual $expected.PolicyAssignmentId $actual.PolicyAssignmentId
391393
Assert-AreEqual $expected.Properties.PolicyDefinitionId $policy.PolicyDefinitionId
392394
Assert-AreEqual $expected.Properties.Scope $rg.ResourceId
395+
Assert-AreEqual 1 $expected.Properties.NonComplianceMessages.Length
396+
Assert-AreEqual "General message" $expected.Properties.NonComplianceMessages[0].Message
393397

394398
# get it back by id and validate
395399
$actualId = Get-AzPolicyAssignment -Id $actual.ResourceId
396400
Assert-AreEqual $actual.ResourceId $actualId.ResourceId
401+
Assert-AreEqual 1 $actualId.Properties.NonComplianceMessages.Length
402+
Assert-AreEqual "General message" $actualId.Properties.NonComplianceMessages[0].Message
403+
404+
$nonComplianceMessages += @{
405+
Message = "Specific message 1"
406+
PolicyDefinitionReferenceId = "ref1"
407+
}
408+
409+
# create it again with two non-compliance messages
410+
$actual = New-AzPolicyAssignment -Name testPA -PolicyDefinition $policy -Scope $rg.ResourceId -Description $description -NonComplianceMessage $nonComplianceMessages
411+
$expected = Get-AzPolicyAssignment -Name testPA -Scope $rg.ResourceId
412+
Assert-AreEqual 2 $expected.Properties.NonComplianceMessages.Length
413+
Assert-AreEqual "Specific message 1" $expected.Properties.NonComplianceMessages[1].Message
414+
Assert-AreEqual "ref1" $expected.Properties.NonComplianceMessages[1].PolicyDefinitionReferenceId
397415

398416
# update the policy assignment, validate the result
399417
$set = Set-AzPolicyAssignment -Id $actualId.ResourceId -DisplayName testDisplay
400418
Assert-AreEqual testDisplay $set.Properties.DisplayName
401419

420+
$nonComplianceMessages = @(@{ Message = "General non-compliance message" })
421+
422+
# update the policy assignment's non-compliance messages with one new general message
423+
$set = Set-AzPolicyAssignment -Id $actualId.ResourceId -NonComplianceMessage $nonComplianceMessages
424+
Assert-AreEqual 1 $set.Properties.NonComplianceMessages.Length
425+
Assert-AreEqual "General non-compliance message" $set.Properties.NonComplianceMessages[0].Message
426+
Assert-Null $set.Properties.NonComplianceMessages[0].PolicyDefinitionReferenceId
427+
428+
$nonComplianceMessages = @(
429+
@{
430+
Message = "Specific message 1"
431+
PolicyDefinitionReferenceId = "ref1"
432+
},
433+
@{
434+
Message = "Specific message 2"
435+
PolicyDefinitionReferenceId = "ref2"
436+
}
437+
)
438+
439+
# update the policy assignment's non-compliance message with two specific messages
440+
$set = Set-AzPolicyAssignment -Id $actualId.ResourceId -NonComplianceMessage $nonComplianceMessages
441+
Assert-AreEqual 2 $set.Properties.NonComplianceMessages.Length
442+
Assert-AreEqual "Specific message 2" $set.Properties.NonComplianceMessages[1].Message
443+
Assert-AreEqual "ref2" $set.Properties.NonComplianceMessages[1].PolicyDefinitionReferenceId
444+
402445
# make another policy assignment, ensure both are present in resource group scope listing
403446
$expected = New-AzPolicyAssignment -Name test2 -Scope $rg.ResourceId -PolicyDefinition $policy -Description $description
404447
$list = Get-AzPolicyAssignment -Scope $rg.ResourceId | ?{ $_.Name -in @('testPA', 'test2') }

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestGetBuiltinsByName.json

Lines changed: 4485 additions & 2685 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestGetCmdletFilterParameter.json

Lines changed: 126 additions & 62 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestGetPolicyAssignmentParameters.json

Lines changed: 178 additions & 166 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestGetPolicyDefinitionParameters.json

Lines changed: 1573 additions & 272 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestGetPolicySetDefinitionParameters.json

Lines changed: 280 additions & 259 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.PolicyTests/TestNewPolicyAssignmentParameters.json

Lines changed: 114 additions & 102 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"Entries": [
33
{
4-
"RequestUri": "/subscriptions/fb3a3d6b-44c8-44f5-88c9-b20917c9b96b/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2019-09-01",
5-
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZmIzYTNkNmItNDRjOC00NGY1LTg4YzktYjIwOTE3YzliOTZiL3Byb3ZpZGVycy9NaWNyb3NvZnQuQXV0aG9yaXphdGlvbi9wb2xpY3lkZWZpbml0aW9ucy9zb21lTmFtZT9hcGktdmVyc2lvbj0yMDE5LTA5LTAx",
4+
"RequestUri": "/subscriptions/f67cc918-f64f-4c3f-aa24-a855465f9d41/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2020-09-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZjY3Y2M5MTgtZjY0Zi00YzNmLWFhMjQtYTg1NTQ2NWY5ZDQxL3Byb3ZpZGVycy9NaWNyb3NvZnQuQXV0aG9yaXphdGlvbi9wb2xpY3lkZWZpbml0aW9ucy9zb21lTmFtZT9hcGktdmVyc2lvbj0yMDIwLTA5LTAx",
66
"RequestMethod": "PUT",
7-
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\"\r\n }\r\n}",
7+
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\",\r\n \"policyType\": \"Custom\"\r\n }\r\n}",
88
"RequestHeaders": {
99
"User-Agent": [
10-
"AzurePowershell/v1.0.0",
11-
"PSVersion/v6.2.3"
10+
"AzurePowershell/v5.4.0",
11+
"PSVersion/v6.2.4"
1212
],
1313
"ParameterSetName": [
1414
"NameParameterSet"
@@ -20,27 +20,30 @@
2020
"application/json; charset=utf-8"
2121
],
2222
"Content-Length": [
23-
"136"
23+
"165"
2424
]
2525
},
2626
"ResponseHeaders": {
2727
"Cache-Control": [
28-
"no-cache"
28+
"no-store, no-cache"
2929
],
3030
"Pragma": [
3131
"no-cache"
3232
],
33-
"x-ms-request-id": [
34-
"westus:6344fa9e-c9a1-4cab-843d-d3968e578d78"
35-
],
3633
"x-ms-ratelimit-remaining-subscription-writes": [
3734
"1199"
3835
],
36+
"Server": [
37+
"Kestrel"
38+
],
39+
"x-ms-request-id": [
40+
"71abfa4f-4eb9-4470-95ee-1aa3e2fc47f5"
41+
],
3942
"x-ms-correlation-request-id": [
40-
"ff361dfc-faf9-452f-bf02-4741fd3fb784"
43+
"71abfa4f-4eb9-4470-95ee-1aa3e2fc47f5"
4144
],
4245
"x-ms-routing-request-id": [
43-
"WESTUS:20200109T002834Z:ff361dfc-faf9-452f-bf02-4741fd3fb784"
46+
"WESTUS2:20210517T224325Z:71abfa4f-4eb9-4470-95ee-1aa3e2fc47f5"
4447
],
4548
"Strict-Transport-Security": [
4649
"max-age=31536000; includeSubDomains"
@@ -49,13 +52,13 @@
4952
"nosniff"
5053
],
5154
"Date": [
52-
"Thu, 09 Jan 2020 00:28:34 GMT"
55+
"Mon, 17 May 2021 22:43:25 GMT"
5356
],
5457
"Content-Length": [
55-
"166"
58+
"176"
5659
],
5760
"Content-Type": [
58-
"application/json; charset=utf-8"
61+
"application/json"
5962
],
6063
"Expires": [
6164
"-1"
@@ -64,18 +67,18 @@
6467
"0"
6568
]
6669
},
67-
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidPolicyRule\",\r\n \"message\": \"Failed to parse policy rule: 'Could not find member 'someThing' on object of type 'PolicyRule'. Path 'someThing'.'.\"\r\n }\r\n}",
70+
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidPolicyRule\",\r\n \"message\": \"Failed to parse policy rule: 'Could not find member 'someThing' on object of type 'PolicyRuleDefinition'. Path 'someThing'.'.\"\r\n }\r\n}",
6871
"StatusCode": 400
6972
},
7073
{
71-
"RequestUri": "/subscriptions/fb3a3d6b-44c8-44f5-88c9-b20917c9b96b/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2019-09-01",
72-
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZmIzYTNkNmItNDRjOC00NGY1LTg4YzktYjIwOTE3YzliOTZiL3Byb3ZpZGVycy9NaWNyb3NvZnQuQXV0aG9yaXphdGlvbi9wb2xpY3lkZWZpbml0aW9ucy9zb21lTmFtZT9hcGktdmVyc2lvbj0yMDE5LTA5LTAx",
74+
"RequestUri": "/subscriptions/f67cc918-f64f-4c3f-aa24-a855465f9d41/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2020-09-01",
75+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZjY3Y2M5MTgtZjY0Zi00YzNmLWFhMjQtYTg1NTQ2NWY5ZDQxL3Byb3ZpZGVycy9NaWNyb3NvZnQuQXV0aG9yaXphdGlvbi9wb2xpY3lkZWZpbml0aW9ucy9zb21lTmFtZT9hcGktdmVyc2lvbj0yMDIwLTA5LTAx",
7376
"RequestMethod": "PUT",
74-
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\"\r\n }\r\n}",
77+
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\",\r\n \"policyType\": \"Custom\"\r\n }\r\n}",
7578
"RequestHeaders": {
7679
"User-Agent": [
77-
"AzurePowershell/v1.0.0",
78-
"PSVersion/v6.2.3"
80+
"AzurePowershell/v5.4.0",
81+
"PSVersion/v6.2.4"
7982
],
8083
"ParameterSetName": [
8184
"SubscriptionIdParameterSet"
@@ -87,27 +90,30 @@
8790
"application/json; charset=utf-8"
8891
],
8992
"Content-Length": [
90-
"136"
93+
"165"
9194
]
9295
},
9396
"ResponseHeaders": {
9497
"Cache-Control": [
95-
"no-cache"
98+
"no-store, no-cache"
9699
],
97100
"Pragma": [
98101
"no-cache"
99102
],
100-
"x-ms-request-id": [
101-
"westus:fde34af3-fe03-4b69-8ccc-2a1fab0dd81c"
102-
],
103103
"x-ms-ratelimit-remaining-subscription-writes": [
104104
"1199"
105105
],
106+
"x-ms-request-id": [
107+
"fa9e2a01-e668-4555-a6ed-f34b4041e9f6"
108+
],
109+
"Server": [
110+
"Kestrel"
111+
],
106112
"x-ms-correlation-request-id": [
107-
"7ec6e9c5-f346-497c-9a27-f5c782a842d2"
113+
"fa9e2a01-e668-4555-a6ed-f34b4041e9f6"
108114
],
109115
"x-ms-routing-request-id": [
110-
"WESTUS:20200109T002835Z:7ec6e9c5-f346-497c-9a27-f5c782a842d2"
116+
"WESTUS2:20210517T224326Z:fa9e2a01-e668-4555-a6ed-f34b4041e9f6"
111117
],
112118
"Strict-Transport-Security": [
113119
"max-age=31536000; includeSubDomains"
@@ -116,13 +122,13 @@
116122
"nosniff"
117123
],
118124
"Date": [
119-
"Thu, 09 Jan 2020 00:28:35 GMT"
125+
"Mon, 17 May 2021 22:43:25 GMT"
120126
],
121127
"Content-Length": [
122-
"166"
128+
"176"
123129
],
124130
"Content-Type": [
125-
"application/json; charset=utf-8"
131+
"application/json"
126132
],
127133
"Expires": [
128134
"-1"
@@ -131,18 +137,18 @@
131137
"0"
132138
]
133139
},
134-
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidPolicyRule\",\r\n \"message\": \"Failed to parse policy rule: 'Could not find member 'someThing' on object of type 'PolicyRule'. Path 'someThing'.'.\"\r\n }\r\n}",
140+
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidPolicyRule\",\r\n \"message\": \"Failed to parse policy rule: 'Could not find member 'someThing' on object of type 'PolicyRuleDefinition'. Path 'someThing'.'.\"\r\n }\r\n}",
135141
"StatusCode": 400
136142
},
137143
{
138-
"RequestUri": "/providers/Microsoft.Management/managementGroups/someManagementGroup/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2019-09-01",
139-
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuTWFuYWdlbWVudC9tYW5hZ2VtZW50R3JvdXBzL3NvbWVNYW5hZ2VtZW50R3JvdXAvcHJvdmlkZXJzL01pY3Jvc29mdC5BdXRob3JpemF0aW9uL3BvbGljeWRlZmluaXRpb25zL3NvbWVOYW1lP2FwaS12ZXJzaW9uPTIwMTktMDktMDE=",
144+
"RequestUri": "/providers/Microsoft.Management/managementGroups/someManagementGroup/providers/Microsoft.Authorization/policydefinitions/someName?api-version=2020-09-01",
145+
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuTWFuYWdlbWVudC9tYW5hZ2VtZW50R3JvdXBzL3NvbWVNYW5hZ2VtZW50R3JvdXAvcHJvdmlkZXJzL01pY3Jvc29mdC5BdXRob3JpemF0aW9uL3BvbGljeWRlZmluaXRpb25zL3NvbWVOYW1lP2FwaS12ZXJzaW9uPTIwMjAtMDktMDE=",
140146
"RequestMethod": "PUT",
141-
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\"\r\n }\r\n}",
147+
"RequestBody": "{\r\n \"name\": \"someName\",\r\n \"properties\": {\r\n \"policyRule\": {\r\n \"someThing\": \"someOtherThing\"\r\n },\r\n \"mode\": \"All\",\r\n \"policyType\": \"Custom\"\r\n }\r\n}",
142148
"RequestHeaders": {
143149
"User-Agent": [
144-
"AzurePowershell/v1.0.0",
145-
"PSVersion/v6.2.3"
150+
"AzurePowershell/v5.4.0",
151+
"PSVersion/v6.2.4"
146152
],
147153
"ParameterSetName": [
148154
"ManagementGroupNameParameterSet"
@@ -154,7 +160,7 @@
154160
"application/json; charset=utf-8"
155161
],
156162
"Content-Length": [
157-
"136"
163+
"165"
158164
]
159165
},
160166
"ResponseHeaders": {
@@ -168,13 +174,13 @@
168174
"gateway"
169175
],
170176
"x-ms-request-id": [
171-
"8b61ecb1-67f1-4b90-b774-fd69f5ebf5d7"
177+
"40a09481-044b-409f-b6dc-45565d0b621f"
172178
],
173179
"x-ms-correlation-request-id": [
174-
"8b61ecb1-67f1-4b90-b774-fd69f5ebf5d7"
180+
"40a09481-044b-409f-b6dc-45565d0b621f"
175181
],
176182
"x-ms-routing-request-id": [
177-
"WESTUS:20200109T002834Z:8b61ecb1-67f1-4b90-b774-fd69f5ebf5d7"
183+
"WESTUS2:20210517T224325Z:40a09481-044b-409f-b6dc-45565d0b621f"
178184
],
179185
"Strict-Transport-Security": [
180186
"max-age=31536000; includeSubDomains"
@@ -183,7 +189,7 @@
183189
"nosniff"
184190
],
185191
"Date": [
186-
"Thu, 09 Jan 2020 00:28:34 GMT"
192+
"Mon, 17 May 2021 22:43:25 GMT"
187193
],
188194
"Connection": [
189195
"close"
@@ -201,12 +207,12 @@
201207
"0"
202208
]
203209
},
204-
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"AuthorizationFailed\",\r\n \"message\": \"The client '54920461-deae-4c50-9893-ca85918263a2' with object id '54920461-deae-4c50-9893-ca85918263a2' does not have authorization to perform action 'Microsoft.Authorization/policydefinitions/write' over scope '/providers/Microsoft.Management/managementGroups/someManagementGroup/providers/Microsoft.Authorization/policydefinitions/someName' or the scope is invalid. If access was recently granted, please refresh your credentials.\"\r\n }\r\n}",
210+
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"AuthorizationFailed\",\r\n \"message\": \"The client '7140c269-e408-47a5-a626-a1d836b96883' with object id '7140c269-e408-47a5-a626-a1d836b96883' does not have authorization to perform action 'Microsoft.Authorization/policydefinitions/write' over scope '/providers/Microsoft.Management/managementGroups/someManagementGroup/providers/Microsoft.Authorization/policydefinitions/someName' or the scope is invalid. If access was recently granted, please refresh your credentials.\"\r\n }\r\n}",
205211
"StatusCode": 403
206212
}
207213
],
208214
"Names": {},
209215
"Variables": {
210-
"SubscriptionId": "fb3a3d6b-44c8-44f5-88c9-b20917c9b96b"
216+
"SubscriptionId": "f67cc918-f64f-4c3f-aa24-a855465f9d41"
211217
}
212218
}

0 commit comments

Comments
 (0)