예제 #1
0
        public void NewUserShouldCreateValidTreeStructure()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("Hans");

            PwGroup usersGroup = TestHelper.GetUsersGroupFor(m_database);

            Assert.AreEqual(1, usersGroup.Entries.UCount);
            Assert.AreEqual(1, usersGroup.Groups.UCount);

            PwGroup userHome = TestHelper.GetUserHomeNodeFor(m_database, 0);

            Assert.AreEqual(1, userHome.Entries.UCount);
            Assert.AreEqual("Hans", userHome.Name);

            PwEntry userEntry = TestHelper.GetUserRootNodeFor(m_database, 0);

            Assert.AreEqual("Hans", userEntry.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.IsFalse(userEntry.IsProxyNode());
            Assert.IsFalse(userEntry.IsNormalPwEntry());

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

            Assert.AreEqual("Hans", userProxy.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.IsTrue(userProxy.IsProxyNode());

            Assert.AreEqual(2, NumberOfEntriesIn(m_database)); // a root node and a proxy node

            IsUsersGroupSane(m_database, 1);
        }
예제 #2
0
        /// <summary>
        /// The function checks if thelast made change has to be propageted to
        /// some referenced PwEntries
        /// </summary>
        /// <returns>True if the function has made changes to the database.</returns>
        private Changes CheckReferences()
        {
            PwEntry lastModifiedEntry = GetLastModifiedEntry();

            //if there are no changes, then we have nothing to do
            if (lastModifiedEntry == null)
            {
                return(Changes.None);
            }
            //was it a proxy or not?
            Changes changeFlag = Changes.None;

            if (lastModifiedEntry.IsProxyNode())
            {
                //lets update the root so we later can update all proxies
                PwEntry root = m_database.GetProxyTargetFor(lastModifiedEntry);
                //check if there are real changes! if not we are done here
                if (lastModifiedEntry.IsSimilarTo(root, true))
                {
                    return(Changes.None);
                }
                PwGroup parent = root.ParentGroup;

                root.CreateBackup(m_database); //rootNode_X should save all modifications in history
                parent.Entries.Remove(root);

                PwEntry updatedRoot = lastModifiedEntry.CloneDeep();
                updatedRoot.Uuid = root.Uuid;
                updatedRoot.SetParent(parent);
                //special handling for userRootNodes because they have a homefolder
                if (root.IsUserRootNode())
                {
                    //maybe the oldUserName has changed to => the homefolder should have the new name also
                    //we also want to have the same icons everywhere
                    parent.Name   = updatedRoot.GetTitle();
                    parent.IconId = updatedRoot.IconId;
                }
                else
                {
                    updatedRoot.Strings.Remove(KeeShare.UuidLinkField);
                }
                changeFlag |= UpdateProxyInformation(updatedRoot);
                changeFlag |= Changes.GroupDeleted;
            }
            else
            {
                changeFlag |= UpdateProxyInformation(lastModifiedEntry);
            }
            pe_lastModedEntry = GetLastModifiedEntry();
            return(changeFlag);
        }
예제 #3
0
 /// <summary>
 /// Checks if the given entry is a proxy of a UserRootNode
 /// </summary>
 /// <param name="entry">the entry you want to check</param>
 /// <returns>True if the entry is a UserProxy</returns>
 public static bool IsUserProxy(this PwDatabase database, PwEntry entry)
 {
     if (!entry.IsProxyNode())
     {
         return(false);
     }
     Debug.Assert(database != null);
     foreach (PwEntry root in database.GetAllUserNodes())
     {
         if (root.Uuid.ToHexString() == entry.Strings.ReadSafe(KeeShare.UuidLinkField))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
        public void ShouldAllowUsersWithSameName()
        {
            m_treeManager.Initialize(m_database);
            m_treeManager.CreateNewUser("Hans");
            m_treeManager.CreateNewUser("Hans");

            PwGroup usersGroup = TestHelper.GetUsersGroupFor(m_database);

            Assert.AreEqual(2, usersGroup.Entries.UCount);
            Assert.AreEqual(2, usersGroup.Groups.UCount);

            PwGroup userGroup1 = TestHelper.GetUserHomeNodeFor(m_database, 0);

            Assert.AreEqual(1, userGroup1.Entries.UCount);
            Assert.AreEqual("Hans", userGroup1.Name);
            PwGroup userGroup2 = TestHelper.GetUserHomeNodeFor(m_database, 1);

            Assert.AreEqual(1, userGroup2.Entries.UCount);
            Assert.AreEqual("Hans", userGroup2.Name);
            Assert.AreNotSame(userGroup1, userGroup2);

            PwEntry userEntry1 = TestHelper.GetUserRootNodeFor(m_database, 0);

            Assert.AreEqual("Hans", userEntry1.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.IsFalse(userEntry1.IsProxyNode());
            Assert.IsFalse(userEntry1.IsNormalPwEntry());
            PwEntry userEntry2 = TestHelper.GetUserRootNodeFor(m_database, 1);

            Assert.AreEqual("Hans", userEntry2.Strings.ReadSafe(KeeShare.KeeShare.TitleField));
            Assert.IsFalse(userEntry2.IsProxyNode());
            Assert.IsFalse(userEntry2.IsNormalPwEntry());
            Assert.AreNotSame(userEntry1, userEntry2);
            Assert.AreNotEqual(userEntry1.Uuid, userEntry2.Uuid);

            PwEntry userProxy1 = TestHelper.GetUserRootProxyFor(m_database, 0);

            Assert.IsTrue(userProxy1.IsProxyNode());
            PwEntry userProxy2 = TestHelper.GetUserRootProxyFor(m_database, 1);

            Assert.IsTrue(userProxy2.IsProxyNode());
            Assert.AreNotSame(userProxy1, userProxy2);
            Assert.AreNotEqual(userProxy1.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField), userProxy2.Strings.ReadSafe(KeeShare.KeeShare.UuidLinkField));

            Assert.AreEqual(4, NumberOfEntriesIn(m_database)); // each a root node and a proxy node!

            IsUsersGroupSane(m_database, 2);
        }
        public void IsProxyNodeTest()
        {
            //should all be false:
            Assert.IsFalse(root1.IsProxyNode());
            Assert.IsFalse(root2.IsProxyNode());
            Assert.IsFalse(normalEntry1.IsProxyNode());
            Assert.IsFalse(normalEntry2.IsProxyNode());
            Assert.IsFalse(normalEntry3.IsProxyNode());

            //should all be true:
            Assert.IsTrue(pwdProxyTo1.IsProxyNode());
            Assert.IsTrue(pwdProxyTo3.IsProxyNode());
            Assert.IsTrue(pwdProxyTo3_1.IsProxyNode());
            Assert.IsTrue(proxyToRoot1.IsProxyNode());
            Assert.IsTrue(brokenProxy1.IsProxyNode());
            Assert.IsTrue(brokenProxy2.IsProxyNode());
        }
예제 #6
0
 public static bool IsPasswordProxy(this PwDatabase database, PwEntry entry)
 {
     return(entry.IsProxyNode() && !database.IsUserProxy(entry));
 }
예제 #7
0
 public static string ToDebugString(this PwEntry entry)
 {
     return("\"" + entry.Strings.ReadSafe(KeeShare.TitleField) + "\" " + entry.Uuid.ToHexString() + " " + entry.IsProxyNode());
 }
 /// <summary>
 /// Checks if the given entry is a proxy of a UserRootNode
 /// </summary>
 /// <param name="entry">the entry you want to check</param>
 /// <returns>True if the entry is a UserProxy</returns>
 public static bool IsUserProxy(this PwDatabase database, PwEntry entry)
 {
     if (!entry.IsProxyNode())
     {
         return false;
     }
     Debug.Assert(database != null);
     foreach (PwEntry root in ExtensionMethods.GetAllUserNodes(database))
     {
         if (root.Uuid.ToHexString() == entry.Strings.ReadSafe(KeeShare.UuidLinkField))
         {
             return true;
         }
     }
     return false;
 }
 public static bool IsPasswordProxy(this PwDatabase database, PwEntry entry)
 {
     return entry.IsProxyNode() && !database.IsUserProxy(entry);
 }