-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't fail silently when windows credentials go wrong. (#958)
* Change error handling from hidden debug output to user prompts. * Only delete corrupted file when approved by the user.
- Loading branch information
Jim Przybylinski
authored
May 17, 2018
1 parent
bdb6b47
commit 67cec9c
Showing
24 changed files
with
1,142 additions
and
508 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...ension/GoogleCloudExtension.GCloud.UnitTests/GoogleCloudExtension.GCloud.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{608977EE-0606-45F6-B68C-4861842B6FE3}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>GoogleCloudExtension.GCloud.UnitTests</RootNamespace> | ||
<AssemblyName>GoogleCloudExtension.GCloud.UnitTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="WindowsInstanceCredentialsTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\GoogleCloudExtension.GCloud\GoogleCloudExtension.GCloud.csproj"> | ||
<Project>{95EFAC7E-4F6E-46F0-BCC8-90EE1487E1E1}</Project> | ||
<Name>GoogleCloudExtension.GCloud</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" /> | ||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" /> | ||
</Target> | ||
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" /> | ||
</Project> |
32 changes: 32 additions & 0 deletions
32
GoogleCloudExtension/GoogleCloudExtension.GCloud.UnitTests/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("GoogleCloudExtension.GCloud.UnitTests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Google Inc.")] | ||
[assembly: AssemblyProduct("Cloud Tools for Visual Studio")] | ||
[assembly: AssemblyCopyright("Copyright © Google Inc. 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
[assembly: ComVisible(false)] | ||
|
||
[assembly: Guid("608977ee-0606-45f6-b68c-4861842b6fe3")] | ||
|
||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
92 changes: 92 additions & 0 deletions
92
...leCloudExtension/GoogleCloudExtension.GCloud.UnitTests/WindowsInstanceCredentialsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace GoogleCloudExtension.GCloud.UnitTests | ||
{ | ||
[TestClass] | ||
public class WindowsInstanceCredentialsTests | ||
{ | ||
// ReSharper disable once UnusedAutoPropertyAccessor.Local | ||
private static object[][] NotEqualObjects { get; } = | ||
{ | ||
new object[] {null}, | ||
new object[] {"UserNameAndPassword"}, | ||
new object[] {new WindowsInstanceCredentials("DifferentUser", "Password")}, | ||
new object[] {new WindowsInstanceCredentials("User", "DifferentPassword")} | ||
}; | ||
|
||
[TestMethod] | ||
public void TestJsonSerialization() | ||
{ | ||
var objectUnderTest = new WindowsInstanceCredentials("UserString", "PasswordString"); | ||
|
||
string json = JsonConvert.SerializeObject(objectUnderTest); | ||
|
||
Assert.AreEqual(@"{""username"":""UserString"",""password"":""PasswordString""}", json); | ||
} | ||
|
||
[TestMethod] | ||
public void TestJsonDeserialization() | ||
{ | ||
var json = @"{""username"":""UserString"",""password"":""PasswordString""}"; | ||
|
||
var result = JsonConvert.DeserializeObject<WindowsInstanceCredentials>(json); | ||
|
||
Assert.AreEqual("UserString", result.User); | ||
Assert.AreEqual("PasswordString", result.Password); | ||
} | ||
|
||
[TestMethod] | ||
[DynamicData(nameof(NotEqualObjects))] | ||
public void TestEqualsFalse(object notEqualObject) | ||
{ | ||
var sourceObject = new WindowsInstanceCredentials("User", "Password"); | ||
Assert.IsFalse(sourceObject.Equals(notEqualObject)); | ||
} | ||
|
||
[TestMethod] | ||
[DynamicData(nameof(NotEqualObjects))] | ||
public void TestHashCodeNotEqual(object notEqualObject) | ||
{ | ||
var sourceObject = new WindowsInstanceCredentials("User", "Password"); | ||
Assert.AreNotEqual(sourceObject.GetHashCode(), notEqualObject?.GetHashCode()); | ||
} | ||
|
||
[TestMethod] | ||
[SuppressMessage("ReSharper", "EqualExpressionComparison")] | ||
public void TestEqualsTrue() | ||
{ | ||
const string user = "User"; | ||
const string password = "Password"; | ||
var source = new WindowsInstanceCredentials(user, password); | ||
var target = new WindowsInstanceCredentials(user, password); | ||
Assert.IsTrue(source.Equals(source)); | ||
Assert.IsTrue(source.Equals(target)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetHashCodeEqual() | ||
{ | ||
const string user = "User"; | ||
const string password = "Password"; | ||
Assert.AreEqual( | ||
new WindowsInstanceCredentials(user, password).GetHashCode(), | ||
new WindowsInstanceCredentials(user, password).GetHashCode()); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
GoogleCloudExtension/GoogleCloudExtension.GCloud.UnitTests/packages.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net461" /> | ||
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net461" /> | ||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.