Initial commit: SWP.Core enterprise framework with multi-tenant architecture, configuration management, security, telemetry and comprehensive test suite
This commit is contained in:
commit
5275a75502
87 changed files with 6140 additions and 0 deletions
86
Tests/PasswordHasherTest.cs
Normal file
86
Tests/PasswordHasherTest.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Sodium;
|
||||
|
||||
namespace SWP.Core.X.TDD;
|
||||
|
||||
[TestClass]
|
||||
public class PasswordHasherTests : TestFixture
|
||||
{
|
||||
[TestMethod]
|
||||
public void MyTestMethod()
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
||||
var salt = PasswordHash.ScryptGenerateSalt();
|
||||
|
||||
// 2. Konverter password til byte[]
|
||||
var passwordBytes = Encoding.UTF8.GetBytes("password123");
|
||||
|
||||
// 3. Kald ScryptHashBinary korrekt
|
||||
var hash = PasswordHash.ScryptHashBinary(
|
||||
passwordBytes,
|
||||
salt
|
||||
);
|
||||
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HashPassword_ShouldCreateValidHashFormat()
|
||||
{
|
||||
// Arrange
|
||||
var password = "TestPassword123";
|
||||
|
||||
// Act
|
||||
var hashedPassword = new SecureTokenizer().TokenizeText(password);
|
||||
var parts = hashedPassword.Split('.');
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(3, parts.Length);
|
||||
Assert.AreEqual("100000", parts[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyPassword_WithCorrectPassword_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
var password = "TestPassword123";
|
||||
var hashedPassword = new SecureTokenizer().TokenizeText(password);
|
||||
|
||||
// Act
|
||||
var result = new SecureTokenizer().VerifyToken(hashedPassword, password);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyPassword_WithWrongPassword_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
var correctPassword = "TestPassword123";
|
||||
var wrongPassword = "WrongPassword123";
|
||||
var hashedPassword = new SecureTokenizer().TokenizeText(correctPassword);
|
||||
|
||||
// Act
|
||||
var result = new SecureTokenizer().VerifyToken(hashedPassword, wrongPassword);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyPassword_WithInvalidHashFormat_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
var password = "TestPassword123";
|
||||
var invalidHash = "InvalidHash";
|
||||
|
||||
// Act
|
||||
var result = new SecureTokenizer().VerifyToken(invalidHash, password);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue