-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding null check for innerException. Adding tests (#4598)
- Loading branch information
1 parent
91f56d7
commit 86691ee
Showing
12 changed files
with
243 additions
and
58 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
src/SdkCommon/Auth/Az.Auth/Az.Auth.Tests/Az.Auth.Net452.Test/Net452ExceptionsTests.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,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 | ||
|
||
} | ||
} |
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
9 changes: 8 additions & 1 deletion
9
src/SdkCommon/Auth/Az.Auth/Az.Auth.Tests/Az.Auth.NetCore.Test/Az.Auth.NetCore.Test.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
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
61 changes: 61 additions & 0 deletions
61
src/SdkCommon/Auth/Az.Auth/Az.Auth.Tests/FullDesktop.Tests/ExceptionsTests.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,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); | ||
} | ||
} | ||
} |
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
37 changes: 0 additions & 37 deletions
37
src/SdkCommon/Auth/Az.Auth/Microsoft.Rest.ClientRuntime.Azure.Authentication.sln
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.