예제 #1
0
        public void RenameOfUserHomeShouldRenameItsRootAndAllProxies()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");
            PwEntry userRootNode        = TestHelper.GetUserRootNodeFor(m_database, 0);
            PwEntry userHomeProxyNode   = TestHelper.GetUserRootProxyFor(m_database, 0);
            PwEntry userExternProxyNode = userRootNode.CreateProxyNode();
            PwGroup userHome            = TestHelper.GetUserHomeNodeFor(m_database, 0);

            m_database.RootGroup.AddEntry(userExternProxyNode, true);

            //rename the homeFolder
            userHome.Name = "FolderNameChanged";
            TestHelper.SimulateTouch(userHome);

            m_treeManager.CorrectStructure();
            //refresh all references after update
            userRootNode        = TestHelper.GetUserRootNodeFor(m_database, 0);
            userHomeProxyNode   = TestHelper.GetUserRootNodeFor(m_database, 0);
            userExternProxyNode = m_database.RootGroup.Entries.GetAt(0);
            userHome            = TestHelper.GetUserHomeNodeFor(m_database, 0);
            //after that update same tests here
            Assert.AreEqual("FolderNameChanged", userRootNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.AreEqual("FolderNameChanged", userHomeProxyNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.AreEqual("FolderNameChanged", userExternProxyNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField));

            //everytime the UsersGroups should be sane!
            IsUsersGroupSane(m_database, 1);
        }
예제 #2
0
        public void RenamePwdProxyNodesTest()
        {
            m_treeManager.Initialize(m_database);
            PwEntry pwd1 = new PwEntry(true, true);

            pwd1.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "pwd1"));
            m_database.RootGroup.AddEntry(pwd1, true);
            pwd1.Touch(true);

            DateTime lastTouch = pwd1.LastModificationTime;

            PwEntry pwdProxy = pwd1.CreateProxyNode();

            m_database.GetGroupsGroup().AddEntry(pwdProxy, true);

            pwdProxy.LastModificationTime = lastTouch.AddTicks(10);

            m_treeManager.CorrectStructure();

            Assert.AreEqual(2, NumberOfEntriesIn(m_database));
            string pwdId = m_database.RootGroup.Entries.GetAt(0).Uuid.ToHexString();

            pwdProxy = m_database.GetGroupsGroup().Entries.GetAt(0);
            Assert.AreEqual(pwdId, pwdProxy.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField));

            pwdProxy.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "new Title"));
            pwdProxy.LastModificationTime = lastTouch.AddTicks(23);

            m_treeManager.CorrectStructure();
            Assert.AreEqual("new Title", m_database.RootGroup.Entries.GetAt(0).Strings.ReadSafe(KeeShare.KeeShare.TitleField));
        }
예제 #3
0
        public void RenameOfUserRootShouldRenameItsHomeAndAllProxies()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");
            PwEntry userRootNode        = TestHelper.GetUserRootNodeFor(m_database, 0);
            PwEntry userHomeProxyNode   = TestHelper.GetUserRootProxyFor(m_database, 0);
            PwEntry userExternProxyNode = userRootNode.CreateProxyNode();
            PwGroup userHome            = TestHelper.GetUserHomeNodeFor(m_database, 0);

            m_database.RootGroup.AddEntry(userExternProxyNode, true);
            userRootNode.CreateBackup(m_database);

            userRootNode.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "mrNew"));
            TestHelper.SimulateTouch(userRootNode);

            m_treeManager.CorrectStructure();
            //refresh all references after update
            userRootNode        = TestHelper.GetUserRootNodeFor(m_database, 0);
            userHomeProxyNode   = TestHelper.GetUserRootNodeFor(m_database, 0);
            userExternProxyNode = m_database.RootGroup.Entries.GetAt(0);
            userHome            = TestHelper.GetUserHomeNodeFor(m_database, 0);

            //after that update all proxyNodes schould have become the same name as the rootNode_X
            Assert.AreEqual("mrNew", userHomeProxyNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.AreEqual("mrNew", userExternProxyNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            //even the home of the user should have the new name
            Assert.AreEqual("mrNew", userHome.Name);
            //everytime the UsersGroups should be sane!
            IsUsersGroupSane(m_database, 1);
        }
예제 #4
0
        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();
        }
예제 #5
0
        public void ShouldRemoveRedundantProxies()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");

            PwEntry mrX    = TestHelper.GetUserRootNodeFor(m_database, 0);
            PwEntry proxy1 = mrX.CreateProxyNode();
            PwEntry proxy2 = mrX.CreateProxyNode();

            m_database.RootGroup.AddEntry(proxy1, true);
            m_database.RootGroup.AddEntry(proxy2, true);

            Assert.AreEqual(4, NumberOfEntriesIn(m_database));
            Assert.AreEqual(2, m_database.RootGroup.Entries.UCount);

            m_treeManager.CorrectStructure();

            Assert.AreEqual(3, NumberOfEntriesIn(m_database));
            Assert.AreEqual(1, m_database.RootGroup.Entries.UCount);
        }
예제 #6
0
        public void CreateProxyFromAnotherUserRootNode()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");

            PwEntry rootProxy = TestHelper.GetUserRootProxyFor(m_database, 0);
            PwEntry userProxy = rootProxy.CreateProxyNode();

            Assert.AreEqual("mrX", userProxy.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.AreEqual(rootProxy.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField), userProxy.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField));
            Assert.AreNotEqual(rootProxy.Uuid.ToHexString(), userProxy.Uuid.ToHexString());
        }
예제 #7
0
        [Test] //test complete
        public void DeleteOneUserShouldRemoveObsoleteProxyNodes()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");
            m_treeManager.CreateNewUser("mrY");

            //a DeleteUser should also delete all proxies of this user!
            //so we create some and look if all proxies will be deleted...
            PwGroup testGroup1 = new PwGroup(true, false);
            PwGroup testGroup2 = new PwGroup(true, false);
            PwGroup testGroup3 = new PwGroup(true, false);

            m_database.RootGroup.AddGroup(testGroup1, true);
            m_database.RootGroup.AddGroup(testGroup2, true);

            testGroup2.AddGroup(testGroup3, true);

            PwEntry mrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");
            PwEntry mrY = TestHelper.GetUserRootNodeByNameFor(m_database, "mrY");

            PwEntry mrXproxy1 = mrX.CreateProxyNode();
            PwEntry mrXproxy2 = mrX.CreateProxyNode();
            PwEntry mrXproxy3 = mrX.CreateProxyNode();

            testGroup1.AddEntry(mrXproxy1, true);
            testGroup2.AddEntry(mrXproxy2, true);
            testGroup3.AddEntry(mrXproxy3, true);

            Assert.AreEqual(7, NumberOfEntriesIn(m_database)); // 2 standard proxies each + 3 additional proxies for mrX

            m_treeManager.DeleteUser(mrX);

            Assert.AreEqual(2, NumberOfEntriesIn(m_database));
            foreach (PwEntry proxy in m_database.RootGroup.GetEntries(true))
            {
                Assert.AreEqual("mrY", proxy.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            }
            IsUsersGroupSane(m_database, 1);
        }
예제 #8
0
        public void CreateProxyNodeForStandardPwEntry()
        {
            m_treeManager.Initialize(m_database);
            PwEntry pwd = new PwEntry(true, true);

            pwd.Strings.Set(KeeShare.KeeShare.TitleField, new ProtectedString(false, "testTitle"));
            pwd.Strings.Set(KeeShare.KeeShare.PasswordField, new ProtectedString(false, "testPwd"));
            PwEntry proxy = pwd.CreateProxyNode();

            Assert.AreEqual("testTitle", proxy.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.AreEqual("testPwd", proxy.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));
            Assert.AreEqual(pwd.Uuid.ToHexString(), proxy.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField));
        }
예제 #9
0
        public void ShouldExportToTargets()
        {
            //we change the password which is used to encrypt the delta container so we can later access the delta container
            //more easily.
            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.
            var exportFolder = m_database.GetExportGroup();

            Assert.IsTrue(0 == exportFolder.Groups.UCount);
            string exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);
            var exportGroup = exportFolder.Groups.GetAt(0);

            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.Strings.ReadSafe(KeeShare.KeeShare.TitleField));

            Assert.IsTrue(File.Exists(exportFile));

            //now we open the creted delta container and verify the contend
            PwDatabase deltaDB = new PwDatabase();

            Assert.DoesNotThrow(delegate {
                deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            });

            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("normalEntry1", deltaDB.RootGroup.Entries.GetAt(0).GetTitle());
            deltaDB.Close();
        }
예제 #10
0
        /// <summary>
        /// The <c>ShareGroupWithUser</c> function adds an user-proxy to the group group.
        /// This userentry specifies the user how should become access to the group group.
        /// </summary>
        /// <param name="group">The group we want to share.</param>
        /// <param name="root">userRootNode of the user we want to share the group with.</param>
        private void ShareGroupWithUser(PwGroup group, PwEntry root)
        {
            //if (!UserExists(name)) return;
            //check if group is shared allready
            if (GroupIsSharedToUser(group, root))
            {
                return;
            }
            PwEntry proxyNode = root.CreateProxyNode();

            if (proxyNode != null)
            {
                proxyNode.SetParent(group);
            }
        }
예제 #11
0
        public void RespectProxiesOfDifferentUsersWithSameNameButDeleteRedudantOnes()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("mrX");
            m_treeManager.CreateNewUser("mrX");

            PwEntry mrX1 = TestHelper.GetUserRootNodeFor(m_database, 0);
            PwEntry mrX2 = TestHelper.GetUserRootNodeFor(m_database, 1);

            Assert.IsTrue(mrX1.IsUserRootNode());
            Assert.IsTrue(mrX2.IsUserRootNode());
            PwEntry proxyX1_1 = mrX1.CreateProxyNode();
            PwEntry proxyX1_2 = mrX1.CreateProxyNode();
            PwEntry proxyX2_1 = mrX2.CreateProxyNode();
            PwEntry proxyX2_2 = mrX2.CreateProxyNode();

            m_database.RootGroup.AddEntry(proxyX1_1, true);
            m_database.RootGroup.AddEntry(proxyX1_2, true);
            m_database.RootGroup.AddEntry(proxyX2_1, true);
            m_database.RootGroup.AddEntry(proxyX2_2, true);
            m_treeManager.CorrectStructure();

            Assert.AreEqual(6, NumberOfEntriesIn(m_database));
        }
예제 #12
0
        /// <summary>
        /// The <c>CreateNewUser</c> function creates a new user you
        /// later can share passwords with.
        /// This includes a proxy in the UsersGroupName group and also
        /// creates a new user-specific group in the tree UsersGroupName
        /// </summary>
        /// <param name="name">oldUserName of the new user</param>
        /// <returns>True if all is done properly! False otherwise!</returns>
        protected Changes CreateNewUser(string name, PwGroup useAsHome = null)
        {
            PwEntry newUser      = CreateUserNode(name);
            PwGroup newUserGroup = useAsHome;

            if (newUserGroup == null) //create a new home for that user
            {
                newUserGroup = m_database.GetUserHomeFor(newUser, true);
            }
            else
            {
                newUserGroup.IconId = PwIcon.UserKey;
                newUserGroup.Notes += newUser.Uuid.ToHexString();
            }

            //put the userRootNode into his homefolder
            newUser.SetParent(newUserGroup);
            //due to better userHandling while dragNdrop we create a proxyNode in the usersGroup
            PwEntry proxy = newUser.CreateProxyNode();

            proxy.SetParent(m_database.GetUsersGroup());
            return(Changes.GroupCreated | Changes.EntryCreated);
        }
예제 #13
0
        private Changes RestoreMovedUserNode(PwEntry userNode, PwGroup userHome, PwGroup usersGroup)
        {
            //only the userNode was moved..
            //are we located anywhere in the "users"group => here we have to be careful!
            if (userNode.IsInsideParent(usersGroup))
            {
                //do we have a applicable homeFolder?
                if (null != userHome)
                {
                    //then we should only move back!
                    userNode.ParentGroup.Entries.Remove(userNode);
                    userNode.SetParent(userHome);
                    //and we are done here...
                    return(Changes.EntryMoved);
                }
            }
            else
            {
                //else userNode was moved intentionally to share a folder, so move the rootNode back
                //and create a proxy at the new location
                PwGroup parentGroup = userNode.ParentGroup;
                parentGroup.Entries.Remove(userNode);
                //ensure that the original rootNode is located in his homefolder
                //move the original userRootNode back to his homefolder
                userNode.SetParent(m_database.GetUserHomeFor(userNode));

                //create proxyNode in the folder
                if (!GroupIsSharedToUser(parentGroup, userNode))
                {
                    PwEntry proxy = userNode.CreateProxyNode();
                    proxy.SetParent(parentGroup);
                    return(Changes.EntryMoved | Changes.EntryCreated);
                }
                return(Changes.EntryMoved);
            }
            return(Changes.None);
        }
예제 #14
0
        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);
        }