-
-
Notifications
You must be signed in to change notification settings - Fork 36
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 #85 from NicolasConstant/develop
0.14.0 PR
- Loading branch information
Showing
7 changed files
with
103 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace BirdsiteLive.Common.Regexes | ||
{ | ||
public class HeaderRegexes | ||
{ | ||
public static readonly Regex HeaderSignature = new Regex(@"^([a-zA-Z0-9]+)=""(.+)""$"); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/Tests/BirdsiteLive.Common.Tests/BirdsiteLive.Common.Tests.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" /> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\BirdsiteLive.Common\BirdsiteLive.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
53 changes: 53 additions & 0 deletions
53
src/Tests/BirdsiteLive.Common.Tests/Regexes/HeaderRegexTests.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,53 @@ | ||
using BirdsiteLive.Common.Regexes; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace BirdsiteLive.Common.Tests | ||
{ | ||
[TestClass] | ||
public class HeaderRegexTests | ||
{ | ||
[TestMethod] | ||
public void KeyId_Test() | ||
{ | ||
var input = @"keyId=""https://misskey.tdl/users/8hwf6zy2k1#main-key"""; | ||
|
||
Assert.IsTrue(HeaderRegexes.HeaderSignature.IsMatch(input)); | ||
var result = HeaderRegexes.HeaderSignature.Match(input); | ||
Assert.AreEqual("keyId", result.Groups[1].ToString()); | ||
Assert.AreEqual("https://misskey.tdl/users/8hwf6zy2k1#main-key", result.Groups[2].ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Algorithm_Test() | ||
{ | ||
var input = @"algorithm=""rsa-sha256"""; | ||
|
||
Assert.IsTrue(HeaderRegexes.HeaderSignature.IsMatch(input)); | ||
var result = HeaderRegexes.HeaderSignature.Match(input); | ||
Assert.AreEqual("algorithm", result.Groups[1].ToString()); | ||
Assert.AreEqual("rsa-sha256", result.Groups[2].ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Target_Test() | ||
{ | ||
var input = @"headers=""(request-target) date host digest"""; | ||
|
||
Assert.IsTrue(HeaderRegexes.HeaderSignature.IsMatch(input)); | ||
var result = HeaderRegexes.HeaderSignature.Match(input); | ||
Assert.AreEqual("headers", result.Groups[1].ToString()); | ||
Assert.AreEqual("(request-target) date host digest", result.Groups[2].ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Signature_Test() | ||
{ | ||
var input = @"signature=""ISxp4HYhkGc83SsCC3zNZMVKBota7HqgWVg6KwaQVTQcUqt+UsWXPxB0XPhaYkqLnH3hJ+KVMdoEn3rbzcw8XZpjVt48o9OAKd0rsEZYkLoERnnFFhEw0GmVDEhdoU7gyoeOreWGsIca6Pf7TC0vGTtqez31zmvoeXvxHgqRhWQvlZM/ovFR2xN+vhmF7rZdkd6UaKOzy21K8B/Q84J7PWdbJ8i0rKieVPDIuTCy5B0iQpgs1TMaz6xKZR/KVzAr207m9Gkku2gnJ4YZHFuoa2ct5M5AtIPMPCsWTU8yaimTkPdNNezSOKV5a7T55HSvFeopLNcQKsWNMioKGpZP5hCIRKNk0Ekx0yDReE6xF/qliT7eSAGVJ/6sLQjBpBFMPKBNOrYTxueBJGtISjCZlxaIyTtJ1ErNuCrKHGjImpNvvJzTJOtu+vWnjTcUJL7N1Mw7PEreCZrNUyNuAldDWSMAFuD4HVA3+KZjpWCfjAbyelzVy2gs96CyE56o9FqJEaM5XVQhsMTpa8OSHdr2QZtKYw7Wng0d8vmbKEX1pdTVeEIhi4M9js39ZdzB4mb8JXSBE/GA6PoE5s+oH3+GoufzJYINCpk0Ulwo9g7HKm9NATnwEZZPq4NKto5mSYZKYRtqjZaa8lIALNhdvzv2+8+ifPLHlOigAUVqoupd9Aq="""; | ||
|
||
Assert.IsTrue(HeaderRegexes.HeaderSignature.IsMatch(input)); | ||
var result = HeaderRegexes.HeaderSignature.Match(input); | ||
Assert.AreEqual("signature", result.Groups[1].ToString()); | ||
Assert.AreEqual("ISxp4HYhkGc83SsCC3zNZMVKBota7HqgWVg6KwaQVTQcUqt+UsWXPxB0XPhaYkqLnH3hJ+KVMdoEn3rbzcw8XZpjVt48o9OAKd0rsEZYkLoERnnFFhEw0GmVDEhdoU7gyoeOreWGsIca6Pf7TC0vGTtqez31zmvoeXvxHgqRhWQvlZM/ovFR2xN+vhmF7rZdkd6UaKOzy21K8B/Q84J7PWdbJ8i0rKieVPDIuTCy5B0iQpgs1TMaz6xKZR/KVzAr207m9Gkku2gnJ4YZHFuoa2ct5M5AtIPMPCsWTU8yaimTkPdNNezSOKV5a7T55HSvFeopLNcQKsWNMioKGpZP5hCIRKNk0Ekx0yDReE6xF/qliT7eSAGVJ/6sLQjBpBFMPKBNOrYTxueBJGtISjCZlxaIyTtJ1ErNuCrKHGjImpNvvJzTJOtu+vWnjTcUJL7N1Mw7PEreCZrNUyNuAldDWSMAFuD4HVA3+KZjpWCfjAbyelzVy2gs96CyE56o9FqJEaM5XVQhsMTpa8OSHdr2QZtKYw7Wng0d8vmbKEX1pdTVeEIhi4M9js39ZdzB4mb8JXSBE/GA6PoE5s+oH3+GoufzJYINCpk0Ulwo9g7HKm9NATnwEZZPq4NKto5mSYZKYRtqjZaa8lIALNhdvzv2+8+ifPLHlOigAUVqoupd9Aq=", result.Groups[2].ToString()); | ||
} | ||
} | ||
} |