1
0
mirror of https://github.com/XFox111/SimpleOTP.git synced 2026-04-22 08:00:45 +03:00

Base32 encoder fix (#19)

- Fixed Base32 encoder #6, added test
- Updated NuGet packages
This commit is contained in:
2021-07-09 00:52:00 +03:00
committed by GitHub
parent a06022ba1e
commit 4c63be6389
6 changed files with 51 additions and 37 deletions
+22 -7
View File
@@ -6,6 +6,7 @@
// ------------------------------------------------------------
using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SimpleOTP.Helpers;
@@ -19,19 +20,33 @@ namespace SimpleOTP.Test.Helpers
public class Base32UnitTest
{
/// <summary>
/// Test overall work of the encoder.
/// Test encoder with byte array.
/// </summary>
[TestMethod("Overall Base32 encoder test")]
[TestMethod("Byte array Base32 encoder test")]
public void EncoderTest()
{
// byte[] bytes = new byte[new Random().Next(128, 161)]; // FIXME: See SimpleOTP.Helpers.Base32Encoder.Encode()
byte[] bytes = new byte[160];
byte[] bytes = new byte[new Random().Next(16, 20)];
new Random().NextBytes(bytes);
string str = Base32Encoder.Encode(bytes);
bytes = Base32Encoder.Decode(str);
string result = Base32Encoder.Encode(bytes);
Assert.AreEqual(str, result);
byte[] result = Base32Encoder.Decode(str);
Assert.AreEqual(bytes.Length, result.Length);
for (int i = 0; i < bytes.Length; i++)
Assert.AreEqual(bytes[i], result[i]);
}
/// <summary>
/// Test encoder with string content.
/// </summary>
[TestMethod("String Base32 encoder test")]
public void EncoderStringTest()
{
string testStr = "Hello, World!";
string encodedStr = Base32Encoder.Encode(Encoding.UTF8.GetBytes(testStr));
byte[] resultBytes = Base32Encoder.Decode(encodedStr);
string result = Encoding.UTF8.GetString(resultBytes);
Assert.AreEqual(testStr, result);
}
}
}
@@ -87,4 +87,4 @@ namespace SimpleOTP.Test.Models
"yEEBMhxEQIMRFCTIQQEyHERAgxEUJMhBATIcRECDERQkyEEBMhxEQIMRFCTIQQEyHE/gcIt5Gg5RNZHAAAAABJRU5ErkJggg==", imageStr);
}
}
}
}
+2 -2
View File
@@ -24,8 +24,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.4" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>