-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from BrandonPotter/feature/configurablePeriod…
…Length206 Allow configuration of TimeStep
- Loading branch information
Showing
7 changed files
with
119 additions
and
92 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,38 @@ | ||
using Xunit; | ||
using Shouldly; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System; | ||
|
||
namespace Google.Authenticator.Tests | ||
{ | ||
public class IntervalTests | ||
{ | ||
const string secret = "ggggjhG&^*&^jfSSSddd"; | ||
|
||
[Theory] | ||
[MemberData(nameof(GetTestValues))] | ||
public void GetCurrentPinsHandlesDifferentIntervals(int timeTolerance, int timeStep, int expectedCount) | ||
{ | ||
var subject = new TwoFactorAuthenticator(timeStep); | ||
|
||
subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(timeTolerance)).Length.ShouldBe(expectedCount); | ||
} | ||
|
||
public static IEnumerable<object[]> GetTestValues() | ||
{ | ||
yield return new object[] { 15, 30, 1 }; | ||
yield return new object[] { 30, 30, 3 }; | ||
yield return new object[] { 60, 30, 5 }; | ||
|
||
yield return new object[] { 15, 15, 3 }; | ||
yield return new object[] { 30, 15, 5 }; | ||
yield return new object[] { 60, 15, 9 }; | ||
|
||
yield return new object[] { 15, 60, 1 }; | ||
yield return new object[] { 30, 60, 1 }; | ||
yield return new object[] { 60, 60, 3 }; | ||
yield return new object[] { 300, 60, 11 }; | ||
} | ||
} | ||
} |
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 @@ | ||
using Xunit; | ||
using Shouldly; | ||
using System; | ||
|
||
namespace Google.Authenticator.Tests | ||
{ | ||
public class TimeStepTests | ||
{ | ||
[Fact] | ||
public void DefaultPINHasNotBeenChangedByAddingTimeStepConfig() | ||
{ | ||
var now = new DateTime(2024,1,2,3,4,5,DateTimeKind.Utc); | ||
var secret = "12314241234342342"; | ||
var defaultPin = new TwoFactorAuthenticator().GetCurrentPIN(secret, now); | ||
|
||
defaultPin.ShouldBe("668182"); // This pin was created with the code from before the timestep config was added | ||
} | ||
|
||
[Fact] | ||
public void DifferentTimeStepsReturnsDifferentPINs() | ||
{ | ||
var now = new DateTime(2024,1,2,3,4,5,DateTimeKind.Utc); | ||
var secret = "12314241234342342"; | ||
var defaultPin = new TwoFactorAuthenticator().GetCurrentPIN(secret, now); | ||
var pinWith15SecondTimeStep = new TwoFactorAuthenticator(15).GetCurrentPIN(secret, now); | ||
var pinWith60SecondTimeStep = new TwoFactorAuthenticator(60).GetCurrentPIN(secret, now); | ||
|
||
defaultPin.ShouldNotBe(pinWith15SecondTimeStep); | ||
defaultPin.ShouldNotBe(pinWith60SecondTimeStep); | ||
pinWith15SecondTimeStep.ShouldNotBe(pinWith60SecondTimeStep); | ||
} | ||
|
||
[Fact] | ||
public void DefaultTimeStepGivesSamePinAs30() | ||
{ | ||
var now = new DateTime(2024,1,2,3,4,5,DateTimeKind.Utc); | ||
var secret = "12314241234342342"; | ||
var defaultPin = new TwoFactorAuthenticator().GetCurrentPIN(secret, now); | ||
var pinWith30SecondTimeStep = new TwoFactorAuthenticator(30).GetCurrentPIN(secret, now); | ||
|
||
defaultPin.ShouldBe(pinWith30SecondTimeStep); | ||
|
||
} | ||
} | ||
} |
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
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