Skip to content

Commit 5a92009

Browse files
committed
Adding tests, updating help
1 parent a0a4a4f commit 5a92009

File tree

6 files changed

+670
-551
lines changed

6 files changed

+670
-551
lines changed

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppTests.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,24 @@ function Test-SetWebApp
595595
# Assert
596596
Assert-AreEqual $webAppName $webApp.Name
597597
Assert-AreEqual $serverFarm1.Id $webApp.ServerFarmId
598+
Assert-Null $webApp.Identity
598599

599-
# Change service plan
600-
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -AsJob
600+
# Change service plan & set site properties
601+
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -HttpsOnly $true -AssignIdentity $true -AsJob
601602
$job | Wait-Job
602603
$webApp = $job | Receive-Job
603604

604605
# Assert
605606
Assert-AreEqual $webAppName $webApp.Name
606607
Assert-AreEqual $serverFarm2.Id $webApp.ServerFarmId
608+
Assert-AreEqual $true $webApp.HttpsOnly
609+
Assert-NotNull $webApp.Identity
607610

608611
# Set config properties
609612
$webapp.SiteConfig.HttpLoggingEnabled = $true
610613
$webapp.SiteConfig.RequestTracingEnabled = $true
611614

615+
# Set site properties
612616
$webApp = $webApp | Set-AzureRmWebApp
613617

614618
# Assert

src/ResourceManager/Websites/Commands.Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestSetWebApp.json

Lines changed: 620 additions & 515 deletions
Large diffs are not rendered by default.

src/ResourceManager/Websites/Commands.Websites/Cmdlets/DeploymentSlots/SetAzureWebAppSlot.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public class SetAzureWebAppSlotCmdlet : WebAppSlotBaseCmdlet
8989
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
9090
public SwitchParameter AsJob { get; set; }
9191

92-
[Parameter(ParameterSetName = ParameterSet1Name, Position = 16, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
92+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
9393
public bool AssignIdentity { get; set; }
9494

95-
[Parameter(ParameterSetName = ParameterSet1Name, Position = 17, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
95+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
9696
public bool HttpsOnly { get; set; }
9797

9898
public override void ExecuteCmdlet()
@@ -142,7 +142,7 @@ public override void ExecuteCmdlet()
142142
{
143143
Location = location,
144144
ServerFarmId = WebApp.ServerFarmId,
145-
Identity = parameters.Contains("AssignIdentity") ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
145+
Identity = parameters.Contains("AssignIdentity") && AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
146146
HttpsOnly = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly
147147
};
148148

@@ -162,24 +162,14 @@ public override void ExecuteCmdlet()
162162
},
163163
StringComparer.OrdinalIgnoreCase));
164164
}
165-
else
166-
{
167-
// disabling the identity property updates the siteconfig only
168-
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
169-
}
165+
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, WebApp.ServerFarmId, site);
170166
}
171167

172168
if (parameters.Contains("AppServicePlan"))
173169
{
174170
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, AppServicePlan);
175171
}
176172

177-
if (parameters.Contains("AssignIdentity") || parameters.Contains("HttpsOnly"))
178-
{
179-
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, WebApp.ServerFarmId, site);
180-
}
181-
182-
183173
break;
184174
case ParameterSet2Name:
185175
// Web app is direct or pipeline input

src/ResourceManager/Websites/Commands.Websites/Cmdlets/WebApps/SetAzureWebApp.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ public class SetAzureWebAppCmdlet : WebAppBaseCmdlet
9797
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
9898
public SwitchParameter AsJob { get; set; }
9999

100-
[Parameter(ParameterSetName = ParameterSet1Name, Position= 16, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
100+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable MSI on an existing azure webapp")]
101101
public bool AssignIdentity { get; set; }
102102

103-
[Parameter(ParameterSetName = ParameterSet1Name, Position=17, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
103+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Enable/disable redirecting all traffic to HTTPS on an existing azure webapp")]
104104
public bool HttpsOnly { get; set; }
105105

106106
public override void ExecuteCmdlet()
@@ -150,7 +150,7 @@ public override void ExecuteCmdlet()
150150
{
151151
Location = location,
152152
ServerFarmId = WebApp.ServerFarmId,
153-
Identity = parameters.Contains("AssignIdentity") ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
153+
Identity = parameters.Contains("AssignIdentity") && AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : WebApp.Identity,
154154
HttpsOnly = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly
155155
};
156156

@@ -160,7 +160,7 @@ public override void ExecuteCmdlet()
160160

161161
// Add or update the appsettings property
162162
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
163-
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, WebApp.SiteConfig, appSettings,
163+
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, WebApp.SiteConfig, appSettings,
164164
WebApp.SiteConfig.ConnectionStrings.
165165
ToDictionary(nvp => nvp.Name,
166166
nvp => new ConnStringValueTypePair
@@ -170,11 +170,7 @@ public override void ExecuteCmdlet()
170170
},
171171
StringComparer.OrdinalIgnoreCase));
172172
}
173-
else
174-
{
175-
// disabling the identity property updates the siteconfig only
176-
appSettings["WEBSITE_DISABLE_MSI"] = (!AssignIdentity).ToString();
177-
}
173+
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, site);
178174
}
179175

180176
if (parameters.Contains("AppServicePlan"))
@@ -187,11 +183,6 @@ public override void ExecuteCmdlet()
187183
WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, HostNames);
188184
}
189185

190-
if(parameters.Contains("AssignIdentity") || parameters.Contains("HttpsOnly"))
191-
{
192-
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, site);
193-
}
194-
195186
break;
196187
case ParameterSet2Name:
197188
// Web app is direct or pipeline input

src/ResourceManager/Websites/Commands.Websites/help/Set-AzureRmWebApp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Set-AzureRmWebApp [[-AppServicePlan] <String>] [[-DefaultDocuments] <String[]>]
2121
[[-ConnectionStrings] <Hashtable>]
2222
[[-HandlerMappings] <System.Collections.Generic.IList`1[Microsoft.Azure.Management.WebSites.Models.HandlerMapping]>]
2323
[[-ManagedPipelineMode] <String>] [[-WebSocketsEnabled] <Boolean>] [[-Use32BitWorkerProcess] <Boolean>]
24-
[[-AutoSwapSlotName] <String>] [-HostNames <String[]>] [-NumberOfWorkers <Int32>] [-AsJob] [-AssignIdentity]
25-
[-HttpsOnly] [-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
24+
[[-AutoSwapSlotName] <String>] [-HostNames <String[]>] [-NumberOfWorkers <Int32>] [-AsJob] [[-AssignIdentity] <Boolean>]
25+
[[-HttpsOnly] <Boolean>] [-ResourceGroupName] <String> [-Name] <String> [-DefaultProfile <IAzureContextContainer>]
2626
[<CommonParameters>]
2727
```
2828

@@ -93,10 +93,10 @@ Accept wildcard characters: False
9393
```
9494
9595
### -AssignIdentity
96-
Enable MSI on an existing azure webapp or functionapp
96+
Enable/disable MSI on an existing azure webapp or functionapp [PREVIEW]
9797
9898
```yaml
99-
Type: SwitchParameter
99+
Type: Boolean
100100
Parameter Sets: S1
101101
Aliases:
102102

@@ -231,7 +231,7 @@ Accept wildcard characters: False
231231
Enable/disable redirecting all traffic to HTTPS on an existing azure webapp or functionapp
232232
233233
```yaml
234-
Type: SwitchParameter
234+
Type: Boolean
235235
Parameter Sets: S1
236236
Aliases:
237237

src/ResourceManager/Websites/Commands.Websites/help/Set-AzureRmWebAppSlot.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Set-AzureRmWebAppSlot [[-AppServicePlan] <String>] [[-DefaultDocuments] <String[
2222
[[-HandlerMappings] <System.Collections.Generic.IList`1[Microsoft.Azure.Management.WebSites.Models.HandlerMapping]>]
2323
[[-ManagedPipelineMode] <String>] [[-WebSocketsEnabled] <Boolean>] [[-Use32BitWorkerProcess] <Boolean>]
2424
[-AutoSwapSlotName <String>] [-NumberOfWorkers <Int32>] [-ResourceGroupName] <String> [-Name] <String>
25-
[-Slot] <String> [-AsJob]
25+
[[-AssignIdentity] <Boolean>] [[HttpsOnly] <Boolean>] [-Slot] <String> [-AsJob]
2626
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2727
```
2828

@@ -352,6 +352,35 @@ Default value: None
352352
Accept pipeline input: False
353353
Accept wildcard characters: False
354354
```
355+
### -HttpsOnly
356+
Enable/disable redirecting all traffic to HTTPS on an existing slot
357+
358+
```yaml
359+
Type: Boolean
360+
Parameter Sets: S1
361+
Aliases:
362+
363+
Required: False
364+
Position: Named
365+
Default value: None
366+
Accept pipeline input: False
367+
Accept wildcard characters: False
368+
```
369+
### -AssignIdentity
370+
Enable/disable MSI on an existing slot [PREVIEW]
371+
372+
```yaml
373+
Type: Boolean
374+
Parameter Sets: S1
375+
Aliases:
376+
377+
Required: False
378+
Position: Named
379+
Default value: None
380+
Accept pipeline input: False
381+
Accept wildcard characters: False
382+
```
383+
355384
### -AsJob
356385
Run cmdlet in the background
357386

0 commit comments

Comments
 (0)