Skip to content

Commit 85db4ba

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents f2856a6 + 60b964d commit 85db4ba

File tree

46 files changed

+1103
-119
lines changed

Some content is hidden

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

46 files changed

+1103
-119
lines changed

ChangeLog.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Select-AzureSubscription: fixed output types in default and PassThru mode
55
* Compute
66
* Get-AzureVMSqlServerExtension
7-
* New-AzureVMSqlServerExtension
87
* Set-AzureVMSqlServerExtension
98
* Remove-AzureVMSqlServerExtension
109
* HDInsight

src/Common/Commands.Common.Test/Common/ProfileCmdltsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ public void ClearAzureProfileClearsTokenCache()
149149
Assert.Equal(0, tokenCache.ReadItems().Count());
150150
}
151151

152+
[Fact]
153+
public void DeleteCorruptedTokenCache()
154+
{
155+
//setup
156+
string testFileName = @"c:\foobar\TokenCache.dat";
157+
ProfileClient.DataStore.WriteFile(testFileName, new byte[] { 0, 1 });
158+
159+
//Act
160+
ProtectedFileTokenCache tokenCache = new ProtectedFileTokenCache(testFileName);
161+
162+
//Assert
163+
Assert.False(ProfileClient.DataStore.FileExists(testFileName));
164+
}
165+
152166
[Fact]
153167
public void SetAzureSubscriptionAddsSubscriptionWithCertificate()
154168
{

src/Common/Commands.Common/Authentication/ProtectedFileTokenCache.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,39 @@ public static ProtectedFileTokenCache Instance
4444
// Initializes the cache against a local file.
4545
// If the file is already present, it loads its content in the ADAL cache
4646
private ProtectedFileTokenCache()
47+
{
48+
Initialize(CacheFileName);
49+
}
50+
51+
private void Initialize(string fileName)
4752
{
4853
AfterAccess = AfterAccessNotification;
4954
BeforeAccess = BeforeAccessNotification;
5055
lock (fileLock)
5156
{
52-
if (ProfileClient.DataStore.FileExists(CacheFileName))
57+
if (ProfileClient.DataStore.FileExists(fileName))
5358
{
54-
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
59+
var existingData = ProfileClient.DataStore.ReadFileAsBytes(fileName);
5560
if (existingData != null)
5661
{
57-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
62+
try
63+
{
64+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
65+
}
66+
catch (CryptographicException)
67+
{
68+
ProfileClient.DataStore.DeleteFile(fileName);
69+
}
5870
}
5971
}
6072
}
6173
}
6274

75+
public ProtectedFileTokenCache(string cacheFile)
76+
{
77+
Initialize(cacheFile);
78+
}
79+
6380
// Empties the persistent store.
6481
public override void Clear()
6582
{
@@ -81,7 +98,14 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
8198
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
8299
if (existingData != null)
83100
{
84-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
101+
try
102+
{
103+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
104+
}
105+
catch (CryptographicException)
106+
{
107+
ProfileClient.DataStore.DeleteFile(CacheFileName);
108+
}
85109
}
86110
}
87111
}

src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,24 @@ private void RegisterServiceManagementProviders<T>(AzureContext context) where T
119119
}
120120
}
121121

122-
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
122+
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
123123
{
124-
if (providers != null && providers.Count > 0)
125-
{
126-
subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127-
providers.ToArray());
128-
ProfileClient profileClient = new ProfileClient();
129-
profileClient.AddOrSetSubscription(subscription);
130-
profileClient.Profile.Save();
131-
}
124+
     if (providers != null && providers.Count > 0)
125+
     {
126+
         subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127+
             providers.ToArray());
128+
         try
129+
         {
130+
             ProfileClient profileClient = new ProfileClient();
131+
             profileClient.AddOrSetSubscription(subscription);
132+
             profileClient.Profile.Save();
133+
         }
134+
         catch (KeyNotFoundException)
135+
         {
136+
             // if using a subscription data file, do not write registration to disk
137+
             // long term solution is using -Profile parameter
138+
         }
139+
     }
132140
}
133141
}
134142
}

src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ function Test-DataFactoryPiping
124124

125125
# Test the data factory no longer exists
126126
Assert-ThrowsContains { Get-AzureDataFactory -ResourceGroupName $rgname -Name $dfname } "ResourceNotFound"
127-
}
127+
}

src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Collections.Generic;
1615
using Microsoft.Azure.Commands.DataFactories.Models;
1716
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1817
using Moq;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
1921
using Xunit;
2022

2123
namespace Microsoft.Azure.Commands.DataFactories.Test
@@ -78,6 +80,30 @@ public void CanGetHub()
7880
commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
7981
}
8082

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void GetHubWithEmptyName()
86+
{
87+
// Action
88+
cmdlet.Name = String.Empty;
89+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
90+
91+
// Assert
92+
Assert.Contains("Value cannot be null", exception.Message);
93+
}
94+
95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void GetHubWithWhiteSpaceName()
98+
{
99+
// Action
100+
cmdlet.Name = " ";
101+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
102+
103+
// Assert
104+
Assert.Contains("Value cannot be null", exception.Message);
105+
}
106+
81107
[Fact]
82108
[Trait(Category.AcceptanceType, Category.CheckIn)]
83109
public void CanListHubs()

src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Collections.Generic;
1615
using Microsoft.Azure.Commands.DataFactories.Models;
1716
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1817
using Moq;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
1921
using Xunit;
2022

2123
namespace Microsoft.Azure.Commands.DataFactories.Test
@@ -78,6 +80,30 @@ public void CanGetPipeline()
7880
commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
7981
}
8082

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void GetPipelineWithEmptyName()
86+
{
87+
// Action
88+
cmdlet.Name = String.Empty;
89+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
90+
91+
// Assert
92+
Assert.Contains("Value cannot be null", exception.Message);
93+
}
94+
95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void GetPipelineWithWhiteSpaceName()
98+
{
99+
// Action
100+
cmdlet.Name = " ";
101+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
102+
103+
// Assert
104+
Assert.Contains("Value cannot be null", exception.Message);
105+
}
106+
81107
[Fact]
82108
[Trait(Category.AcceptanceType, Category.CheckIn)]
83109
public void CanListPipelines()

src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.DataFactories.Models;
16+
using Microsoft.Azure.Commands.DataFactories.Properties;
1517
using System.Collections.Generic;
18+
using System.Globalization;
1619
using System.Management.Automation;
1720
using System.Security.Permissions;
18-
using Microsoft.Azure.Commands.DataFactories.Models;
19-
using System.Globalization;
20-
using Microsoft.Azure.Commands.DataFactories.Properties;
2121

2222
namespace Microsoft.Azure.Commands.DataFactories
2323
{
@@ -31,6 +31,12 @@ public class GetAzureDataFactoryHubCommand : HubContextBaseCmdlet
3131
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
3232
public override void ExecuteCmdlet()
3333
{
34+
// ValidationNotNullOrEmpty doesn't handle whitespaces well
35+
if (Name != null && string.IsNullOrWhiteSpace(Name))
36+
{
37+
throw new PSArgumentNullException("Name");
38+
}
39+
3440
if (ParameterSetName == ByFactoryObject)
3541
{
3642
if (DataFactory == null)

src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.DataFactories.Models;
16+
using Microsoft.Azure.Commands.DataFactories.Properties;
1517
using System;
18+
using System.Collections;
1619
using System.Collections.Generic;
20+
using System.Globalization;
1721
using System.Management.Automation;
1822
using System.Security.Permissions;
19-
using Microsoft.Azure.Commands.DataFactories.Models;
20-
using System.Collections;
21-
using System.Globalization;
22-
using Microsoft.Azure.Commands.DataFactories.Properties;
2323

2424
namespace Microsoft.Azure.Commands.DataFactories
2525
{
@@ -42,6 +42,12 @@ public class GetAzureDataFactoryPipelineCommand : DataFactoryBaseCmdlet
4242
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
4343
public override void ExecuteCmdlet()
4444
{
45+
// ValidationNotNullOrEmpty doesn't handle whitespaces well
46+
if (Name != null && string.IsNullOrWhiteSpace(Name))
47+
{
48+
throw new PSArgumentNullException("Name");
49+
}
50+
4551
if (ParameterSetName == ByFactoryObject)
4652
{
4753
if (DataFactory == null)

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</Reference>
4949
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5050
<SpecificVersion>False</SpecificVersion>
51-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
51+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
5252
</Reference>
5353
<Reference Include="Microsoft.Azure.Monitoring, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5454
<SpecificVersion>False</SpecificVersion>
@@ -58,7 +58,7 @@
5858
<SpecificVersion>False</SpecificVersion>
5959
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.7.1-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
6060
</Reference>
61-
<Reference Include="Microsoft.Azure.Utilities.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61+
<Reference Include="Microsoft.Azure.Utilities.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6262
<SpecificVersion>False</SpecificVersion>
6363
<HintPath>..\..\..\packages\Hydra.HttpRecorder.1.0.5417.13285-prerelease\lib\net45\Microsoft.Azure.Utilities.HttpRecorder.dll</HintPath>
6464
</Reference>
@@ -85,17 +85,17 @@
8585
<Reference Include="Microsoft.WindowsAzure.Common">
8686
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
8787
</Reference>
88-
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
88+
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
8989
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
9090
</Reference>
9191
<Reference Include="Microsoft.WindowsAzure.Management.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9292
<SpecificVersion>False</SpecificVersion>
9393
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.3.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
9494
</Reference>
95-
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
95+
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9696
<SpecificVersion>False</SpecificVersion>
9797
<HintPath>..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll</HintPath>
98-
</Reference>
98+
</Reference>
9999
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
100100
<SpecificVersion>False</SpecificVersion>
101101
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>

src/ResourceManager/Sql/Commands.Sql.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Hydra.SpecTestSupport" version="1.0.5406.28672-prerelease" targetFramework="net45" />
55
<package id="Microsoft.Azure.Gallery" version="2.2.1-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Management.Resources" version="2.7.1-preview" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Management.Sql" version="0.14.0-prerelease" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.Sql" version="0.14.3-prerelease" targetFramework="net45" />
88
<package id="Microsoft.Azure.Monitoring" version="2.2.1-preview" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<ItemGroup>
9090
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9191
<SpecificVersion>False</SpecificVersion>
92-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
92+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
9393
</Reference>
9494
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9595
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)