Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-rc0'
Browse files Browse the repository at this point in the history
  • Loading branch information
belidzs committed Jun 18, 2020
2 parents 6cef3dc + e919ec7 commit 2a60c0a
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 1 deletion.
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>
91 changes: 91 additions & 0 deletions Mailgun.Models.SignedEvent.Tests/MailgunSignatureTests.cs
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.
31 changes: 31 additions & 0 deletions Mailgun.Models.SignedEvent.sln
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.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
<Authors>Balazs Keresztury</Authors>
<Copyright>Copyright (c) 2020 Balazs Keresztury</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.0.0-rc0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Mailgun.Models.SignedEvent/stylecop.json
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"
}
}
}

0 comments on commit 2a60c0a

Please sign in to comment.