public void ShouldExportAfterChangedContent() { PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0); //the first autoExport only checks if there is a delta container allready and if not it will export one //in our case there should be no existing container so a new one will be created. string exportPath = GetTestPath(); PwGroup exportGroup = new PwGroup(true, true, exportPath, PwIcon.Apple); m_database.GetExportGroup().AddGroup(exportGroup, true); exportGroup.AddEntry(mrX.CreateProxyNode(), true); string exportFile = exportPath + SyncSource.FileNameFor(mrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.RefeshSourcesList(); m_syncManager.Export(); mrX = TestHelper.GetUserRootNodeFor(m_database, 0); Assert.AreEqual("mrX", mrX.GetTitle()); Assert.IsTrue(File.Exists(exportFile)); //now we will change a password that is shared to mrX and then trigger the AutoExport method //like it will happen on any OnChangeEvent. After that again we validate the data in the export container. PwEntry entry1 = m_database.RootGroup.FindEntry(Uuid1, true); entry1.SetTitle("new title"); //due to the fact that the UnitTest is way faster than userIneraction we have to manipulate the lastModTimestamp //because if we don't do that the um.Update() method will maybe use another value to update all references and //then we will have the old title in the stringField TestHelper.SimulateTouch(entry1); //now we run the update methods that will be triggered on every UiChangeEvent m_treeManager.CorrectStructure(); m_syncManager.RefeshSourcesList(); //the autoexport method was triggered by in import or OnSaveEvent only so we have to trigger it manually here m_syncManager.Export(); PwDatabase deltaDB = new PwDatabase(); Assert.DoesNotThrow(delegate { deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); }); //as before we want to have the same content except that entry1 should now have a new title! Assert.AreEqual(5, deltaDB.RootGroup.GetEntries(true).UCount); Assert.AreEqual(3, deltaDB.RootGroup.Entries.UCount); Assert.AreEqual("grp1", deltaDB.RootGroup.Groups.GetAt(0).Name); Assert.AreEqual(2, deltaDB.RootGroup.Groups.GetAt(0).Entries.UCount); //now we will test in detail if there are only the expected entries in the created delta container Assert.AreEqual(Uuid1, deltaDB.RootGroup.Entries.GetAt(0).Uuid); Assert.AreEqual(Uuid3, deltaDB.RootGroup.Entries.GetAt(2).Uuid); Assert.AreEqual(Uuid6, deltaDB.RootGroup.Entries.GetAt(1).Uuid); Assert.AreEqual(Uuid4, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(0).Uuid); Assert.AreEqual(Uuid5, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(1).Uuid); Assert.AreEqual("new title", deltaDB.RootGroup.Entries.GetAt(0).GetTitle()); deltaDB.Close(); }
public void ShouldExportImportedNodes() { var importDatabase = TestHelper.CreateDatabase(); var importedEntry = new PwEntry(true, true); importedEntry.SetTitle("ImportedEntry"); var importedGroup = new PwGroup(true, true); importedGroup.Name = "ImportedGroup"; importedGroup.AddEntry(importedEntry, true); importDatabase.RootGroup.AddGroup(importedGroup, true); var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(userMrX.CreateProxyNode(), true); m_database.RootGroup.AddEntry(userMrX.CreateProxyNode(), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("ExistingEntry"); m_database.RootGroup.AddEntry(existingEntry, true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(0, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); m_syncManager.Export(); Assert.IsTrue(File.Exists(exportFile)); var importer = new SyncImporterAccessor(); importer.MergeInAccessor(m_database, importDatabase); Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(1, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); m_syncManager.Export(); Assert.IsTrue(File.Exists(exportFile)); var deltaDBUpdated = new PwDatabase(); deltaDBUpdated.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); deltaDBUpdated.Close(); }
public void ShouldNotImportDatabasesWithDifferentUsers() { var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); var userMrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(userMrY.CreateProxyNode(), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("Entry Version 1"); m_database.RootGroup.AddEntry(existingEntry, true); m_database.RootGroup.AddEntry(userMrY.CreateProxyNode(), true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrY) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.Export(); existingEntry.SetTitle("Entry Version 2"); var deltaDBInitial = new PwDatabase(); deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(0, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2")); Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); deltaDBInitial.Close(); m_syncManager.AddImportPath(exportFile); m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword("InvalidPassword"); m_syncManager.RefeshSourcesList(); Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2")); Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); }
public void ShouldHandleExportAndImportOfDifferentDatabasesSuccessfully() { var exportKeeShare = new KeeShare.KeeShare(); var exportDatabase = TestHelper.CreateDatabase(); exportKeeShare.Initialize(exportDatabase); var treeManagerAccessor = new TreeManagerAccessor(); treeManagerAccessor.Initialize(exportDatabase); treeManagerAccessor.CreateNewUser("MrX"); exportKeeShare.EnsureValidTree(exportDatabase); var userNode = TestHelper.GetUserRootNodeByNameFor(exportDatabase, "MrX"); var userHome = TestHelper.GetUserHomeNodeByNameFor(exportDatabase, "MrX"); var exportRootEntry = new PwEntry(true, true); exportRootEntry.SetTitle("ExportRootEntry"); exportDatabase.RootGroup.AddEntry(exportRootEntry, true); var exportPath = GetTestPath(); var exportFile = exportPath + SyncSource.FileNameFor(userNode) + SyncExporter.FileExtension; exportKeeShare.AddExportPath(exportPath); var exportTarget = exportDatabase.GetExportGroup().Groups.GetAt(0); exportTarget.AddEntry(userNode.CreateProxyNode(), true); var exportHomeEntry = new PwEntry(true, true); exportHomeEntry.SetTitle("ExportHomeEntry"); userHome.AddEntry(exportHomeEntry, true); exportDatabase.RootGroup.AddEntry(userNode.CreateProxyNode(), true); var importDatabase = TestHelper.CreateDatabase(); var importKeeShare = new KeeShare.KeeShare(); importKeeShare.Initialize(importDatabase); exportKeeShare.Export(); importKeeShare.AddImportPath(exportFile); var importGroup = importDatabase.GetImportGroup().Groups.GetAt(0); var importSource = importGroup.Entries.GetAt(0); importSource.SetPassword(userNode.Strings.ReadSafe(KeeShare.KeeShare.PasswordField)); importKeeShare.EnsureValidTree(importDatabase); Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportRootEntry")); Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportHomeEntry")); }
public void ShouldHandleExportAndImportOfDifferentDatabasesSuccessfully() { var exportKeeShare = new KeeShare.KeeShare(); var exportDatabase = TestHelper.CreateDatabase(); exportKeeShare.Initialize(exportDatabase); var treeManagerAccessor = new TreeManagerAccessor(); treeManagerAccessor.Initialize(exportDatabase); treeManagerAccessor.CreateNewUser("MrX"); exportKeeShare.EnsureValidTree(exportDatabase); var userNode = TestHelper.GetUserRootNodeByNameFor(exportDatabase, "MrX"); var userHome = TestHelper.GetUserHomeNodeByNameFor(exportDatabase, "MrX"); var exportRootEntry = new PwEntry(true, true); exportRootEntry.SetTitle("ExportRootEntry"); exportDatabase.RootGroup.AddEntry(exportRootEntry, true); var exportPath = GetTestPath(); var exportFile = exportPath + SyncSource.FileNameFor(userNode) + SyncExporter.FileExtension; exportKeeShare.AddExportPath(exportPath); var exportTarget = exportDatabase.GetExportGroup().Groups.GetAt(0); exportTarget.AddEntry(PwNode.CreateProxyNode(userNode), true); var exportHomeEntry = new PwEntry(true, true); exportHomeEntry.SetTitle("ExportHomeEntry"); userHome.AddEntry(exportHomeEntry, true); exportDatabase.RootGroup.AddEntry(PwNode.CreateProxyNode(userNode), true); var importDatabase = TestHelper.CreateDatabase(); var importKeeShare = new KeeShare.KeeShare(); importKeeShare.Initialize(importDatabase); exportKeeShare.Export(); importKeeShare.AddImportPath(exportFile); var importGroup = importDatabase.GetImportGroup().Groups.GetAt(0); var importSource = importGroup.Entries.GetAt(0); importSource.SetPassword(userNode.Strings.ReadSafe(KeeShare.KeeShare.PasswordField)); importKeeShare.EnsureValidTree(importDatabase); Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportRootEntry")); Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportHomeEntry")); }
public void ShouldHandleCyclesOfNodesInImportAndExport() { var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(userMrX.CreateProxyNode(), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("Entry Version 1"); m_database.RootGroup.AddEntry(existingEntry, true); m_database.RootGroup.AddEntry(userMrX.CreateProxyNode(), true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.Export(); var deltaDBInitial = new PwDatabase(); deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); foreach (var entry in deltaDBInitial.RootGroup.GetEntries(true)) { entry.SetTitle("Changed"); } deltaDBInitial.Save(null); deltaDBInitial.Close(); m_syncManager.AddImportPath(exportFile); m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword(userMrX.Strings.ReadSafe(KeeShare.KeeShare.PasswordField)); m_syncManager.RefeshSourcesList(); // Node normalEntry6 is within the user home and is relocated on export which changes the parent node - during import, the parents of // not "officially" relocated nodes is checked and an assertion is thrown Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Changed")); }
private void FillInFixture() { PwGroup rootGroup = m_database.RootGroup; m_treeManager.CreateNewUser("mrX"); m_treeManager.CreateNewUser("mrY"); m_standardKey = SyncSource.CreateKeyFor(STANDARD_PASSWORD); PwEntry mrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); PwEntry mrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY"); mrX.SetPassword(STANDARD_PASSWORD); mrY.SetPassword(STANDARD_PASSWORD); PwGroup mrXhome = m_database.GetUsersGroup().Groups.GetAt(0); //normal entries PwEntry normalEntry1 = new PwEntry(true, false); normalEntry1.SetTitle("normalEntry1"); Uuid1 = normalEntry1.Uuid; PwEntry normalEntry2 = new PwEntry(true, false); normalEntry2.SetTitle("normalEntry2"); Uuid2 = normalEntry2.Uuid; PwEntry normalEntry3 = new PwEntry(true, false); normalEntry3.SetTitle("normalEntry3"); Uuid3 = normalEntry3.Uuid; PwEntry normalEntry4 = new PwEntry(true, false); normalEntry4.SetTitle("normalEntry4"); Uuid4 = normalEntry4.Uuid; PwEntry normalEntry5 = new PwEntry(true, false); normalEntry5.SetTitle("normalEntry5"); Uuid5 = normalEntry5.Uuid; PwEntry normalEntry6 = new PwEntry(true, false); normalEntry6.SetTitle("normalEntry6"); Uuid6 = normalEntry6.Uuid; //pwdProxies PwEntry pwdProxyTo1 = PwNode.CreateProxyNode(normalEntry1); PwEntry pwdProxyTo3 = PwNode.CreateProxyNode(normalEntry3); //userProxies PwEntry userProxyToMrX = PwNode.CreateProxyNode(mrX); PwGroup grp1 = new PwGroup(true, true, "grp1", PwIcon.BlackBerry); rootGroup.AddEntry(normalEntry1, true); rootGroup.AddEntry(normalEntry2, true); rootGroup.AddEntry(normalEntry3, true); rootGroup.AddGroup(grp1, true); grp1.AddEntry(normalEntry4, true); grp1.AddEntry(normalEntry5, true); grp1.AddEntry(userProxyToMrX, true); grp1.AddEntry(pwdProxyTo1, true); mrXhome.AddEntry(normalEntry6, true); mrXhome.AddEntry(pwdProxyTo3, true); Assert.AreEqual(13, rootGroup.GetEntries(true).UCount); }
public void ShouldNotImportDatabasesWithDifferentUsers() { var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); var userMrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrY), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("Entry Version 1"); m_database.RootGroup.AddEntry(existingEntry, true); m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrY), true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrY) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.Export(); existingEntry.SetTitle("Entry Version 2"); var deltaDBInitial = new PwDatabase(); deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(0, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2")); Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); deltaDBInitial.Close(); m_syncManager.AddImportPath(exportFile); m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword("InvalidPassword"); m_syncManager.RefeshSourcesList(); Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 2")); Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); }
public void ShouldHandleCyclesOfNodesInImportAndExport() { var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("Entry Version 1"); m_database.RootGroup.AddEntry(existingEntry, true); m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); m_syncManager.Export(); var deltaDBInitial = new PwDatabase(); deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1")); foreach(var entry in deltaDBInitial.RootGroup.GetEntries(true)) { entry.SetTitle("Changed"); } deltaDBInitial.Save(null); deltaDBInitial.Close(); m_syncManager.AddImportPath(exportFile); m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword(userMrX.Strings.ReadSafe(KeeShare.KeeShare.PasswordField)); m_syncManager.RefeshSourcesList(); // Node normalEntry6 is within the user home and is relocated on export which changes the parent node - during import, the parents of // not "officially" relocated nodes is checked and an assertion is thrown Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Changed")); }
public void ShouldExportImportedNodes() { var importDatabase = TestHelper.CreateDatabase(); var importedEntry = new PwEntry(true, true); importedEntry.SetTitle("ImportedEntry"); var importedGroup = new PwGroup(true, true); importedGroup.Name = "ImportedGroup"; importedGroup.AddEntry(importedEntry, true); importDatabase.RootGroup.AddGroup(importedGroup, true); var exportPath = GetTestPath(); m_syncManager.AddExportPath(exportPath); var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); m_database.GetExportGroup().Groups.GetAt(0).AddEntry(PwNode.CreateProxyNode(userMrX), true); m_database.RootGroup.AddEntry(PwNode.CreateProxyNode(userMrX), true); var existingEntry = new PwEntry(true, true); existingEntry.SetTitle("ExistingEntry"); m_database.RootGroup.AddEntry(existingEntry, true); m_treeManager.CorrectStructure(); string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension; Assert.IsFalse(File.Exists(exportFile)); Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(0, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); m_syncManager.Export(); Assert.IsTrue(File.Exists(exportFile)); var importer = new SyncImporterAccessor(); importer.MergeInAccessor(m_database, importDatabase); Assert.AreEqual(1, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(1, m_database.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); m_syncManager.Export(); Assert.IsTrue(File.Exists(exportFile)); var deltaDBUpdated = new PwDatabase(); deltaDBUpdated.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null); Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "ImportedEntry")); Assert.AreEqual(1, deltaDBUpdated.RootGroup.GetGroups(true).Count(g => g.Name == "ImportedGroup")); deltaDBUpdated.Close(); }
private void FillInFixture() { PwGroup rootGroup = m_database.RootGroup; m_treeManager.CreateNewUser("mrX"); m_treeManager.CreateNewUser("mrY"); m_standardKey = SyncSource.CreateKeyFor(STANDARD_PASSWORD); PwEntry mrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX"); PwEntry mrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY"); mrX.SetPassword(STANDARD_PASSWORD); mrY.SetPassword(STANDARD_PASSWORD); PwGroup mrXhome = m_database.GetUsersGroup().Groups.GetAt(0); //normal entries PwEntry normalEntry1 = new PwEntry(true, false); normalEntry1.SetTitle("normalEntry1"); Uuid1 = normalEntry1.Uuid; PwEntry normalEntry2 = new PwEntry(true, false); normalEntry2.SetTitle("normalEntry2"); Uuid2 = normalEntry2.Uuid; PwEntry normalEntry3 = new PwEntry(true, false); normalEntry3.SetTitle("normalEntry3"); Uuid3 = normalEntry3.Uuid; PwEntry normalEntry4 = new PwEntry(true, false); normalEntry4.SetTitle("normalEntry4"); Uuid4 = normalEntry4.Uuid; PwEntry normalEntry5 = new PwEntry(true, false); normalEntry5.SetTitle("normalEntry5"); Uuid5 = normalEntry5.Uuid; PwEntry normalEntry6 = new PwEntry(true, false); normalEntry6.SetTitle("normalEntry6"); Uuid6 = normalEntry6.Uuid; //pwdProxies PwEntry pwdProxyTo1 = normalEntry1.CreateProxyNode(); PwEntry pwdProxyTo3 = normalEntry3.CreateProxyNode(); //userProxies PwEntry userProxyToMrX = mrX.CreateProxyNode(); PwGroup grp1 = new PwGroup(true, true, "grp1", PwIcon.BlackBerry); rootGroup.AddEntry(normalEntry1, true); rootGroup.AddEntry(normalEntry2, true); rootGroup.AddEntry(normalEntry3, true); rootGroup.AddGroup(grp1, true); grp1.AddEntry(normalEntry4, true); grp1.AddEntry(normalEntry5, true); grp1.AddEntry(userProxyToMrX, true); grp1.AddEntry(pwdProxyTo1, true); mrXhome.AddEntry(normalEntry6, true); mrXhome.AddEntry(pwdProxyTo3, true); Assert.AreEqual(13, rootGroup.GetEntries(true).UCount); }