mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -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,71 +1,73 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Serialization;
|
||||
#else
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Serialization;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Serialization
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class HashedBlockStreamTests
|
||||
{
|
||||
static readonly byte[] data = new byte[16];
|
||||
|
||||
static readonly byte[] hashStreamData = new byte[] {
|
||||
// The first 4 bytes are an integer indicating the block index
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
// Then the SHA-256 hash of the data
|
||||
0x37, 0x47, 0x08, 0xFF, 0xF7, 0x71, 0x9D, 0xD5,
|
||||
0x97, 0x9E, 0xC8, 0x75, 0xD5, 0x6C, 0xD2, 0x28,
|
||||
0x6F, 0x6D, 0x3C, 0xF7, 0xEC, 0x31, 0x7A, 0x3B,
|
||||
0x25, 0x63, 0x2A, 0xAB, 0x28, 0xEC, 0x37, 0xBB,
|
||||
// then an integer that is the length of the data
|
||||
0x10, 0x00, 0x00, 0x00,
|
||||
// and finally the data itself
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// Next, a terminating block
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
// terminating block is indicated by a hash of all 0s...
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// ...and by a size of 0
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestRead ()
|
||||
[TestClass()]
|
||||
public class HashedBlockStreamTests
|
||||
{
|
||||
using (var ms = new MemoryStream (hashStreamData)) {
|
||||
using (var hbs = new HashedBlockStream (ms, false)) {
|
||||
using (var br = new BinaryReader(hbs)) {
|
||||
var bytes = br.ReadBytes (data.Length);
|
||||
Assert.That (bytes, Is.EqualTo (data));
|
||||
Assert.That (() => br.ReadByte (), Throws.InstanceOf<EndOfStreamException> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static readonly byte[] data = new byte[16];
|
||||
|
||||
[Test ()]
|
||||
public void TestWrite ()
|
||||
{
|
||||
var buffer = new byte[hashStreamData.Length];
|
||||
using (var ms = new MemoryStream (buffer)) {
|
||||
using (var hbs = new HashedBlockStream (ms, true)) {
|
||||
using (var bw = new BinaryWriter(hbs)) {
|
||||
bw.Write (data);
|
||||
}
|
||||
static readonly byte[] hashStreamData = new byte[]
|
||||
{
|
||||
// The first 4 bytes are an integer indicating the block index
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
// Then the SHA-256 hash of the data
|
||||
0x37, 0x47, 0x08, 0xFF, 0xF7, 0x71, 0x9D, 0xD5,
|
||||
0x97, 0x9E, 0xC8, 0x75, 0xD5, 0x6C, 0xD2, 0x28,
|
||||
0x6F, 0x6D, 0x3C, 0xF7, 0xEC, 0x31, 0x7A, 0x3B,
|
||||
0x25, 0x63, 0x2A, 0xAB, 0x28, 0xEC, 0x37, 0xBB,
|
||||
// then an integer that is the length of the data
|
||||
0x10, 0x00, 0x00, 0x00,
|
||||
// and finally the data itself
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// Next, a terminating block
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
// terminating block is indicated by a hash of all 0s...
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// ...and by a size of 0
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void TestRead()
|
||||
{
|
||||
using (var ms = new MemoryStream(hashStreamData))
|
||||
{
|
||||
using (var hbs = new HashedBlockStream(ms, false))
|
||||
{
|
||||
using (var br = new BinaryReader(hbs))
|
||||
{
|
||||
var bytes = br.ReadBytes(data.Length);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(bytes, data));
|
||||
Assert.ThrowsException<EndOfStreamException>(() => br.ReadByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestWrite()
|
||||
{
|
||||
var buffer = new byte[hashStreamData.Length];
|
||||
using (var ms = new MemoryStream(buffer))
|
||||
{
|
||||
using (var hbs = new HashedBlockStream(ms, true))
|
||||
{
|
||||
using (var bw = new BinaryWriter(hbs))
|
||||
{
|
||||
bw.Write(data);
|
||||
}
|
||||
}
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(buffer, hashStreamData));
|
||||
}
|
||||
}
|
||||
Assert.That (buffer, Is.EqualTo (hashStreamData));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Serialization;
|
||||
@@ -10,7 +10,7 @@ using ModernKeePassLib.Collections;
|
||||
|
||||
namespace ModernKeePassLib.Test.Serialization
|
||||
{
|
||||
[TestFixture()]
|
||||
[TestClass()]
|
||||
public class KdbxFileTests
|
||||
{
|
||||
const string TestLocalizedAppName = "My Localized App Name";
|
||||
@@ -86,7 +86,7 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
|
||||
const string TestDate = "2017-10-23T08:03:55Z";
|
||||
|
||||
[Test()]
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var database = new PwDatabase();
|
||||
@@ -96,12 +96,12 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
file.Load(ms, KdbxFormat.PlainXml, null);
|
||||
}
|
||||
//Assert.That(database.Color.ToArgb(), Is.EqualTo(Color.Red.ToArgb()));
|
||||
Assert.That(database.Compression, Is.EqualTo(PwCompressionAlgorithm.GZip));
|
||||
Assert.AreEqual(database.Compression, PwCompressionAlgorithm.GZip);
|
||||
//Assert.That (database.CustomData, Is.EqualTo ());
|
||||
Assert.That(database.CustomIcons, Is.Empty);
|
||||
Assert.IsTrue(database.CustomIcons.Count == 0);
|
||||
}
|
||||
|
||||
[Test()]
|
||||
[TestMethod]
|
||||
public void TestSave()
|
||||
{
|
||||
var buffer = new byte[4096];
|
||||
@@ -134,18 +134,17 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
var file = new KdbxFile(database);
|
||||
file.Save(ms, null, KdbxFormat.PlainXml, null);
|
||||
}
|
||||
var fileContents = Encoding.UTF8.GetString(buffer).Replace("\0", "");
|
||||
if (typeof(KdbxFile).Namespace.StartsWith("KeePassLib.")
|
||||
&& Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
var fileContents = Encoding.UTF8.GetString(buffer, 0, buffer.Length).Replace("\0", "");
|
||||
if (typeof(KdbxFile).Namespace.StartsWith("KeePassLib."))
|
||||
{
|
||||
// Upstream KeePassLib does not specify line endings for XmlTextWriter,
|
||||
// so it uses native line endings.
|
||||
fileContents = fileContents.Replace("\n", "\r\n");
|
||||
}
|
||||
Assert.That(fileContents, Is.EqualTo(TestDatabase));
|
||||
Assert.AreEqual(fileContents, TestDatabase);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestSearch()
|
||||
{
|
||||
var database = new PwDatabase();
|
||||
|
Reference in New Issue
Block a user