-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from aspriddell/add-new-handler-wrappers
Add new ssl bypass handler
- Loading branch information
Showing
7 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
...onFruit.Common.Data.Tests/Handlers/AuthPreservingHandler/HeaderPreservingHandlerClient.cs
This file was deleted.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
DragonFruit.Common.Data.Tests/Handlers/InsecureSslVerificationHandlerTests.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,47 @@ | ||
// DragonFruit.Common Copyright 2020 DragonFruit Network | ||
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Security.Authentication; | ||
using DragonFruit.Common.Data.Basic; | ||
using DragonFruit.Common.Data.Handlers; | ||
using NUnit.Framework; | ||
|
||
#pragma warning disable 618 | ||
|
||
namespace DragonFruit.Common.Data.Tests.Handlers | ||
{ | ||
[TestFixture] | ||
public class InsecureSslVerificationHandlerTests | ||
{ | ||
[Test] | ||
public void TestSslVerificationHandler() | ||
{ | ||
var client = new ApiClient(); | ||
var request = new BasicApiRequest("http://wrong.host.badssl.com/"); | ||
|
||
try | ||
{ | ||
client.Perform(request); | ||
Assert.Fail("Request must fail when SSL validation is enabled"); | ||
} | ||
// .NET Standard 2 returns aggregate exception | ||
catch (AggregateException e) | ||
{ | ||
var innerExceptions = e.InnerExceptions.Select(x => x.InnerException); | ||
Assert.IsTrue(innerExceptions.Any(x => x is AuthenticationException)); | ||
} | ||
// .NET 5 returns a non-aggregated copy of above | ||
catch (HttpRequestException e) | ||
{ | ||
Assert.IsTrue(e.InnerException is AuthenticationException); | ||
} | ||
|
||
// set handler and go again | ||
client.Handler = () => new InsecureSslVerificationHandler(); | ||
Assert.IsTrue(client.Perform(request).IsSuccessStatusCode); | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
DragonFruit.Common.Data/Handlers/InsecureSslVerificationHandler.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,20 @@ | ||
// DragonFruit.Common Copyright 2020 DragonFruit Network | ||
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details | ||
|
||
using System; | ||
using System.Net.Http; | ||
|
||
namespace DragonFruit.Common.Data.Handlers | ||
{ | ||
[Obsolete(nameof(InsecureSslVerificationHandler) + "is insecure and should only be used for testing/development purposes")] | ||
public class InsecureSslVerificationHandler : HttpClientHandler | ||
{ | ||
public InsecureSslVerificationHandler() | ||
{ | ||
ServerCertificateCustomValidationCallback = delegate | ||
{ | ||
return true; | ||
}; | ||
} | ||
} | ||
} |
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