diff options
author | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-06 15:20:07 +0100 |
---|---|---|
committer | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-06 15:20:07 +0100 |
commit | 41cb13ee263104981850a73d4abf4a583df31941 (patch) | |
tree | 46b14ab6b93d813e9f40aae760f4b3902e380800 /TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs | |
parent | ff91ec6adbf7f1c816b645844e7f83f4be74e548 (diff) | |
download | TwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.zip TwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.tar.gz TwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.tar.bz2 |
Use one global default UsedCodesManager
Diffstat (limited to 'TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs')
-rw-r--r-- | TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs index 3dc6d86..1a1ffc6 100644 --- a/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs +++ b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs @@ -8,16 +8,34 @@ namespace TwoStepsAuthenticator.UnitTests { [TestFixture] public class TimeAuthenticatorTests { + private MockUsedCodesManager mockUsedCodesManager { get; set; } + + [SetUp] + public void SetUp() { + this.mockUsedCodesManager = new MockUsedCodesManager(); + } [Test] public void CreateKey() { - var authenticator = new TimeAuthenticator(); + var authenticator = new TimeAuthenticator(usedCodeManager: mockUsedCodesManager); var secret = Authenticator.GenerateKey(); var code = authenticator.GetCode(secret); Assert.IsTrue(authenticator.CheckCode(secret, code), "Generated Code doesn't verify"); } + [Test] + public void Uses_usedCodesManager() { + var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + var authenticator = new TimeAuthenticator(() => date, usedCodeManager: mockUsedCodesManager); + var secret = Authenticator.GenerateKey(); + var code = authenticator.GetCode(secret); + + authenticator.CheckCode(secret, code); + Assert.AreEqual(mockUsedCodesManager.LastChallenge, 0uL); + Assert.AreEqual(mockUsedCodesManager.LastCode, code); + } + // Test Vectors from http://tools.ietf.org/html/rfc6238#appendix-B have all length 8. We want a length of 6. // This Test Vectors are from a Ruby implementation. They work with the Google Authentificator app. [TestCase("DRMK64PPMMC7TDZF", "2013-12-04 18:33:01 +0100", "661188")] @@ -26,7 +44,7 @@ namespace TwoStepsAuthenticator.UnitTests { public void VerifyKeys(string secret, string timeString, string code) { var date = DateTime.Parse(timeString); - var authenticator = new TimeAuthenticator(() => date); + var authenticator = new TimeAuthenticator(() => date, usedCodeManager: mockUsedCodesManager); Assert.IsTrue(authenticator.CheckCode(secret, code)); } @@ -34,7 +52,7 @@ namespace TwoStepsAuthenticator.UnitTests { [Test] public void VerifyUsedTime() { var date = DateTime.Parse("2013-12-05 17:23:50 +0100"); - var authenticator = new TimeAuthenticator(() => date); + var authenticator = new TimeAuthenticator(() => date, usedCodeManager: mockUsedCodesManager); DateTime usedTime; |