Added test for merge with kdbp file and fixed it in SaveDB
This commit is contained in:
@@ -11,7 +11,7 @@ using ProtoBuf.Meta;
|
|||||||
|
|
||||||
namespace KeePassLib.Serialization
|
namespace KeePassLib.Serialization
|
||||||
{
|
{
|
||||||
internal class KdbpFile
|
public class KdbpFile
|
||||||
{
|
{
|
||||||
public const string FileNameExtension = "kdbp";
|
public const string FileNameExtension = "kdbp";
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ namespace keepass2android
|
|||||||
pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
|
pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
|
||||||
pwImp.MasterKey = pwDatabase.MasterKey;
|
pwImp.MasterKey = pwDatabase.MasterKey;
|
||||||
KdbxFile kdbx = new KdbxFile(pwImp);
|
KdbxFile kdbx = new KdbxFile(pwImp);
|
||||||
kdbx.Load(fileStorage.OpenFileForRead(ioc), KdbxFormat.Default, null);
|
kdbx.Load(fileStorage.OpenFileForRead(ioc), KdbpFile.GetFormatToUse(ioc), null);
|
||||||
|
|
||||||
pwDatabase.MergeIn(pwImp, PwMergeMethod.Synchronize, null);
|
pwDatabase.MergeIn(pwImp, PwMergeMethod.Synchronize, null);
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ namespace Kp2aUnitTests
|
|||||||
{
|
{
|
||||||
TestRunner runner = new TestRunner();
|
TestRunner runner = new TestRunner();
|
||||||
// Run all tests from this assembly
|
// Run all tests from this assembly
|
||||||
runner.AddTests(Assembly.GetExecutingAssembly());
|
//runner.AddTests(Assembly.GetExecutingAssembly());
|
||||||
//runner.AddTests(new List<Type> { typeof(TestSaveDb)});
|
//runner.AddTests(new List<Type> { typeof(TestSaveDb)});
|
||||||
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSaveWithSyncConflict"));
|
runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSaveWithSyncKdbp"));
|
||||||
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSave"));
|
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadKdbxAndSaveKdbp_TestIdenticalFiles"));
|
||||||
return runner;
|
return runner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,17 @@ namespace Kp2aUnitTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected IKp2aApp SetupAppWithDefaultDatabase()
|
protected IKp2aApp SetupAppWithDefaultDatabase()
|
||||||
|
{
|
||||||
|
string filename = DefaultFilename;
|
||||||
|
|
||||||
|
return SetupAppWithDatabase(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IKp2aApp SetupAppWithDatabase(string filename)
|
||||||
{
|
{
|
||||||
IKp2aApp app = new TestKp2aApp();
|
IKp2aApp app = new TestKp2aApp();
|
||||||
IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};
|
|
||||||
|
IOConnectionInfo ioc = new IOConnectionInfo {Path = filename};
|
||||||
Database db = app.CreateNewDatabase();
|
Database db = app.CreateNewDatabase();
|
||||||
|
|
||||||
db.KpDatabase = new PwDatabase();
|
db.KpDatabase = new PwDatabase();
|
||||||
|
|||||||
@@ -44,13 +44,25 @@ namespace Kp2aUnitTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestLoadEditSaveWithSync()
|
public void TestLoadEditSaveWithSync()
|
||||||
{
|
{
|
||||||
|
TestSync(DefaultFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestLoadEditSaveWithSyncKdbp()
|
||||||
|
{
|
||||||
|
TestSync(DefaultDirectory+"savetest.kdbp");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void TestSync(string filename)
|
||||||
|
{
|
||||||
//create the default database:
|
//create the default database:
|
||||||
IKp2aApp app = SetupAppWithDefaultDatabase();
|
IKp2aApp app = SetupAppWithDatabase(filename);
|
||||||
//save it and reload it so we have a base version
|
//save it and reload it so we have a base version
|
||||||
SaveDatabase(app);
|
SaveDatabase(app);
|
||||||
app = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
app = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||||
//load it once again:
|
//load it once again:
|
||||||
IKp2aApp app2 = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
IKp2aApp app2 = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||||
|
|
||||||
//modify the database by adding a group in both databases:
|
//modify the database by adding a group in both databases:
|
||||||
app.GetDb().KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "TestGroup", PwIcon.Apple), true);
|
app.GetDb().KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "TestGroup", PwIcon.Apple), true);
|
||||||
@@ -71,11 +83,10 @@ namespace Kp2aUnitTests
|
|||||||
app.GetDb().KpDatabase.RootGroup.AddGroup(group2, true);
|
app.GetDb().KpDatabase.RootGroup.AddGroup(group2, true);
|
||||||
|
|
||||||
//load database to a new app instance:
|
//load database to a new app instance:
|
||||||
IKp2aApp resultApp = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
IKp2aApp resultApp = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||||
|
|
||||||
//ensure the sync was successful:
|
//ensure the sync was successful:
|
||||||
AssertDatabasesAreEqual(app.GetDb().KpDatabase, resultApp.GetDb().KpDatabase);
|
AssertDatabasesAreEqual(app.GetDb().KpDatabase, resultApp.GetDb().KpDatabase);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user