Skip to content

Commit 03a4b3b

Browse files
authored
Add additional arguments validation for AzureFileCopy (#18022)
* Add validation of additional arguments * Add VerticalBar validation for WindowsFileCopy * Add error messages * Add L0 tests for AzureFileCopy * Update tasks versions * Update tasks version to sprint 221
1 parent b5a2fbc commit 03a4b3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+271
-47
lines changed

Tasks/AzureFileCopyV1/AzureFileCopy.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ try {
136136
}
137137

138138
Check-ContainerNameAndArgs -containerName $containerName -additionalArguments $additionalArguments
139+
Validate-AdditionalArguments $additionalArguments
139140

140141
# Uploading files to container
141142
Upload-FilesToAzureContainer -sourcePath $sourcePath -storageAccountName $storageAccount -containerName $containerName -blobPrefix $blobPrefix -blobStorageEndpoint $blobStorageEndpoint -storageKey $storageKey `

Tasks/AzureFileCopyV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@
9191
"loc.messages.AFC_RootContainerAndDirectory": "'/S' option is not valid for $root containers.",
9292
"loc.messages.AFC_RedirectResponseInvalidStatusCode": "The HTTP response code: '{0}' is not a valid redirect status code",
9393
"loc.messages.AFC_RedirectResponseLocationHeaderIsNull": "Redirect response location header is null.",
94-
"loc.messages.AFC_UninstallWinRMCustomScriptExtension": "Uninstall WinRM custom script manually and retry deployment."
94+
"loc.messages.AFC_UninstallWinRMCustomScriptExtension": "Uninstall WinRM custom script manually and retry deployment.",
95+
"loc.messages.AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters": "Additional arguments can't include separator characters '&', ';' and '|'. Please verify input. To learn more about argument validation, please check https://aka.ms/azdo-task-argument-validation"
9596
}

Tasks/AzureFileCopyV1/Tests/L0.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,8 @@ describe('AzureFileCopy Suite', function () {
111111
it('Validate AzureFileCopy.Utility Check-ContainerNameAndArgs', (done) => {
112112
psr.run(path.join(__dirname, 'L0CheckContainerNameAndArgs.ps1'), done);
113113
});
114+
it('Validate AzureFileCopy.Utility Validate-AdditionalArguments', (done) => {
115+
psr.run(path.join(__dirname, 'L0ValidateAdditionalArguments.ps1'), done);
116+
});
114117
}
115118
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
5+
. $PSScriptRoot\..\Utility.ps1
6+
7+
# Arrange
8+
9+
$invalidAdditionalArgumentsWithSemicolon = "echo 123 ; start notepad.exe"
10+
$invalidAdditionalArgumentsWithAmpersand = "echo 123 & start notepad.exe"
11+
$invalidAdditionalArgumentsWithVerticalBar = "echo 123 | start notepad.exe"
12+
$additionalArgumentsValidationErrorMessage = "AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters *";
13+
14+
# Assert
15+
16+
Assert-Throws {
17+
Validate-AdditionalArguments $invalidAdditionalArgumentsWithSemicolon
18+
} -Message $additionalArgumentsValidationErrorMessage
19+
20+
Assert-Throws {
21+
Validate-AdditionalArguments $invalidAdditionalArgumentsWithAmpersand
22+
} -Message $additionalArgumentsValidationErrorMessage
23+
24+
Assert-Throws {
25+
Validate-AdditionalArguments $invalidAdditionalArgumentsWithVerticalBar
26+
} -Message $additionalArgumentsValidationErrorMessage

Tasks/AzureFileCopyV1/Tests/MockVariable.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
$validInputSourcePath = Join-Path $env:windir "Source"
32
$validInputAzureBlobDestinationType = "AzureBlob"
43
$validInputAzureVmsDestinationType = "AzureVms"

Tasks/AzureFileCopyV1/Utility.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,4 +1447,12 @@ function Check-ContainerNameAndArgs
14471447
{
14481448
Write-Warning (Get-vstsLocString -Key "AFC_RootContainerAndDirectory")
14491449
}
1450+
}
1451+
1452+
function Validate-AdditionalArguments([string]$additionalArguments)
1453+
{
1454+
if($additionalArguments -match "[&;|]")
1455+
{
1456+
ThrowError -errorMessage (Get-VstsLocString -Key "AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters")
1457+
}
14501458
}

Tasks/AzureFileCopyV1/task.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 1,
16-
"Minor": 219,
16+
"Minor": 221,
1717
"Patch": 0
1818
},
1919
"demands": [
@@ -349,6 +349,7 @@
349349
"AFC_RootContainerAndDirectory": "'/S' option is not valid for $root containers.",
350350
"AFC_RedirectResponseInvalidStatusCode": "The HTTP response code: '{0}' is not a valid redirect status code",
351351
"AFC_RedirectResponseLocationHeaderIsNull": "Redirect response location header is null.",
352-
"AFC_UninstallWinRMCustomScriptExtension": "Uninstall WinRM custom script manually and retry deployment."
352+
"AFC_UninstallWinRMCustomScriptExtension": "Uninstall WinRM custom script manually and retry deployment.",
353+
"AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters": "Additional arguments can't include separator characters '&', ';' and '|'. Please verify input. To learn more about argument validation, please check https://aka.ms/azdo-task-argument-validation"
353354
}
354355
}

Tasks/AzureFileCopyV1/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 1,
16-
"Minor": 219,
16+
"Minor": 221,
1717
"Patch": 0
1818
},
1919
"demands": [
@@ -349,6 +349,7 @@
349349
"AFC_RootContainerAndDirectory": "ms-resource:loc.messages.AFC_RootContainerAndDirectory",
350350
"AFC_RedirectResponseInvalidStatusCode": "ms-resource:loc.messages.AFC_RedirectResponseInvalidStatusCode",
351351
"AFC_RedirectResponseLocationHeaderIsNull": "ms-resource:loc.messages.AFC_RedirectResponseLocationHeaderIsNull",
352-
"AFC_UninstallWinRMCustomScriptExtension": "ms-resource:loc.messages.AFC_UninstallWinRMCustomScriptExtension"
352+
"AFC_UninstallWinRMCustomScriptExtension": "ms-resource:loc.messages.AFC_UninstallWinRMCustomScriptExtension",
353+
"AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters": "ms-resource:loc.messages.AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters"
353354
}
354355
}

Tasks/AzureFileCopyV2/AzureFileCopy.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ try {
166166
}
167167

168168
Check-ContainerNameAndArgs -containerName $containerName -additionalArguments $additionalArgumentsForBlobCopy
169+
Validate-AdditionalArguments $additionalArguments
169170

170171
# Uploading files to container
171172
Upload-FilesToAzureContainer -sourcePath $sourcePath `

Tasks/AzureFileCopyV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@
9797
"loc.messages.AFC_AzCopyBlobUploadNonZeroExitCode": "AzCopy.exe exited with non-zero exit code while uploading files to blob storage.",
9898
"loc.messages.AFC_PreexecutionJob_UnableToGetStorageKey": "Unable to fetch storage account key. Error: '{0}'",
9999
"loc.messages.AFC_UninstallWinRMCustomScriptExtension": "Uninstall WinRM custom script manually and retry deployment.",
100+
"loc.messages.AFC_AdditionalArgumentsMustNotIncludeForbiddenCharacters": "Additional arguments can't include separator characters '&', ';' and '|'. Please verify input. To learn more about argument validation, please check https://aka.ms/azdo-task-argument-validation",
100101
"loc.messages.ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired."
101102
}

0 commit comments

Comments
 (0)