summaryrefslogtreecommitdiffstats
path: root/TwoStepsAuthenticator.UnitTests
diff options
context:
space:
mode:
Diffstat (limited to 'TwoStepsAuthenticator.UnitTests')
-rw-r--r--TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs42
-rw-r--r--TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs (renamed from TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs)6
-rw-r--r--TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj4
-rw-r--r--TwoStepsAuthenticator.UnitTests/UsedCodesManagerTests.cs23
4 files changed, 71 insertions, 4 deletions
diff --git a/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
new file mode 100644
index 0000000..ebe7493
--- /dev/null
+++ b/TwoStepsAuthenticator.UnitTests/CounterAuthenticatorTests.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace TwoStepsAuthenticator.UnitTests {
+
+ [TestFixture]
+ public class CounterAuthenticatorTests {
+
+ [Test]
+ public void CreateKey() {
+ var authenticator = new CounterAuthenticator();
+ var secret = authenticator.GenerateKey();
+ var code = authenticator.GetCode(secret, 0L);
+
+ Assert.IsTrue(authenticator.CheckCode(secret, code, 0L), "Generated Code doesn't verify");
+ }
+
+ // Test Values from http://www.ietf.org/rfc/rfc4226.txt - Appendix D
+ [TestCase("12345678901234567890", 0L, "755224")]
+ [TestCase("12345678901234567890", 1L, "287082")]
+ [TestCase("12345678901234567890", 2L, "359152")]
+ [TestCase("12345678901234567890", 3L, "969429")]
+ [TestCase("12345678901234567890", 4L, "338314")]
+ [TestCase("12345678901234567890", 5L, "254676")]
+ [TestCase("12345678901234567890", 6L, "287922")]
+ [TestCase("12345678901234567890", 7L, "162583")]
+ [TestCase("12345678901234567890", 8L, "399871")]
+ [TestCase("12345678901234567890", 9L, "520489")]
+ public void VerifyKeys(string secret, long counter, string code) {
+ var authenticator = new CounterAuthenticator();
+ var base32Secret = Base32Encoding.ToString(Encoding.ASCII.GetBytes(secret));
+
+ Assert.IsTrue(authenticator.CheckCode(base32Secret, code, counter));
+
+ }
+
+ }
+}
diff --git a/TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs
index 5c250b8..1f8c9ab 100644
--- a/TwoStepsAuthenticator.UnitTests/AuthenticatorTests.cs
+++ b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs
@@ -7,11 +7,11 @@ using NUnit.Framework;
namespace TwoStepsAuthenticator.UnitTests {
[TestFixture]
- public class AuthenticatorTests {
+ public class TimeAuthenticatorTests {
[Test]
public void CreateKey() {
- var authenticator = new Authenticator();
+ var authenticator = new TimeAuthenticator();
var secret = authenticator.GenerateKey();
var code = authenticator.GetCode(secret);
@@ -26,7 +26,7 @@ namespace TwoStepsAuthenticator.UnitTests {
public void VerifyKeys(string secret, string timeString, string code) {
var date = DateTime.Parse(timeString);
- var authenticator = new Authenticator(() => date);
+ var authenticator = new TimeAuthenticator(() => date);
Assert.IsTrue(authenticator.CheckCode(secret, code));
}
diff --git a/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj
index 54dae80..aa38917 100644
--- a/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj
+++ b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj
@@ -50,8 +50,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="AuthenticatorTests.cs" />
+ <Compile Include="CounterAuthenticatorTests.cs" />
+ <Compile Include="TimeAuthenticatorTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UsedCodesManagerTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/TwoStepsAuthenticator.UnitTests/UsedCodesManagerTests.cs b/TwoStepsAuthenticator.UnitTests/UsedCodesManagerTests.cs
new file mode 100644
index 0000000..7099c89
--- /dev/null
+++ b/TwoStepsAuthenticator.UnitTests/UsedCodesManagerTests.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace TwoStepsAuthenticator.UnitTests {
+
+ [TestFixture]
+ public class UsedCodesManagerTests {
+
+ [Test]
+ public void Can_add_codes() {
+ var manager = new UsedCodesManager();
+
+ Assert.IsFalse(manager.IsCodeUsed("abc", "def"));
+ manager.AddCode("abc", "def");
+ Assert.IsTrue(manager.IsCodeUsed("abc", "def"));
+ }
+
+ }
+}