summaryrefslogtreecommitdiffstats
path: root/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
diff options
context:
space:
mode:
authorChristoph Enzmann <christoph.enzmann@confer.ch>2013-12-06 15:20:07 +0100
committerChristoph Enzmann <christoph.enzmann@confer.ch>2013-12-06 15:20:07 +0100
commit41cb13ee263104981850a73d4abf4a583df31941 (patch)
tree46b14ab6b93d813e9f40aae760f4b3902e380800 /TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
parentff91ec6adbf7f1c816b645844e7f83f4be74e548 (diff)
downloadTwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.zip
TwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.tar.gz
TwoStepsAuthenticator-41cb13ee263104981850a73d4abf4a583df31941.tar.bz2
Use one global default UsedCodesManager
Diffstat (limited to 'TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs')
-rw-r--r--TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs23
1 files changed, 20 insertions, 3 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
index f834178..3a81a90 100644
--- a/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
+++ b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
@@ -9,10 +9,27 @@ namespace TwoStepsAuthenticator.UnitTests {
[TestFixture]
public class CounterAuthenticatorTests {
+ private MockUsedCodesManager mockUsedCodesManager { get; set; }
+
+ [SetUp]
+ public void SetUp() {
+ this.mockUsedCodesManager = new MockUsedCodesManager();
+ }
+
+ [Test]
+ public void Uses_usedCodesManager() {
+ var authenticator = new CounterAuthenticator(usedCodeManager: mockUsedCodesManager);
+ var secret = Authenticator.GenerateKey();
+ var code = authenticator.GetCode(secret, 42uL);
+
+ authenticator.CheckCode(secret, code, 42uL);
+ Assert.AreEqual(mockUsedCodesManager.LastChallenge, 42uL);
+ Assert.AreEqual(mockUsedCodesManager.LastCode, code);
+ }
[Test]
public void CreateKey() {
- var authenticator = new CounterAuthenticator();
+ var authenticator = new CounterAuthenticator(usedCodeManager: mockUsedCodesManager);
var secret = Authenticator.GenerateKey();
var code = authenticator.GetCode(secret, 0uL);
@@ -31,7 +48,7 @@ namespace TwoStepsAuthenticator.UnitTests {
[TestCase("12345678901234567890", 8uL, "399871")]
[TestCase("12345678901234567890", 9uL, "520489")]
public void VerifyKeys(string secret, ulong counter, string code) {
- var authenticator = new CounterAuthenticator();
+ var authenticator = new CounterAuthenticator(usedCodeManager: mockUsedCodesManager);
var base32Secret = Base32Encoding.ToString(Encoding.ASCII.GetBytes(secret));
Assert.IsTrue(authenticator.CheckCode(base32Secret, code, counter));
@@ -40,7 +57,7 @@ namespace TwoStepsAuthenticator.UnitTests {
[Test]
public void VerifyUsedCounter() {
- var authenticator = new CounterAuthenticator();
+ var authenticator = new CounterAuthenticator(usedCodeManager: mockUsedCodesManager);
// Test Values from http://www.ietf.org/rfc/rfc4226.txt - Appendix D
var base32Secret = Base32Encoding.ToString(Encoding.ASCII.GetBytes("12345678901234567890"));