-
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.
- Loading branch information
Showing
19 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Mailgun.Models.SignedEvent.Tests/Mailgun.Models.SignedEvent.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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="stylecop.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="stylecop.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Mailgun.Models.SignedEvent\Mailgun.Models.SignedEvent.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,91 @@ | ||
// <copyright file="MailgunSignatureTests.cs" company="Balazs Keresztury"> | ||
// Copyright (c) Balazs Keresztury. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mailgun.Models.SignedEvent.Tests | ||
{ | ||
/// <summary> | ||
/// Tests MailgunSignature. | ||
/// </summary> | ||
public class MailgunSignatureTests | ||
{ | ||
private DateTime _originalTimestamp; | ||
private TimeSpan _timeSinceOriginalTimestamp; | ||
private MailgunSignature _validSignature; | ||
private string _apiKey; | ||
|
||
/// <summary> | ||
/// Sets up test fixture with a know valid signature. | ||
/// </summary> | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
this._originalTimestamp = new DateTime(2020, 6, 18, 11, 55, 0).ToUniversalTime(); | ||
var originalTimestampAsUnixEpoch = (this._originalTimestamp - DateTime.UnixEpoch).TotalSeconds.ToString(); | ||
this._timeSinceOriginalTimestamp = DateTime.UtcNow - this._originalTimestamp; | ||
this._apiKey = "ffffffffffffffffffffffffffffffff-ffffffff-ffffffff"; | ||
|
||
this._validSignature = new MailgunSignature() | ||
{ | ||
Signature = "de4b938580bb4d84f710cbb8bfa7d224bb2262c8f644f558c2901c1ae645bb03", | ||
Token = "ffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
Timestamp = originalTimestampAsUnixEpoch, | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Checks if a valid signature returns as valid. | ||
/// </summary> | ||
[Test] | ||
public void Valid() | ||
{ | ||
Assert.That(this._validSignature.IsValid(this._apiKey, this._timeSinceOriginalTimestamp + new TimeSpan(0, 1, 0)), Is.True); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if a slightly old signature returns invalid. | ||
/// </summary> | ||
[Test] | ||
public void TooOld() | ||
{ | ||
Assert.That(this._validSignature.IsValid(this._apiKey, this._timeSinceOriginalTimestamp - new TimeSpan(0, 1, 0)), Is.False); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if changing the signature invalidates it. | ||
/// </summary> | ||
[Test] | ||
public void BadSignature() | ||
{ | ||
this._validSignature.Signature += "x"; | ||
|
||
Assert.That(this._validSignature.IsValid(this._apiKey, this._timeSinceOriginalTimestamp + new TimeSpan(0, 1, 0)), Is.False); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if changing the token invalidates the signature. | ||
/// </summary> | ||
[Test] | ||
public void BadToken() | ||
{ | ||
this._validSignature.Token += "x"; | ||
|
||
Assert.That(this._validSignature.IsValid(this._apiKey, this._timeSinceOriginalTimestamp + new TimeSpan(0, 1, 0)), Is.False); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if changing the API key invalidates the signature. | ||
/// </summary> | ||
[Test] | ||
public void BadApiKey() | ||
{ | ||
this._apiKey += "x"; | ||
|
||
Assert.That(this._validSignature.IsValid(this._apiKey, this._timeSinceOriginalTimestamp + new TimeSpan(0, 1, 0)), Is.False); | ||
} | ||
} | ||
} |
File renamed without changes.
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,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30204.135 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mailgun.Models.SignedEvent", "Mailgun.Models.SignedEvent\Mailgun.Models.SignedEvent.csproj", "{1BEB07E0-C800-45A1-990E-5F64962B8C9E}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mailgun.Models.SignedEvent.Tests", "Mailgun.Models.SignedEvent.Tests\Mailgun.Models.SignedEvent.Tests.csproj", "{8E4EF695-2A4F-4FF9-913D-541F4AF7F841}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1BEB07E0-C800-45A1-990E-5F64962B8C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1BEB07E0-C800-45A1-990E-5F64962B8C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1BEB07E0-C800-45A1-990E-5F64962B8C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1BEB07E0-C800-45A1-990E-5F64962B8C9E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8E4EF695-2A4F-4FF9-913D-541F4AF7F841}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8E4EF695-2A4F-4FF9-913D-541F4AF7F841}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8E4EF695-2A4F-4FF9-913D-541F4AF7F841}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8E4EF695-2A4F-4FF9-913D-541F4AF7F841}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {DC36B6DF-0548-4665-AF32-553ED3E0B3A4} | ||
EndGlobalSection | ||
EndGlobal |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion
6
Mailgun.Models.SignedEvent.csproj → ...edEvent/Mailgun.Models.SignedEvent.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", | ||
"settings": { | ||
"documentationRules": { | ||
"companyName": "Balazs Keresztury", | ||
"copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information.", | ||
"variables": { | ||
"licenseName": "MIT", | ||
"licenseFile": "LICENSE" | ||
} | ||
}, | ||
"orderingRules": { | ||
"usingDirectivesPlacement": "outsideNamespace" | ||
} | ||
} | ||
} |