Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Missing Unit Test for GetPossibleConfig #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions csharp-password-hash/csharp-password-hash.Test/PasswordHashTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class PasswordHashTest
private const string GlobalSalt= "SecureSalt";
private const string CorrectPassword = "CorrectPassword";
private const string SaltedPasswordFormat = Constants.PasswordPlaceHolder+"--"+Constants.SaltPlaceHolder;
private const string DefaultSaltedPasswordFormat = "#PasswordPlaceHolder#--#SaltPlaceHolder#";

public class WhenPerPasswordSaltTrue
{
Expand Down Expand Up @@ -225,6 +226,17 @@ public void Correct_Hash_Values_Should_Match_GetHash(HashingAlgo hashingAlgo, st

Assert.Equal(hashExpected,hashActual);
}

[Theory]
[ClassData(typeof(TestHashFinderDataGenerator))]
public void Correct_Hashing_Config_Should_Match_GetPossibleConfig(HashingAlgo expectedHashingAlgo, EncodingType expectedEncodingType, string inputHash)
{
var passwordHashing = new PasswordHashing();
var hashingConfigActual = passwordHashing.GetPossibleConfig(CorrectPassword, GlobalSalt, DefaultSaltedPasswordFormat, inputHash);

Assert.Equal(expectedHashingAlgo, hashingConfigActual.HashingAlgo);
Assert.Equal(expectedEncodingType, hashingConfigActual.PasswordHashEncodingType);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;


namespace CSharpPasswordHash.Test
{
public class TestHashFinderDataGenerator : IEnumerable<object[]>
{
private readonly List<object[]> _data = new List<object[]>
{
/* Hash values generated using the following HashingConfig
#PasswordPlaceHolder#: CorrectPassword
#SaltPlaceHolder#: SecureSalt

{CSharpPasswordHash.HashingConfig}
GeneratePerPasswordSalt: false
GlobalSalt: "SecureSalt"
PasswordHashEncodingType: CSharpPasswordHash.EncodingType.Default/Base64
SaltedPasswordFormat: "#PasswordPlaceHolder#--#SaltPlaceHolder#"
*/
new object[] { HashingAlgo.SHA1, EncodingType.Default, "fe380f9845fd3cf4d9b83422913a0c56ff51ef2e"},
new object[] { HashingAlgo.SHA1, EncodingType.Base64, "/jgPmEX9PPTZuDQikToMVv9R7y4="},
new object[] { HashingAlgo.SHA256, EncodingType.Default, "8e508309d85194826dd92cba809a793299905de164be4f5a7aa5232c5ffd9845"},
new object[] { HashingAlgo.SHA256, EncodingType.Base64, "jlCDCdhRlIJt2Sy6gJp5MpmQXeFkvk9aeqUjLF/9mEU="},
new object[] { HashingAlgo.HMAC_SHA1, EncodingType.Default, "b64c470ec33564f921da7ccd3223a7800797322b" },
new object[] { HashingAlgo.HMAC_SHA1, EncodingType.Base64, "tkxHDsM1ZPkh2nzNMiOngAeXMis="},
new object[] { HashingAlgo.HMAC_SHA256, EncodingType.Default, "2d8b2eb164fd8424860048e63ecde73bdcad8f198ece060416b8481ee851baa6"},
new object[] { HashingAlgo.HMAC_SHA256, EncodingType.Base64, "LYsusWT9hCSGAEjmPs3nO9ytjxmOzgYEFrhIHuhRuqY="},
new object[] { HashingAlgo.MD5, EncodingType.Default, "923d89cde8c404a0f182474abb4ddfad" },
new object[] { HashingAlgo.MD5, EncodingType.Base64, "kj2JzejEBKDxgkdKu03frQ==" }
};

public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}