forked from bitbeans/zxcvbn-cs
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated spatial matcher tests and fixed the implementation.
- Loading branch information
1 parent
00e4bb0
commit fd9af54
Showing
3 changed files
with
71 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Zxcvbn.Matcher; | ||
using Zxcvbn.Matcher.Matches; | ||
|
||
namespace Zxcvbn.Tests.Matcher | ||
{ | ||
public class SpatialMatcherTests | ||
{ | ||
private readonly SpatialMatcher _matcher = new SpatialMatcher(); | ||
|
||
[Theory, InlineData(""), InlineData("/"), InlineData("qw"), InlineData("*/")] | ||
public void DoesNotmatch1And2CharacterPatterns(string password) | ||
{ | ||
var matches = _matcher.MatchPassword(password); | ||
|
||
matches.Should().BeEmpty(); | ||
} | ||
|
||
[Theory, InlineData("12345", "qwerty", 1, 0), InlineData("@WSX", "qwerty", 1, 4), InlineData("6tfGHJ", "qwerty", 2, 3), InlineData("hGFd", "qwerty", 1, 2), | ||
InlineData("/;p09876yhn", "qwerty", 3, 0), InlineData("Xdr%", "qwerty", 1, 2), InlineData("159-", "keypad", 1, 0), | ||
InlineData("*84", "keypad", 1, 0), InlineData("/8520", "keypad", 1, 0), InlineData("369", "keypad", 1, 0), InlineData("/963.", "mac_keypad", 1, 0), | ||
InlineData("*-632.0214", "mac_keypad", 9, 0), InlineData("aoEP%yIxkjq:", "dvorak", 4, 5), InlineData(";qoaOQ:Aoq;a", "dvorak", 11, 4)] | ||
public void MatchesKeyboardPattern(string pattern, string keyboard, int turns, int shifts) | ||
{ | ||
var matches = _matcher.MatchPassword(pattern).OfType<SpatialMatch>().ToList(); | ||
|
||
matches.Should().NotBeEmpty(); | ||
matches.Should().ContainSingle(s => s.Graph == keyboard); | ||
|
||
var match = matches.Single(m => m.Graph == keyboard); | ||
|
||
match.Turns.Should().Be(turns); | ||
match.ShiftedCount.Should().Be(shifts); | ||
match.i.Should().Be(0); | ||
match.j.Should().Be(pattern.Length - 1); | ||
match.Pattern.Should().Be("spatial"); | ||
} | ||
|
||
// [Fact] | ||
// public void MultipleSequencesMultipleKeyboards() | ||
// { | ||
// var sm = new SpatialMatcher(); | ||
|
||
// var res = sm.MatchPassword("plko14569852pyfdb").ToList(); | ||
// res.Count.Should().Be(6); | ||
// } | ||
|
||
// [Fact] | ||
// public void SingleSequence() | ||
// { | ||
// var sm = new SpatialMatcher(); | ||
|
||
// var res = sm.MatchPassword("qwert").ToList(); | ||
// res.Count.Should().Be(1); | ||
|
||
// res[0].i.Should().Be(0); | ||
// res[0].j.Should().Be(4); | ||
// res[0].Token.Should().Be("qwert"); | ||
// } | ||
} | ||
} |
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