* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Security;
|
|
using Umbraco.Cms.Infrastructure.Security;
|
|
using Umbraco.Cms.Infrastructure.Serialization;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Security
|
|
{
|
|
[TestFixture]
|
|
public class MemberPasswordHasherTests
|
|
{
|
|
private MemberPasswordHasher CreateSut() => new MemberPasswordHasher(new LegacyPasswordSecurity(), new JsonNetSerializer());
|
|
|
|
[Test]
|
|
public void VerifyHashedPassword_GivenAnAspNetIdentity2PasswordHash_ThenExpectSuccessRehashNeeded()
|
|
{
|
|
const string password = "Password123!";
|
|
const string hash = "AJszAsQqxOYbASKfL3JVUu6cjU18ouizXDfX4j7wLlir8SWj2yQaTepE9e5bIohIsQ==";
|
|
|
|
var sut = CreateSut();
|
|
var result = sut.VerifyHashedPassword(new MemberIdentityUser(), hash, password);
|
|
|
|
Assert.AreEqual(result, PasswordVerificationResult.SuccessRehashNeeded);
|
|
}
|
|
|
|
[Test]
|
|
public void VerifyHashedPassword_GivenAnAspNetCoreIdentityPasswordHash_ThenExpectSuccess()
|
|
{
|
|
const string password = "Password123!";
|
|
const string hash = "AQAAAAEAACcQAAAAEGF/tTVoL6ef3bQPZFYfbgKFu1CDQIAMgyY1N4EDt9jqdG/hsOX93X1U6LNvlIQ3mw==";
|
|
|
|
var sut = CreateSut();
|
|
var result = sut.VerifyHashedPassword(new MemberIdentityUser(), hash, password);
|
|
|
|
Assert.AreEqual(result, PasswordVerificationResult.Success);
|
|
}
|
|
|
|
[Test]
|
|
public void VerifyHashedPassword_GivenALegacyPasswordHash_ThenExpectSuccessRehashNeeded()
|
|
{
|
|
const string password = "Password123!";
|
|
const string hash = "yDiU2YyuYZU4jz6F0fpErQ==BxNRHkXBVyJs9gwWF6ktWdfDwYf5bwm+rvV7tOcNNx8=";
|
|
|
|
var sut = CreateSut();
|
|
var result = sut.VerifyHashedPassword(new MemberIdentityUser(), hash, password);
|
|
|
|
Assert.AreEqual(result, PasswordVerificationResult.SuccessRehashNeeded);
|
|
}
|
|
|
|
[Test]
|
|
public void VerifyHashedPassword_GivenAnUnknownBase64Hash_ThenExpectInvalidOperationException()
|
|
{
|
|
var hashBytes = new byte[] {3, 2, 1};
|
|
var hash = Convert.ToBase64String(hashBytes);
|
|
|
|
var sut = CreateSut();
|
|
Assert.Throws<InvalidOperationException>(() => sut.VerifyHashedPassword(new MemberIdentityUser(), hash, "password"));
|
|
}
|
|
|
|
[TestCase("AJszAsQqxOYbASKfL3JVUu6cjU18ouizXDfX4j7wLlir8SWj2yQaTepE9e5bIohIsQ==")]
|
|
[TestCase("AQAAAAEAACcQAAAAEGF/tTVoL6ef3bQPZFYfbgKFu1CDQIAMgyY1N4EDt9jqdG/hsOX93X1U6LNvlIQ3mw==")]
|
|
[TestCase("yDiU2YyuYZU4jz6F0fpErQ==BxNRHkXBVyJs9gwWF6ktWdfDwYf5bwm+rvV7tOcNNx8=")]
|
|
public void VerifyHashedPassword_GivenAnInvalidPassword_ThenExpectFailure(string hash)
|
|
{
|
|
const string invalidPassword = "nope";
|
|
|
|
var sut = CreateSut();
|
|
var result = sut.VerifyHashedPassword(new MemberIdentityUser(), hash, invalidPassword);
|
|
|
|
Assert.AreEqual(result, PasswordVerificationResult.Failed);
|
|
}
|
|
}
|
|
}
|