diff options
author | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-05 11:19:11 +0100 |
---|---|---|
committer | Christoph Enzmann <christoph.enzmann@confer.ch> | 2013-12-05 11:19:11 +0100 |
commit | b52682a9b3216a7d966238e3c8ed6b4da3920313 (patch) | |
tree | 9cd5e32a7dd65b1297dfe9655173f3a0c512be05 /TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs | |
parent | 99c53801f3d4269b8058e87fa48b4bc37c7533fd (diff) | |
download | TwoStepsAuthenticator-b52682a9b3216a7d966238e3c8ed6b4da3920313.zip TwoStepsAuthenticator-b52682a9b3216a7d966238e3c8ed6b4da3920313.tar.gz TwoStepsAuthenticator-b52682a9b3216a7d966238e3c8ed6b4da3920313.tar.bz2 |
Counter based OTP added, removed UsedCodesManager from authenticator, UsedCodesManager refactoring
Diffstat (limited to 'TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs')
-rw-r--r-- | TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs new file mode 100644 index 0000000..1f8c9ab --- /dev/null +++ b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; + +namespace TwoStepsAuthenticator.UnitTests { + + [TestFixture] + public class TimeAuthenticatorTests { + + [Test] + public void CreateKey() { + var authenticator = new TimeAuthenticator(); + var secret = authenticator.GenerateKey(); + var code = authenticator.GetCode(secret); + + Assert.IsTrue(authenticator.CheckCode(secret, code), "Generated Code doesn't verify"); + } + + // 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")] + [TestCase("EQOGSM3XZUH6SE2Y", "2013-12-04 18:34:56 +0100", "256804")] + [TestCase("4VU7EQACVDMFJSBG", "2013-12-04 18:36:16 +0100", "800872")] + public void VerifyKeys(string secret, string timeString, string code) { + var date = DateTime.Parse(timeString); + + var authenticator = new TimeAuthenticator(() => date); + Assert.IsTrue(authenticator.CheckCode(secret, code)); + + } + } +} |