forked from FantasticFiasco/aws-signature-version-4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix default request headers are added twice on Android using Mono (Fa…
…ntasticFiasco#29) The behavior on Mono is different from the behavior on .NET Framework or .NET Core, where a default request header that already exists on the request message is ignored. Closes FantasticFiasco#28
- Loading branch information
1 parent
4bd7b8c
commit a415cc9
Showing
9 changed files
with
237 additions
and
55 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace AwsSignatureVersion4.Private | ||
{ | ||
public class EnvironmentProbe | ||
{ | ||
private readonly Lazy<bool> isMono; | ||
|
||
public EnvironmentProbe() | ||
{ | ||
isMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null); | ||
} | ||
|
||
public virtual bool IsMono => isMono.Value; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Net.Http; | ||
using AwsSignatureVersion4.Private; | ||
using AwsSignatureVersion4.TestSuite; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace AwsSignatureVersion4.Unit.Private | ||
{ | ||
public class CanonicalRequestGivenDotnetShould : IClassFixture<TestSuiteContext>, IDisposable | ||
{ | ||
private readonly TestSuiteContext context; | ||
private readonly EnvironmentProbe defaultEnvironmentProbe; | ||
|
||
public CanonicalRequestGivenDotnetShould(TestSuiteContext context) | ||
{ | ||
this.context = context; | ||
|
||
context.AdjustHeaderValueSeparator(); | ||
|
||
// Mock .NET environment | ||
defaultEnvironmentProbe = CanonicalRequest.EnvironmentProbe; | ||
CanonicalRequest.EnvironmentProbe = new DotnetEnvironmentProbe(); | ||
} | ||
|
||
[Fact] | ||
public void RespectDefaultHeader() | ||
{ | ||
// Arrange | ||
var headers = new HttpRequestMessage().Headers; | ||
|
||
var defaultHeaders = new HttpRequestMessage().Headers; | ||
defaultHeaders.Add("some-header-name", "some-header-value"); | ||
|
||
// Act | ||
var actual = CanonicalRequest.SortHeaders(headers, defaultHeaders); | ||
|
||
// Assert | ||
actual["some-header-name"].ShouldBe(new[] { "some-header-value" }); | ||
} | ||
|
||
[Fact] | ||
public void IgnoreDuplicateDefaultHeader() | ||
{ | ||
// Arrange | ||
var headers = new HttpRequestMessage().Headers; | ||
headers.Add("some-header-name", "some-header-value"); | ||
|
||
var defaultHeaders = new HttpRequestMessage().Headers; | ||
defaultHeaders.Add("some-header-name", "some-ignored-header-value"); | ||
|
||
// Act | ||
var actual = CanonicalRequest.SortHeaders(headers, defaultHeaders); | ||
|
||
// Assert | ||
actual["some-header-name"].ShouldBe(new[] { "some-header-value" }); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Reset header value separator | ||
context.ResetHeaderValueSeparator(); | ||
|
||
// Reset environment probe | ||
CanonicalRequest.EnvironmentProbe = defaultEnvironmentProbe; | ||
} | ||
|
||
private class DotnetEnvironmentProbe : EnvironmentProbe | ||
{ | ||
public override bool IsMono { get; } = false; | ||
} | ||
} | ||
} |
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,73 @@ | ||
using System; | ||
using System.Net.Http; | ||
using AwsSignatureVersion4.Private; | ||
using AwsSignatureVersion4.TestSuite; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace AwsSignatureVersion4.Unit.Private | ||
{ | ||
public class CanonicalRequestGivenMonoShould : IClassFixture<TestSuiteContext>, IDisposable | ||
{ | ||
private readonly TestSuiteContext context; | ||
private readonly EnvironmentProbe defaultEnvironmentProbe; | ||
|
||
public CanonicalRequestGivenMonoShould(TestSuiteContext context) | ||
{ | ||
this.context = context; | ||
|
||
context.AdjustHeaderValueSeparator(); | ||
|
||
// Mock Mono environment | ||
defaultEnvironmentProbe = CanonicalRequest.EnvironmentProbe; | ||
CanonicalRequest.EnvironmentProbe = new MonoEnvironmentProbe(); | ||
} | ||
|
||
[Fact] | ||
public void RespectDefaultHeader() | ||
{ | ||
// Arrange | ||
var headers = new HttpRequestMessage().Headers; | ||
|
||
var defaultHeaders = new HttpRequestMessage().Headers; | ||
defaultHeaders.Add("some-header-name", "some-header-value"); | ||
|
||
// Act | ||
var actual = CanonicalRequest.SortHeaders(headers, defaultHeaders); | ||
|
||
// Assert | ||
actual["some-header-name"].ShouldBe(new[] { "some-header-value" }); | ||
} | ||
|
||
[Fact] | ||
public void RespectDuplicateDefaultHeader() | ||
{ | ||
// Arrange | ||
var headers = new HttpRequestMessage().Headers; | ||
headers.Add("some-header-name", "some-header-value"); | ||
|
||
var defaultHeaders = new HttpRequestMessage().Headers; | ||
defaultHeaders.Add("some-header-name", "some-other-header-value"); | ||
|
||
// Act | ||
var actual = CanonicalRequest.SortHeaders(headers, defaultHeaders); | ||
|
||
// Assert | ||
actual["some-header-name"].ShouldBe(new[] { "some-header-value", "some-other-header-value" }); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Reset header value separator | ||
context.ResetHeaderValueSeparator(); | ||
|
||
// Reset environment probe | ||
CanonicalRequest.EnvironmentProbe = defaultEnvironmentProbe; | ||
} | ||
|
||
private class MonoEnvironmentProbe : EnvironmentProbe | ||
{ | ||
public override bool IsMono { get; } = 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
Oops, something went wrong.