diff options
author | Guillaume Lacasa <guillaumelacasa@hotmail.com> | 2015-06-29 15:57:03 +0200 |
---|---|---|
committer | Guillaume Lacasa <guillaumelacasa@hotmail.com> | 2015-06-29 15:57:03 +0200 |
commit | bea18ecded08a62e3532edad59483061f3eaf375 (patch) | |
tree | 983015d02b8d1bf4d9b83e92b1c7d508a4068f60 | |
parent | 3989c468e618330f5b5d1c67e5eaf2e0fa7c4c34 (diff) | |
download | TwoStepsAuthenticator-bea18ecded08a62e3532edad59483061f3eaf375.zip TwoStepsAuthenticator-bea18ecded08a62e3532edad59483061f3eaf375.tar.gz TwoStepsAuthenticator-bea18ecded08a62e3532edad59483061f3eaf375.tar.bz2 |
CheckCode method made obsolete if no user is passed
Unit tests updated
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs | 16 | ||||
-rw-r--r-- | TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj | 30 | ||||
-rw-r--r-- | TwoStepsAuthenticator.UnitTests/packages.config | 3 | ||||
-rw-r--r-- | TwoStepsAuthenticator/TimeAuthenticator.cs | 1 |
5 files changed, 38 insertions, 13 deletions
@@ -152,3 +152,4 @@ $RECYCLE.BIN/ # Mac desktop service store files .DS_Store +packages/ diff --git a/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs index 0c385fa..4f1b4af 100644 --- a/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs +++ b/TwoStepsAuthenticator.UnitTests/TimeAuthenticatorTests.cs @@ -25,25 +25,25 @@ namespace TwoStepsAuthenticator.UnitTests var secret = Authenticator.GenerateKey(); var code = authenticator.GetCode(secret); - Assert.IsTrue(authenticator.CheckCode(secret, code), "Generated Code doesn't verify"); + Assert.IsTrue(authenticator.CheckCode(secret, code, "dummyuser"), "Generated Code doesn't verify"); } [Test] - public void Uses_usedCodesManager() + public void UsesUsedCodesManager() { var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date); var secret = Authenticator.GenerateKey(); var code = authenticator.GetCode(secret); - authenticator.CheckCode(secret, code); + authenticator.CheckCode(secret, code, "dummyuser"); Assert.AreEqual(mockUsedCodesManager.LastChallenge, 0uL); Assert.AreEqual(mockUsedCodesManager.LastCode, code); } [Test] - public void Prevent_code_reuse() { + public void PreventCodeReuse() { var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var usedCodesManager = new UsedCodesManager(); var authenticator = new TimeAuthenticator(usedCodesManager, () => date); @@ -51,6 +51,7 @@ namespace TwoStepsAuthenticator.UnitTests var code = authenticator.GetCode(secret); Assert.IsTrue(authenticator.CheckCode(secret, code, "dummyuser")); + Assert.IsTrue(authenticator.CheckCode(secret, code, "otheruser")); Assert.IsFalse(authenticator.CheckCode(secret, code, "dummyuser")); } @@ -79,9 +80,10 @@ namespace TwoStepsAuthenticator.UnitTests Assert.True(authenticator.CheckCode("H22Q7WAMQYFZOJ2Q", "696227", null, out usedTime)); // 17:23:50 - 30s - Assert.AreEqual(usedTime.Hour, date.Hour); - Assert.AreEqual(usedTime.Minute, 23); - Assert.AreEqual(usedTime.Second, 20); + var sameDate = date.AddSeconds(-30); + Assert.AreEqual(usedTime.Hour, sameDate.Hour); + Assert.AreEqual(usedTime.Minute, sameDate.Minute); + Assert.AreEqual(usedTime.Second, sameDate.Second); } } } diff --git a/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj index 38fce5d..0eb5b1d 100644 --- a/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj +++ b/TwoStepsAuthenticator.UnitTests/TwoStepsAuthenticator.UnitTests.csproj @@ -38,8 +38,25 @@ <StartupObject /> </PropertyGroup> <ItemGroup> - <Reference Include="nunit.framework"> - <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath> + <Reference Include="nunit.core"> + <HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="nunit.core.interfaces"> + <HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="nunit.util"> + <HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="NUnit.VisualStudio.TestAdapter"> + <HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath> + <Private>False</Private> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> @@ -57,14 +74,17 @@ <Compile Include="UsedCodesManagerTests.cs" /> </ItemGroup> <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> <ProjectReference Include="..\TwoStepsAuthenticator\TwoStepsAuthenticator.csproj"> <Project>{6c898cd1-0bf3-4711-847e-ad7dac815cd8}</Project> <Name>TwoStepsAuthenticator</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. diff --git a/TwoStepsAuthenticator.UnitTests/packages.config b/TwoStepsAuthenticator.UnitTests/packages.config index 967502d..1f8800b 100644 --- a/TwoStepsAuthenticator.UnitTests/packages.config +++ b/TwoStepsAuthenticator.UnitTests/packages.config @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="NUnit" version="2.6.3" targetFramework="net40" /> + <package id="NUnit" version="2.6.4" targetFramework="net45" /> + <package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/TwoStepsAuthenticator/TimeAuthenticator.cs b/TwoStepsAuthenticator/TimeAuthenticator.cs index 24441fe..7272b77 100644 --- a/TwoStepsAuthenticator/TimeAuthenticator.cs +++ b/TwoStepsAuthenticator/TimeAuthenticator.cs @@ -100,6 +100,7 @@ namespace TwoStepsAuthenticator /// <param name="secret">Shared Secret</param> /// <param name="code">OTP</param> /// <returns>true if code matches</returns> + [Obsolete("The CheckCode method should only be used with a user object")] public bool CheckCode(string secret, string code) { DateTime successfulTime = DateTime.MinValue; |