Skip to content

Commit bf9b61a

Browse files
Sumananshahabhijeet
authored andcommitted
WORK 8397371: [Sheduler PowerShell] Powershell encodes http job URI before sending to RP. (Azure#3484)
1 parent acaa012 commit bf9b61a

File tree

5 files changed

+1696
-807
lines changed

5 files changed

+1696
-807
lines changed

src/ResourceManager/Scheduler/Commands.Scheduler.Test/ScenarioTests/JobTests.ps1

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function Test-CreateHttpJob
5858
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
5959
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
6060

61+
# Create a new http job with client certificate authentication
6162
$jobName = "HttpJobWithHttpClientCertificateAuthentication"
6263
$method = "get"
6364
$body = $null
@@ -69,6 +70,7 @@ function Test-CreateHttpJob
6970
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
7071
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
7172

73+
# Create a new http job with start time.
7274
$jobName = "HttpJobWithStartTime"
7375
$startTime = Get-Date
7476
$startTime = $startTime.AddDays(1)
@@ -79,7 +81,7 @@ function Test-CreateHttpJob
7981
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
8082
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
8183

82-
$jobName = "HttpJobWith"
84+
# Create a new http job with recurrence.
8385
$jobName = "HttpJobWithRecurrence"
8486
$interval = 1
8587
$frequency = "Minute"
@@ -94,6 +96,7 @@ function Test-CreateHttpJob
9496
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
9597
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
9698

99+
# Create a new job with error http action.
97100
$jobName = "HttpJobWithErrorHttpAction"
98101
$status = "Enabled"
99102
$startTime = $null
@@ -117,6 +120,16 @@ function Test-CreateHttpJob
117120
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
118121
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
119122
Validate-HttpJob $errorActionMethod $errorActionUri $errorActionBody $errorActionHeaders $errorActionAuthenticationType $jobDefinition.JobErrorAction
123+
124+
# Create a new job with encodable uri characters.
125+
$jobName = "HttpJobWithEncodableUriCharacters"
126+
$uri = "http://www.bing.com/workers?somekey=somevalue%2drandomvalue%2fconsistent%3d"
127+
$errorActionUri = "http://www.bing.com/workers?somekey=somevalue%2drandomvalue%2fconsistent%3d"
128+
129+
$jobDefinition = New-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -Method $method -Uri $uri -ErrorActionType $errorActionType -ErrorActionMethod $errorActionMethod -ErrorActionUri $errorActionUri -ErrorActionRequestBody $errorActionBody -ErrorActionHeaders $errorActionHeaders -ErrorActionHttpAuthenticationType $errorActionAuthenticationType -ErrorActionUsername $errorActionUsername -ErrorActionPassword $errorActionPassword
130+
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
131+
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
132+
Validate-HttpJob $errorActionMethod $errorActionUri $errorActionBody $errorActionHeaders $errorActionAuthenticationType $jobDefinition.JobErrorAction
120133
}
121134
finally
122135
{
@@ -157,15 +170,16 @@ function Test-UpdateHttpJob
157170
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
158171
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
159172

173+
# Update a job with start time.
160174
$startTime = Get-Date
161175
$startTime = $startTime.AddDays(1)
162176
$startTime = $startTime.ToUniversalTime()
163177

164-
$jobDefinition = Set-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -StartTime $startTime
178+
$jobDefinition = Set-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -StartTime $startTime -Uri $uri
165179
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
166180
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
167181

168-
# Create a new http job with headers and body
182+
# Update a job with headers and body.
169183
$method = "post"
170184
$body = "Hello"
171185
$headers = @{"Content-Type" = "application/json"}
@@ -174,13 +188,15 @@ function Test-UpdateHttpJob
174188
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
175189
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
176190

191+
# Update a job with authentication.
177192
$httpAuthenticationType = "Basic"
178193
$userName = "httpJob"
179194
$password = "p@ssword!"
180195
$jobDefinition = Set-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -HttpAuthenticationType $httpAuthenticationType -Username $username -Password $password
181196
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
182197
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
183198

199+
# Update a job with interval / frequency.
184200
$interval = 1
185201
$frequency = "Minute"
186202
$endTime = Get-Date
@@ -194,6 +210,13 @@ function Test-UpdateHttpJob
194210
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
195211
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
196212

213+
# Update a job with encodable characters URI.
214+
$uri = "http://www.bing.com/workers?somekey=somevalue%2drandomvalue%2fconsistent%3d"
215+
$jobDefinition = Set-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -Uri $uri
216+
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
217+
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
218+
219+
# Update a job with error action.
197220
$status = "Enabled"
198221
$jobActionType = "Http"
199222
$errorActionType = "Http"
@@ -208,7 +231,15 @@ function Test-UpdateHttpJob
208231
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
209232
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
210233
Validate-HttpJob $errorActionMethod $errorActionUri $errorActionBody $errorActionHeaders $errorActionAuthenticationType $jobDefinition.JobErrorAction
234+
235+
# Update a job with encodable characters error action URI.
236+
$errorActionUri = "http://www.bing.com/workers?somekey=somevalue%2drandomvalue%2fconsistent%3d"
237+
$jobDefinition = Set-AzureRmSchedulerHttpJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName -JobName $jobName -ErrorActionType $errorActionType -ErrorActionUri $errorActionUri
238+
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition
239+
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition.JobAction
240+
Validate-HttpJob $errorActionMethod $errorActionUri $errorActionBody $errorActionHeaders $errorActionAuthenticationType $jobDefinition.JobErrorAction
211241

242+
# Get scheduler job.
212243
$jobDefinition = Get-AzureRmSchedulerJob -ResourceGroupName $resourceGroupName -JobCollectionName $jobCollectionName
213244
Validate-DefaultJob $resourceGroupName $jobCollectionName $jobName $status $startTime $recurrence $endSchedule $jobDefinition[0]
214245
Validate-HttpJob $method $uri $body $headers $httpAuthenticationType $jobDefinition[0].JobAction

0 commit comments

Comments
 (0)