Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding null check for innerException. Adding tests #4598

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Test Project for Microsoft.Rest.ClientRuntime.Azure.Authentication</Description>
<Version>1.0.0</Version>
<AssemblyName>Az.Auth.Net452.Tests</AssemblyName>
<PackageId>Az.Auth.Net452.Tests</PackageId>
<PackageTags>Net452Tests AzAuthNet452 Test $(NugetCommonTags) $(NugetCommonProfileTags)</PackageTags>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Az.Authentication\Microsoft.Rest.ClientRuntime.Azure.Authentication.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>



<!--
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('packages\xunit.core.2.3.1\build\xunit.core.props')" />
Expand Down Expand Up @@ -104,4 +136,5 @@
<Error Condition="!Exists('packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('packages\xunit.core.2.3.1\build\xunit.core.targets')" />
</Project>
</Project>
-->
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Az.Auth.Net452.Test
{
public class CertAuthTests : TestBase
public class CertAuthTests : AuthFullDesktopTestBase
{
public CertAuthTests()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Az.Auth.Net452.Test
{
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest.Azure.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

public class Net452ExceptionsTests
{
[Fact]
public void AuthExceptionWithInnerException()
{
AuthenticationException authExToBeThrown = null;
string authError = "Error Occured";
try
{
var token = ApplicationTokenProvider.LoginSilentAsync("SomeDomain", "clientId", "someText").GetAwaiter().GetResult();
}
catch(AdalException adalEx)
{
authExToBeThrown = new AuthenticationException(authError, adalEx);
}

Assert.NotNull(authExToBeThrown);
Assert.Equal(authError, authExToBeThrown.Message);
}

#if FullNetFx
[Fact]
public void AuthExceptionWithNullInnerException()
{
AuthenticationException authExToBeThrown = null;
string authError = "Error Occured";
try
{
ClientCredential cc = new ClientCredential("SomeClientId", "SomethingSomething");
ActiveDirectoryServiceSettings adSvcSettings = new ActiveDirectoryServiceSettings()
{
AuthenticationEndpoint = new Uri("https://randomEndPoint"),
TokenAudience = new Uri("https://SomeUri"),
ValidateAuthority = true
};

var token = ApplicationTokenProvider.LoginSilentAsync( "SomeDomain", cc, adSvcSettings).GetAwaiter().GetResult();
}
catch (AdalException adalEx)
{
authExToBeThrown = new AuthenticationException(authError);
}

Assert.NotNull(authExToBeThrown);
Assert.Equal(authError, authExToBeThrown.Message);
}
#endif

}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Az.Auth.Net452.Test
{
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



public class TestBase
public class AuthFullDesktopTestBase
{
//private string LiteralCnnString = string.Empty;

private bool IsLiteralDirty = false;
private string _literalCnnString;
private ConnectionString _cs;
Expand Down Expand Up @@ -86,11 +85,11 @@ public TestEndpoints CloudEndPoints
}


public TestBase(string connectionString)
public AuthFullDesktopTestBase(string connectionString)
{
LiteralCnnString = connectionString;
}

public TestBase() { LiteralCnnString = string.Empty; }
public AuthFullDesktopTestBase() { LiteralCnnString = string.Empty; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Az.Auth.Net452.Test
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Az.Auth.Net452.Test
{
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
Expand All @@ -9,7 +12,7 @@
using System.Threading;
using System.Threading.Tasks;

public class UserLogin: TestBase
public class UserLogin: AuthFullDesktopTestBase
{
public UserLogin() : base()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Test Project for Microsoft.Rest.ClientRuntime.Azure.Authentication</Description>
<Version>1.0.0</Version>
<AssemblyName>Az.Auth.NetCore.Tests</AssemblyName>
<PackageId>Az.Auth.NetCore.Tests</PackageId>
<PackageTags>NetCoreTests AzAuthNetCore Test $(NugetCommonTags) $(NugetCommonProfileTags)</PackageTags>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Test Project for Microsoft.Rest.ClientRuntime.Azure.Authentication</Description>
<Version>1.0.0</Version>
<AssemblyName>Az.Auth.FullDesktop.Tests</AssemblyName>
<PackageId>Az.Auth.FullDesktop.Tests</PackageId>
<PackageTags>FullDesktopTests AzAuthFullDesktop Test $(NugetCommonTags) $(NugetCommonProfileTags)</PackageTags>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Az.Authentication\Microsoft.Rest.ClientRuntime.Azure.Authentication.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>

<!--
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props" Condition="Exists('..\..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props')" />
Expand Down Expand Up @@ -89,4 +119,5 @@
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
</Project>
</Project>
-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Az.Auth.FullDesktop.Test
{
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest.Azure.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

public class ExceptionsTests
{
[Fact]
public void AuthExceptionWithInnerException()
{
AuthenticationException authExToBeThrown = null;
string authError = "Error Occured";
try
{
var token = ApplicationTokenProvider.LoginSilentAsync("SomeDomain", "clientId", "someText").GetAwaiter().GetResult();
}
catch(AdalException adalEx)
{
authExToBeThrown = new AuthenticationException(authError, adalEx);
}

Assert.NotNull(authExToBeThrown);
Assert.Equal(authError, authExToBeThrown.Message);
}

[Fact]
public void AuthExceptionWithNullInnerException()
{
AuthenticationException authExToBeThrown = null;
string authError = "Error Occured";
try
{
ClientCredential cc = new ClientCredential("SomeClientId", "SomethingSomething");
ActiveDirectoryServiceSettings adSvcSettings = new ActiveDirectoryServiceSettings()
{
AuthenticationEndpoint = new Uri("https://randomEndPoint"),
TokenAudience = new Uri("https://SomeUri"),
ValidateAuthority = true
};

var token = ApplicationTokenProvider.LoginSilentAsync( "SomeDomain", cc, adSvcSettings).GetAwaiter().GetResult();
}
catch (AdalException adalEx)
{
authExToBeThrown = new AuthenticationException(authError);
}

Assert.NotNull(authExToBeThrown);
Assert.Equal(authError, authExToBeThrown.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AuthenticationException(string message, Exception innerException)
/// <param name="message">The exception message</param>
/// <param name="innerException">The inner AdalException with additional details</param>
internal AuthenticationException(string message, AdalException innerException) :
base(string.Format(CultureInfo.CurrentCulture, message, innerException.Message), innerException)
base(string.Format(CultureInfo.CurrentCulture, message, (innerException == null)? string.Empty : innerException?.Message ), innerException)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)'=='net461' ">
<DefineConstants>net461;FullNetFx</DefineConstants>
<DefineConstants>net461</DefineConstants>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
Expand Down

This file was deleted.

Loading