diff --git a/Tasks/AzureFileCopy/AzureFileCopy.ps1 b/Tasks/AzureFileCopy/AzureFileCopy.ps1 index 45ef74977a33..c7835a5453f4 100644 --- a/Tasks/AzureFileCopy/AzureFileCopy.ps1 +++ b/Tasks/AzureFileCopy/AzureFileCopy.ps1 @@ -44,6 +44,7 @@ $isPremiumStorage = $false $sourcePath = $sourcePath.Trim('"') $storageAccount = $storageAccount.Trim() +$containerName = $containerName.Trim().ToLower() # azcopy location on automation agent $azCopyExeLocation = 'AzCopy\AzCopy.exe' @@ -128,6 +129,8 @@ else $uploadAdditionalArguments = $additionalArguments } +Check-ContainerNameAndArgs -containerName $containerName -additionalArguments $additionalArguments + # Uploading files to container Upload-FilesToAzureContainer -sourcePath $sourcePath -storageAccountName $storageAccount -containerName $containerName -blobPrefix $blobPrefix -blobStorageEndpoint $blobStorageEndpoint -storageKey $storageKey ` -azCopyLocation $azCopyLocation -additionalArguments $uploadAdditionalArguments -destinationType $destination diff --git a/Tasks/AzureFileCopy/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureFileCopy/Strings/resources.resjson/en-US/resources.resjson index 835192cffc01..c88e61892325 100644 --- a/Tasks/AzureFileCopy/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureFileCopy/Strings/resources.resjson/en-US/resources.resjson @@ -87,5 +87,6 @@ "loc.messages.AFC_AddNetworkSecurityRuleFailed": "Failed to add the network security rule: {0}", "loc.messages.AFC_UnableToSetCustomScriptExtension": "Unable to set the custom script extension '{0}' for virtual machine '{1}': {2}", "loc.messages.AFC_CopyPrereqsFailed": "Failed to enable copy prerequisites. {0}", - "loc.messages.AFC_BlobStorageNotFound": "Storage account: {0} not found. Please specify existing storage account" + "loc.messages.AFC_BlobStorageNotFound": "Storage account: {0} not found. Please specify existing storage account", + "loc.messages.AFC_RootContainerAndDirectory": "'/S' option is not valid for $root containers." } \ No newline at end of file diff --git a/Tasks/AzureFileCopy/Tests/L0.ts b/Tasks/AzureFileCopy/Tests/L0.ts index a54298f3330a..e3dd37c4e654 100644 --- a/Tasks/AzureFileCopy/Tests/L0.ts +++ b/Tasks/AzureFileCopy/Tests/L0.ts @@ -108,5 +108,8 @@ describe('AzureFileCopy Suite', function () { it('Validate AzureFileCopy.Utility Copy-FilesSequentiallyToAzureVMs', (done) => { psr.run(path.join(__dirname, 'L0CopyFilesSequentiallyToAzureVMs.ps1'), done); }); + it('Validate AzureFileCopy.Utility Check-ContainerNameAndArgs', (done) => { + psr.run(path.join(__dirname, 'L0CheckContainerNameAndArgs.ps1'), done); + }); } }); diff --git a/Tasks/AzureFileCopy/Tests/L0CheckContainerNameAndArgs.ps1 b/Tasks/AzureFileCopy/Tests/L0CheckContainerNameAndArgs.ps1 new file mode 100644 index 000000000000..34a0a1052dec --- /dev/null +++ b/Tasks/AzureFileCopy/Tests/L0CheckContainerNameAndArgs.ps1 @@ -0,0 +1,27 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\..\Utility.ps1 + +Register-Mock Write-Warning { } + +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/S" +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/S " +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/XN /S /XO" +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments " /S " +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/Y /S" + +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/s" +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/s " +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/XN /s /XO" +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments " /s " +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/Y /s" +Assert-WasCalled Write-Warning -Times 10 + +Unregister-Mock Write-Warning +Register-Mock Write-Warning { } + +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/SetContentType:video/mp4" +Check-ContainerNameAndArgs -containerName '$root' -additionalArguments "/Source:path /SetContentType:video/mp4" +Assert-WasCalled Write-Warning -Times 0 \ No newline at end of file diff --git a/Tasks/AzureFileCopy/Utility.ps1 b/Tasks/AzureFileCopy/Utility.ps1 index 64e31b037cec..f6c3d51a5df2 100644 --- a/Tasks/AzureFileCopy/Utility.ps1 +++ b/Tasks/AzureFileCopy/Utility.ps1 @@ -1314,3 +1314,15 @@ function Add-AzureVMCustomScriptExtension Write-Verbose "Successfully added the custom script extension '$extensionName' for virtual machine '$vmName'" } + +function Check-ContainerNameAndArgs +{ + param([string]$containerName, + [string]$additionalArguments) + + $additionalArguments = ' ' + $additionalArguments + ' ' + if($containerName -eq '$root' -and $additionalArguments -like '* /S *') + { + Write-Warning (Get-vstsLocString -Key "AFC_RootContainerAndDirectory") + } +} \ No newline at end of file diff --git a/Tasks/AzureFileCopy/task.json b/Tasks/AzureFileCopy/task.json index 13e1a73ae540..6fc5f5436bbd 100644 --- a/Tasks/AzureFileCopy/task.json +++ b/Tasks/AzureFileCopy/task.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 85 + "Patch": 86 }, "demands": [ "azureps" @@ -323,6 +323,7 @@ "AFC_AddNetworkSecurityRuleFailed": "Failed to add the network security rule: {0}", "AFC_UnableToSetCustomScriptExtension": "Unable to set the custom script extension '{0}' for virtual machine '{1}': {2}", "AFC_CopyPrereqsFailed": "Failed to enable copy prerequisites. {0}", - "AFC_BlobStorageNotFound": "Storage account: {0} not found. Please specify existing storage account" + "AFC_BlobStorageNotFound": "Storage account: {0} not found. Please specify existing storage account", + "AFC_RootContainerAndDirectory": "'/S' option is not valid for $root containers." } } \ No newline at end of file diff --git a/Tasks/AzureFileCopy/task.loc.json b/Tasks/AzureFileCopy/task.loc.json index e2fff2aaa41d..d2d4df83e179 100644 --- a/Tasks/AzureFileCopy/task.loc.json +++ b/Tasks/AzureFileCopy/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 85 + "Patch": 86 }, "demands": [ "azureps" @@ -323,6 +323,7 @@ "AFC_AddNetworkSecurityRuleFailed": "ms-resource:loc.messages.AFC_AddNetworkSecurityRuleFailed", "AFC_UnableToSetCustomScriptExtension": "ms-resource:loc.messages.AFC_UnableToSetCustomScriptExtension", "AFC_CopyPrereqsFailed": "ms-resource:loc.messages.AFC_CopyPrereqsFailed", - "AFC_BlobStorageNotFound": "ms-resource:loc.messages.AFC_BlobStorageNotFound" + "AFC_BlobStorageNotFound": "ms-resource:loc.messages.AFC_BlobStorageNotFound", + "AFC_RootContainerAndDirectory": "ms-resource:loc.messages.AFC_RootContainerAndDirectory" } } \ No newline at end of file