Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dcff842
Fixed what-if funcationality with -QueryString parameter
Xynoclafe Feb 24, 2021
c608cd3
Added/Modified test cases for -QueryString
Xynoclafe Feb 26, 2021
39c53f0
Suppress credscan (credentials are invalid/for deleted resources)
Xynoclafe Mar 2, 2021
7731a98
include storage module in tests
Xynoclafe Mar 4, 2021
313600d
Remove scenario test and add mock test for -QueryString scenarios
Xynoclafe Mar 11, 2021
3fe7d81
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Mar 11, 2021
971ec2c
Update changelog
Xynoclafe Mar 11, 2021
7df85e4
Fix build issues; Switch a mock test for a scenario test
Xynoclafe Mar 12, 2021
1584bea
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Mar 12, 2021
0f681c6
Merge branch 'master' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 15, 2021
fa42dd3
Replace myget with Azure artifacts (#14543)
dingmeng-xue Mar 16, 2021
18614a8
Fix credscan file
Xynoclafe Mar 16, 2021
36d8201
Update Cloud Shell image in README.md (#14531)
jiasli Mar 16, 2021
9639ca0
Fix merge
Xynoclafe Mar 16, 2021
acaf849
Normalized -QueryString starting with ? for scenarios involving dynam…
Xynoclafe Mar 16, 2021
45c4600
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
8853e83
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
dc1a2f5
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<clear/>
<!-- Do not add any additional feeds if new packages are needed they need to come from nuget.org or our azure-sdk-for-net DevOps feed -->
<add key="local-feed" value="tools/LocalFeed" />
<add key="myget-azure-powershell" value="https://www.myget.org/F/azure-powershell/api/v3/index.json" />
<add key="azure-powershell" value="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-powershell/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources>
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

This repository contains PowerShell cmdlets for developers and administrators to develop, deploy, and manage Microsoft Azure applications.

Try it out in Azure Cloud Shell!
* Direct link: Open a browser to https://shell.azure.com
* Azure portal: Select the Cloud Shell icon on the [Azure portal](https://portal.azure.com/):

[![CloudShellLaunchIcon](https://docs.microsoft.com/en-us/azure/cloud-shell/media/overview/portal-launch-icon.png)](#)
Try it out in [Azure Cloud Shell](https://portal.azure.com/#cloudshell)!

## Modules
Below is a table containing our Azure PowerShell rollup module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public override object GetDynamicParameters()
{
if (!string.IsNullOrEmpty(QueryString))
{
protectedTemplateUri = TemplateUri + "?" + QueryString;
if(QueryString.Substring(0,1) == "?")
protectedTemplateUri = TemplateUri + QueryString;
else
protectedTemplateUri = TemplateUri + "?" + QueryString;
}
return base.GetDynamicParameters();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public DeploymentWhatIf ToDeploymentWhatIf()
else if (Uri.IsWellFormedUriString(this.TemplateUri, UriKind.Absolute))
{
properties.TemplateLink = new TemplateLink(this.TemplateUri);

if (!string.IsNullOrEmpty(this.QueryString))
{
properties.TemplateLink.QueryString = this.QueryString;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a test case

}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ public class NewAzureResourceGroupDeploymentCommandTests : RMTestBase

private string lastDeploymentName = "oldfooDeployment";

private string queryString = "foo";

private Dictionary<string, string> deploymentTags = Enumerable.Range(0, 2).ToDictionary(i => $"tagname{i}", i => $"tagvalue{i}");

private string templateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\sampleTemplateFile.json");

private string templateUri = "http://mytemplate.com";

public NewAzureResourceGroupDeploymentCommandTests(ITestOutputHelper output)
{
resourcesClientMock = new Mock<ResourceManagerSdkClient>();
Expand Down Expand Up @@ -356,5 +360,71 @@ public void ResolvesDynamicParametersWithCrossSubTemplateSpec()
dynamicParams.Count().Should().Be(template.Parameters.Count);
dynamicParams.Keys.Should().Contain(template.Parameters.Keys);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CreatesNewDeploymentUsingQueryStringParam()
{
PSDeploymentCmdletParameters expectedParameters = new PSDeploymentCmdletParameters()
{
TemplateFile = templateUri,
DeploymentName = deploymentName,
QueryString = queryString,
Tags = new Dictionary<string, string>(this.deploymentTags)
};
PSDeploymentCmdletParameters actualParameters = new PSDeploymentCmdletParameters();
PSResourceGroupDeployment expected = new PSResourceGroupDeployment()
{
Mode = DeploymentMode.Incremental,
DeploymentName = deploymentName,
CorrelationId = "123",
Outputs = new Dictionary<string, DeploymentVariable>()
{
{ "Variable1", new DeploymentVariable() { Value = "true", Type = "bool" } },
{ "Variable2", new DeploymentVariable() { Value = "10", Type = "int" } },
{ "Variable3", new DeploymentVariable() { Value = "hello world", Type = "string" } }
},
Parameters = new Dictionary<string, DeploymentVariable>()
{
{ "Parameter1", new DeploymentVariable() { Value = "true", Type = "bool" } },
{ "Parameter2", new DeploymentVariable() { Value = "10", Type = "int" } },
{ "Parameter3", new DeploymentVariable() { Value = "hello world", Type = "string" } }
},
ProvisioningState = ProvisioningState.Succeeded.ToString(),
ResourceGroupName = resourceGroupName,
TemplateLink = new TemplateLink()
{
ContentVersion = "1.0",
Uri = "http://mytemplate.com",
QueryString = "foo"
},
Timestamp = new DateTime(2014, 2, 13)
};
resourcesClientMock.Setup(f => f.ExecuteResourceGroupDeployment(
It.IsAny<PSDeploymentCmdletParameters>()))
.Returns(expected)
.Callback((PSDeploymentCmdletParameters p) => { actualParameters = p; });

cmdlet.ResourceGroupName = resourceGroupName;
cmdlet.Name = expectedParameters.DeploymentName;
cmdlet.TemplateUri = expectedParameters.TemplateFile;
cmdlet.QueryString = expectedParameters.QueryString;
cmdlet.Tag = new Hashtable(this.deploymentTags);

cmdlet.ExecuteCmdlet();

actualParameters.DeploymentName.Should().Equals(expectedParameters.DeploymentName);
actualParameters.TemplateFile.Should().Equals(expectedParameters.TemplateFile);
actualParameters.QueryString.Should().Equals(expectedParameters.QueryString);
actualParameters.TemplateParameterObject.Should().NotBeNull();
actualParameters.OnErrorDeployment.Should().BeNull();
actualParameters.Tags.Should().NotBeNull();

var differenceTags = actualParameters.Tags
.Where(entry => expectedParameters.Tags[entry.Key] != entry.Value);
differenceTags.Should().BeEmpty();

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}
}
}
15 changes: 8 additions & 7 deletions src/Resources/Resources.Test/ScenarioTests/DeploymentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ public void TestNewDeploymentFromNonexistentTemplateParameterFile()
TestRunner.RunTestScript("Test-NewDeploymentFromNonexistentTemplateParameterFile");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewDeploymentWithQueryString()
{
TestRunner.RunTestScript("Test-NewDeploymentWithQueryString");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestNewDeploymentFromBicepFile()
Expand All @@ -201,5 +194,13 @@ public void TestTestDeploymentFromBicepFile()
{
TestRunner.RunTestScript("Test-TestDeploymentFromBicepFile");
}

//Please make sure to re-record this test if any changes are made to WhatIf, QueryString or ResourceGroupDeployments
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestWhatIfWithQueryString()
{
TestRunner.RunTestScript("Test-WhatIfWithQueryString");
}
}
}
103 changes: 71 additions & 32 deletions src/Resources/Resources.Test/ScenarioTests/DeploymentTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -788,38 +788,6 @@ function Test-NewDeploymentFromNonexistentTemplateParameterFile
}
}

<#
.SYNOPSIS
Tests deployment from a template in a storage account using a query string.
#>
function Test-NewDeploymentWithQueryString
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "West US 2"
$subId = (Get-AzContext).Subscription.SubscriptionId

try
{
# Prepare our RG and basic template spec:

New-AzResourceGroup -Name $rgname -Location $rglocation

#Create deployment
$deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringtesting.blob.core.windows.net/testqsblob/linkedTemplateParent.json" -QueryString "foo"

# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState
}

finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests deployment via Bicep file.
Expand Down Expand Up @@ -884,4 +852,75 @@ function Test-TestDeploymentFromBicepFile
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
is running live in target environment
#>
function IsLive
{
return [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback
}

<#
.SYNOPSIS
Tests what-if on a deployment from a template in a storage account using a query string.
Please make sure to re-record this test if any changes are made to WhatIf or ResourceGroupDeployments
#>
function Test-WhatIfWithQueryString
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$saname = "querystringpstests"
$rglocation = "West US 2"
$subId = (Get-AzContext).Subscription.SubscriptionId

if(IsLive)
{
try
{
# Prepare our RG
New-AzResourceGroup -Name $rgname -Location $rglocation

#Prepare our Storage Account
$account = New-AzStorageAccount -ResourceGroupName $rgname -AccountName $saname -Location $rglocation -SkuName "Standard_LRS"

#Get StorageAccountKey
$key = (Get-AzStorageAccountKey -ResourceGroupName $rgname -AccountName $saname)| Where-Object {$_.KeyName -eq "key1"}

#Get StorageAccount context
$context = New-AzStorageContext -StorageAccountName $saname -StorageAccountKey $key.Value

#Create FileShare
New-AzStorageShare -Name "querystringshare" -Context $context

#Upload files to the StorageAccount
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateParent.json" -Path "sampleLinkedTemplateParent.json" -Context $context
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateChild.json" -Path "sampleLinkedTemplateChild.json" -Context $context

#Get SAStoken
$token = New-AzStorageAccountSASToken -Service File -ResourceType Service,Container,Object -Permission "r" -Context $context -ExpiryTime (Get-Date).AddMinutes(3)

#Create deployment
$deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1)

# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

#Run What-if
$result = New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1) -WhatIf

#assert that nothing has changed.
Assert-AreEqual 0 ($result).Count
}

finally
{
# Cleanup
Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $saname;
Clean-ResourceGroup $rgname
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected ResourceTestRunner(ITestOutputHelper output)
.WithExtraRmModules(helper => new[]
{
helper.RMResourceModule,
helper.GetRMModulePath("AzureRM.Monitor.psd1")
helper.GetRMModulePath("AzureRM.Monitor.psd1"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add helper.GetRMModulePath("AzureRM.Storage.psd1"), here to use cmdlets in Storage when running test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wyunchi-ms I made the suggested changes, but now it fails with "Device not configured"

helper.GetRMModulePath("AzureRM.Storage.psd1")
})
.WithRecordMatcher(
(ignoreResourcesClient, resourceProviders, userAgentsToIgnore) =>
Expand Down
Loading