-
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
Haik
committed
Oct 16, 2023
1 parent
82427bd
commit 28813e8
Showing
5 changed files
with
147 additions
and
67 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
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,45 @@ | ||
namespace Pandatech.Crypto.Tests; | ||
|
||
public class Argon2IdTests | ||
{ | ||
[Fact] | ||
public void HashVerify_ShouldBeValid() | ||
{ | ||
var password = RandomPassword.Generate(32, true, true, true, true); | ||
var hash = Argon2Id.HashPassword(password); | ||
|
||
Assert.True(Argon2Id.VerifyHash(password, hash)); | ||
} | ||
|
||
[Fact] | ||
public void HashVerify_InvalidPassword_ShouldBeInvalid() | ||
{ | ||
var password = RandomPassword.Generate(32, true, true, true, true); | ||
var hash = Argon2Id.HashPassword(password); | ||
|
||
|
||
} | ||
|
||
[Fact] | ||
public void DifferentPasswords_ShouldHaveDifferentHashes() | ||
{ | ||
var password1 = RandomPassword.Generate(32, true, true, true, true); | ||
var password2 = RandomPassword.Generate(32, true, true, true, true); | ||
var hash1 = Argon2Id.HashPassword(password1); | ||
var hash2 = Argon2Id.HashPassword(password2); | ||
|
||
Assert.NotEqual(hash1, hash2); | ||
} | ||
|
||
[Fact] | ||
public void HashPassword_EmptyPassword_ShouldThrowException() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Argon2Id.HashPassword("")); | ||
} | ||
|
||
[Fact] | ||
public void VerifyHash_NullHash_ShouldThrowException() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Argon2Id.VerifyHash("password", null!)); | ||
} | ||
} |
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,42 @@ | ||
namespace Pandatech.Crypto.Tests; | ||
|
||
public class RandomPasswordTests | ||
{ | ||
[Theory] | ||
[InlineData(7, true, true, true, true)] | ||
[InlineData(4, false, true, false, false)] | ||
[InlineData(5, true, true, true, false)] | ||
public void Generate_ShouldReturnPasswordWithCorrectProperties( | ||
int length, | ||
bool includeUppercase, | ||
bool includeLowercase, | ||
bool includeDigits, | ||
bool includeSpecialChars) | ||
{ | ||
// Generate a random password | ||
var password = RandomPassword.Generate(length, includeUppercase, includeLowercase, includeDigits, | ||
includeSpecialChars); | ||
|
||
// Check if the password length is correct | ||
Assert.Equal(length, password.Length); | ||
|
||
// Check if the password contains the correct character sets | ||
if (includeUppercase) | ||
Assert.Contains(password, char.IsUpper); | ||
if (includeLowercase) | ||
Assert.Contains(password, char.IsLower); | ||
if (includeDigits) | ||
Assert.Contains(password, char.IsDigit); | ||
if (includeSpecialChars) | ||
Assert.Contains(password, c => "!@#$%^&*()-_=+[]{}|;:'\",.<>?".Contains(c)); | ||
} | ||
|
||
[Fact] | ||
public void Generate_ShouldReturnDifferentPasswords() | ||
{ | ||
var password1 = RandomPassword.Generate(12, true, true, true, true); | ||
var password2 = RandomPassword.Generate(12, true, true, true, true); | ||
|
||
Assert.NotEqual(password1, password2); | ||
} | ||
} |
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