Skip to content

Commit

Permalink
Validate Root Container and add. args (#3654)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent1173 authored Feb 26, 2017
1 parent 44843fd commit 53405ea
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Tasks/AzureFileCopy/AzureFileCopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 3 additions & 0 deletions Tasks/AzureFileCopy/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});
27 changes: 27 additions & 0 deletions Tasks/AzureFileCopy/Tests/L0CheckContainerNameAndArgs.ps1
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions Tasks/AzureFileCopy/Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
5 changes: 3 additions & 2 deletions Tasks/AzureFileCopy/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 85
"Patch": 86
},
"demands": [
"azureps"
Expand Down Expand Up @@ -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."
}
}
5 changes: 3 additions & 2 deletions Tasks/AzureFileCopy/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 85
"Patch": 86
},
"demands": [
"azureps"
Expand Down Expand Up @@ -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"
}
}

0 comments on commit 53405ea

Please sign in to comment.