mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
Changed test project type to WIndows 8.1
Changed test project framework from Nunit to MSTest Changed HashAlgorithm from BouncyCastle to WinRT crypto WIP progress bar in opendatabaseusercontrol TextBox with button made generic WIP implement copy on button click in Entry Page
This commit is contained in:
@@ -1,33 +1,35 @@
|
||||
using NUnit.Framework;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class CompositeKeyTests
|
||||
{
|
||||
[Test]
|
||||
public void TestGenerateKey32 ()
|
||||
[TestClass()]
|
||||
public class CompositeKeyTests
|
||||
{
|
||||
var originalKey = new byte[32];
|
||||
var expectedKey = new byte[32] {
|
||||
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
||||
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
||||
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
||||
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
||||
};
|
||||
const ulong rounds = 1;
|
||||
[TestMethod]
|
||||
public void TestGenerateKey32()
|
||||
{
|
||||
var originalKey = new byte[32];
|
||||
var expectedKey = new byte[32]
|
||||
{
|
||||
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
||||
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
||||
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
||||
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
||||
};
|
||||
const ulong rounds = 1;
|
||||
|
||||
var composite = new CompositeKey ();
|
||||
AesKdf kdf = new AesKdf();
|
||||
KdfParameters p = kdf.GetDefaultParameters();
|
||||
p.SetUInt64(AesKdf.ParamRounds, rounds);
|
||||
p.SetByteArray(AesKdf.ParamSeed, originalKey);
|
||||
var key = composite.GenerateKey32(p);
|
||||
Assert.That (key, Is.Not.Null);
|
||||
var keyData = key.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedKey));
|
||||
var composite = new CompositeKey();
|
||||
AesKdf kdf = new AesKdf();
|
||||
KdfParameters p = kdf.GetDefaultParameters();
|
||||
p.SetUInt64(AesKdf.ParamRounds, rounds);
|
||||
p.SetByteArray(AesKdf.ParamSeed, originalKey);
|
||||
var key = composite.GenerateKey32(p);
|
||||
Assert.IsNotNull(key);
|
||||
var keyData = key.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,35 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpCustomKeyTests
|
||||
{
|
||||
static readonly byte[] testData = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass()]
|
||||
public class KcpCustomKeyTests
|
||||
{
|
||||
var expectedHash = new byte[32] {
|
||||
0xAF, 0x55, 0x70, 0xF5, 0xA1, 0x81, 0x0B, 0x7A,
|
||||
0xF7, 0x8C, 0xAF, 0x4B, 0xC7, 0x0A, 0x66, 0x0F,
|
||||
0x0D, 0xF5, 0x1E, 0x42, 0xBA, 0xF9, 0x1D, 0x4D,
|
||||
0xE5, 0xB2, 0x32, 0x8D, 0xE0, 0xE8, 0x3D, 0xFC
|
||||
};
|
||||
static readonly byte[] testData =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
var key = new KcpCustomKey ("test1", testData, false);
|
||||
var keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (testData));
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedHash = new byte[32]
|
||||
{
|
||||
0xAF, 0x55, 0x70, 0xF5, 0xA1, 0x81, 0x0B, 0x7A,
|
||||
0xF7, 0x8C, 0xAF, 0x4B, 0xC7, 0x0A, 0x66, 0x0F,
|
||||
0x0D, 0xF5, 0x1E, 0x42, 0xBA, 0xF9, 0x1D, 0x4D,
|
||||
0xE5, 0xB2, 0x32, 0x8D, 0xE0, 0xE8, 0x3D, 0xFC
|
||||
};
|
||||
|
||||
key = new KcpCustomKey ("test2", testData, true);
|
||||
keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedHash));
|
||||
var key = new KcpCustomKey("test1", testData, false);
|
||||
var keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, testData));
|
||||
|
||||
key = new KcpCustomKey("test2", testData, true);
|
||||
keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedHash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,76 +1,84 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Windows.Storage;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpKeyFileTests
|
||||
{
|
||||
const string testCreateFile = "TestCreate.xml";
|
||||
const string testKey = "0123456789";
|
||||
|
||||
const string expectedFileStart =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
|
||||
"<KeyFile>\r\n" +
|
||||
"\t<Meta>\r\n" +
|
||||
"\t\t<Version>1.00</Version>\r\n" +
|
||||
"\t</Meta>\r\n" +
|
||||
"\t<Key>\r\n" +
|
||||
"\t\t<Data>";
|
||||
|
||||
const string expectedFileEnd = "\t</Key>\r\n" +
|
||||
"</KeyFile>\r\n";
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass]
|
||||
public class KcpKeyFileTests
|
||||
{
|
||||
var expectedKeyData = new byte[32] {
|
||||
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
|
||||
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
|
||||
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
|
||||
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
|
||||
};
|
||||
private const string TestCreateFile = "TestCreate.xml";
|
||||
private const string TestKey = "0123456789";
|
||||
|
||||
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
|
||||
using (var fs = new FileStream(fullPath, FileMode.Create)) {
|
||||
using (var sw = new StreamWriter(fs)) {
|
||||
sw.Write (expectedFileStart);
|
||||
sw.Write (testKey);
|
||||
sw.Write (expectedFileEnd);
|
||||
private const string ExpectedFileStart =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
|
||||
"<KeyFile>\r\n" +
|
||||
"\t<Meta>\r\n" +
|
||||
"\t\t<Version>1.00</Version>\r\n" +
|
||||
"\t</Meta>\r\n" +
|
||||
"\t<Key>\r\n" +
|
||||
"\t\t<Data>";
|
||||
|
||||
private const string ExpectedFileEnd = "\t</Key>\r\n" +
|
||||
"</KeyFile>\r\n";
|
||||
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedKeyData = new byte[32]
|
||||
{
|
||||
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
|
||||
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
|
||||
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
|
||||
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
|
||||
};
|
||||
|
||||
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
|
||||
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
|
||||
using (var fs = file.OpenStreamForWriteAsync().GetAwaiter().GetResult())
|
||||
{
|
||||
using (var sw = new StreamWriter(fs))
|
||||
{
|
||||
sw.Write(ExpectedFileStart);
|
||||
sw.Write(TestKey);
|
||||
sw.Write(ExpectedFileEnd);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var keyFile = new KcpKeyFile(fullPath);
|
||||
var keyData = keyFile.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedKeyData));
|
||||
}
|
||||
finally
|
||||
{
|
||||
file.DeleteAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var keyFile = new KcpKeyFile (fullPath);
|
||||
var keyData = keyFile.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedKeyData));
|
||||
} finally {
|
||||
File.Delete (fullPath);
|
||||
}
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestCreate()
|
||||
{
|
||||
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
|
||||
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
|
||||
KcpKeyFile.Create(fullPath, null);
|
||||
try
|
||||
{
|
||||
var fileContents = FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
|
||||
|
||||
[Test ()]
|
||||
public void TestCreate ()
|
||||
{
|
||||
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
|
||||
File.Create(fullPath).Close();
|
||||
KcpKeyFile.Create (fullPath, null);
|
||||
try {
|
||||
var fileContents = File.ReadAllText (fullPath);
|
||||
Assert.That (fileContents.Length, Is.EqualTo (187));
|
||||
Assert.That (fileContents, Does.StartWith (expectedFileStart));
|
||||
Assert.That (fileContents, Does.EndWith (expectedFileEnd));
|
||||
} finally {
|
||||
File.Delete (fullPath);
|
||||
}
|
||||
Assert.AreEqual(fileContents.Length, 187);
|
||||
Assert.IsTrue(fileContents.StartsWith(ExpectedFileStart));
|
||||
Assert.IsTrue(fileContents.EndsWith(ExpectedFileEnd));
|
||||
}
|
||||
finally
|
||||
{
|
||||
file.DeleteAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,33 +1,29 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpPasswordTests
|
||||
{
|
||||
const string testPassword = "password";
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass()]
|
||||
public class KcpPasswordTests
|
||||
{
|
||||
var expectedHash = new byte[32] {
|
||||
0x5E, 0x88, 0x48, 0x98, 0xDA, 0x28, 0x04, 0x71,
|
||||
0x51, 0xD0, 0xE5, 0x6F, 0x8D, 0xC6, 0x29, 0x27,
|
||||
0x73, 0x60, 0x3D, 0x0D, 0x6A, 0xAB, 0xBD, 0xD6,
|
||||
0x2A, 0x11, 0xEF, 0x72, 0x1D, 0x15, 0x42, 0xD8
|
||||
};
|
||||
const string testPassword = "password";
|
||||
|
||||
var key = new KcpPassword (testPassword);
|
||||
var keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedHash));
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedHash = new byte[32]
|
||||
{
|
||||
0x5E, 0x88, 0x48, 0x98, 0xDA, 0x28, 0x04, 0x71,
|
||||
0x51, 0xD0, 0xE5, 0x6F, 0x8D, 0xC6, 0x29, 0x27,
|
||||
0x73, 0x60, 0x3D, 0x0D, 0x6A, 0xAB, 0xBD, 0xD6,
|
||||
0x2A, 0x11, 0xEF, 0x72, 0x1D, 0x15, 0x42, 0xD8
|
||||
};
|
||||
|
||||
var key = new KcpPassword(testPassword);
|
||||
var keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedHash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user