-
Notifications
You must be signed in to change notification settings - Fork 6
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 #23 from mdsol/develop
Release of v2.4.0
- Loading branch information
Showing
7 changed files
with
121 additions
and
11 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
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,59 @@ | ||
using System; | ||
|
||
namespace Medidata.MAuth.Core | ||
{ | ||
/// <summary> | ||
/// Contains utility extension methods for MAuth. | ||
/// </summary> | ||
public static class UtilityExtensions | ||
{ | ||
/// <summary> | ||
/// Parses an MAuth authentication HTTP header value for the application uuid and the MAuth signature payload. | ||
/// If the parsing is not successful, an <see cref="ArgumentException"/> is thrown. | ||
/// </summary> | ||
/// <param name="headerValue"> | ||
/// The value of the X-MWS-Authentication HTTP header containing the application uuid and the MAuth signature | ||
/// payload. | ||
/// </param> | ||
/// <returns>The application uuid and the payload encoded with Base64 encoding.</returns> | ||
public static (Guid Uuid, string Base64Payload) ParseAuthenticationHeader(this string headerValue) => | ||
headerValue.TryParseAuthenticationHeader(out var result) ? | ||
result : | ||
throw new ArgumentException("Invalid MAuth authentication header value.", nameof(headerValue)); | ||
|
||
/// <summary> | ||
/// Parses an MAuth authentication HTTP header value for the application uuid and the MAuth signature payload. | ||
/// A return value indicates whether the parsing succeeded. | ||
/// </summary> | ||
/// <param name="headerValue"> | ||
/// The value of the X-MWS-Authentication HTTP header containing the application uuid and the MAuth signature | ||
/// payload. | ||
/// </param> | ||
/// <param name="result"> | ||
/// When this method returns, contains the application uuid and the Base64 encoded MAuth signature | ||
/// payload contained in <paramref name="headerValue"/> if the parsing succeeded, or the default value of a | ||
/// (<see cref="Guid"/>, <see cref="string"/>) tuple if the parsing failed. The parsing fails if the | ||
/// <paramref name="headerValue"/> is <see langword="null"/> or <see cref="string.Empty"/>, or not of the | ||
/// correct format. This parameter is passed uninitialized; any value originally supplied in | ||
/// <paramref name="result"/> will be overwritten.</param> | ||
/// <returns> | ||
/// <see langword="true"/> if <paramref name="headerValue"/> was parsed successfully; otherwise, | ||
/// <see langword="false"/>. | ||
/// </returns> | ||
public static bool TryParseAuthenticationHeader(this string headerValue, | ||
out (Guid Uuid, string Base64Payload) result) | ||
{ | ||
var match = Constants.AuthenticationHeaderRegex.Match(headerValue); | ||
|
||
result = default((Guid, string)); | ||
|
||
if (!match.Success) | ||
return false; | ||
|
||
result.Uuid = new Guid(match.Groups["uuid"].Value); | ||
result.Base64Payload = match.Groups["payload"].Value; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Medidata.MAuth.Core; | ||
using Medidata.MAuth.Tests.Infrastructure; | ||
using Xunit; | ||
|
||
namespace Medidata.MAuth.Tests | ||
{ | ||
public class UtilityExtensionsTest | ||
{ | ||
[Fact] | ||
public async Task TryParseAuthenticationHeader_WithValidAuthHeader_WillSucceed() | ||
{ | ||
// Arrange | ||
var request = await TestData.For("GET"); | ||
var expected = (TestExtensions.ClientUuid, request.Payload); | ||
|
||
// Act | ||
var result = request.MAuthHeader.TryParseAuthenticationHeader(out var actual); | ||
|
||
// Assert | ||
Assert.True(result); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void TryParseAuthenticationHeader_WithInvalidAuthHeader_WillFail() | ||
{ | ||
// Arrange | ||
var invalid = "invalid"; | ||
|
||
// Act | ||
var result = invalid.TryParseAuthenticationHeader(out var actual); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void ParseAuthenticationHeader_WithInvalidAuthHeader_WillThrowException() | ||
{ | ||
// Arrange | ||
var invalid = "invalid"; | ||
|
||
// Act, Assert | ||
Assert.Throws<ArgumentException>(() => invalid.ParseAuthenticationHeader()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project> | ||
<PropertyGroup> | ||
<Version>2.3.0</Version> | ||
<Version>2.4.0</Version> | ||
</PropertyGroup> | ||
</Project> |