コード例 #1
0
        public void FindItemByAttributeOnlyFindsMatchingIDs()
        {
            string keyringName = "keyring1";

            List <int> correct_ids   = new List <int> ();
            List <int> incorrect_ids = new List <int> ();

            Hashtable correctAttr = new Hashtable();

            correctAttr["banana"] = "a fruit";
            Hashtable incorrectAttr = new Hashtable();

            incorrectAttr["banana"] = "a fish";

            correct_ids.Add(Ring.CreateItem(keyringName, ItemType.Note, "a note", correctAttr, "secret", false));
            incorrect_ids.Add(Ring.CreateItem(keyringName, ItemType.GenericSecret, "not a note", incorrectAttr, "secret", false));
            correct_ids.Add(Ring.CreateItem(keyringName, ItemType.Note, "another note", correctAttr, "notsecret", false));
            correct_ids.Add(Ring.CreateItem(keyringName, ItemType.Note, "a third note", correctAttr, "reallysecret", false));
            incorrect_ids.Add(Ring.CreateOrModifyNetworkPassword(keyringName, "use4r", "domain", "server", "object", "protocol", "authtype", 42, "password"));

            CollectionAssert.IsSubsetOf(Ring.Find(ItemType.Note, correctAttr).
                                        Where((data) => data.Keyring == keyringName).
                                        Select((data) => data.ItemID).ToList(), correct_ids);
            foreach (var id in incorrect_ids)
            {
                CollectionAssert.DoesNotContain(Ring.Find(ItemType.Note, correctAttr).
                                                Where((data) => data.Keyring == keyringName).
                                                Select((data) => data.ItemID), id);
            }
        }
コード例 #2
0
        public void AccessingALockedKeyringPromptsToUnlock()
        {
            string keyringName = "akeyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                Ring.Lock(keyringName);
                Ring.CreateItem(keyringName, ItemType.Note, "Random note", new Hashtable(), "reallysecret", false);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #3
0
        public void DeletingItemRemovesItFromIdList()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                int id = Ring.CreateItem(keyringName, ItemType.Note, "test data", new Hashtable(), "secret", false);
                CollectionAssert.Contains(Ring.ListItemIDs(keyringName), id);
                Ring.DeleteItem(keyringName, id);
                CollectionAssert.DoesNotContain(Ring.ListItemIDs(keyringName), id);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #4
0
        public void DataOfAddedItemPersists()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                int id = Ring.CreateItem(keyringName, ItemType.Note, "test data", new Hashtable(), "secret", false);

                ItemData item = Ring.GetItemInfo(keyringName, id);
                Assert.AreEqual("test data", (string)item.Attributes["name"]);
                Assert.AreEqual("secret", item.Secret);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #5
0
        public void GetItemAttributesReturnsCreatedValues()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                Hashtable attributes = new Hashtable();
                attributes["stringAttr"] = "astring";
                attributes["uintAttr"]   = 42;
                int id = Ring.CreateItem(keyringName, ItemType.Note, "test", attributes, "secret", false);

                CollectionAssert.IsSubsetOf(attributes, Ring.GetItemAttributes(keyringName, id));
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #6
0
        public void SetItemDataPersists()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                int id = Ring.CreateItem(keyringName, ItemType.Note, "test", new Hashtable(), "secret", false);

                Ring.SetItemInfo(keyringName, id, ItemType.GenericSecret, "newdisplayname", "newsecret");
                ItemData item = Ring.GetItemInfo(keyringName, id);
                Assert.AreEqual("newdisplayname", (string)item.Attributes["name"]);
                Assert.AreEqual("newsecret", item.Secret);
                Assert.AreEqual(ItemType.GenericSecret, item.Type);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #7
0
        public void CreatedItemIdExistsInIdList()
        {
            string keyringName = "testifu";

            Ring.CreateKeyring(keyringName, "password");

            Hashtable attributes = new Hashtable();

            attributes["name"]     = "woot";
            attributes["banana"]   = "some other value";
            attributes["eggplant"] = "aubergine";
            attributes["apple"]    = 25;

            try {
                int id = Ring.CreateItem(keyringName, ItemType.Note, "Random note", attributes, "reallysecret", false);
                CollectionAssert.Contains(Ring.ListItemIDs(keyringName), id);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #8
0
        public void FindNetworkPasswordByDomainFindsAppropriateIDs()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");
            List <int> ids = new List <int> ();

            try {
                ids.Add(Ring.CreateOrModifyNetworkPassword(keyringName, "user", "domain", "server", "object", "protocol", "authtype", 42, "password"));
                Ring.CreateOrModifyNetworkPassword(keyringName, "user2", "d3omain", "4server", "o5bject", "proto6col", "3authtype", 49, "password");
                Ring.CreateItem(keyringName, ItemType.Note, "I'm not a network password", new Hashtable(), "secret", false);
                ids.Add(Ring.CreateOrModifyNetworkPassword(keyringName, "u3ser", "domain", "server", "object", "protocol", "authtype", 42, "password"));
                ids.Add(Ring.CreateOrModifyNetworkPassword(keyringName, "use4r", "domain", "server", "object", "protocol", "authtype", 42, "password"));

                CollectionAssert.AreEquivalent(ids, Ring.FindNetworkPassword(null, "domain", null, null, null, null, 0).
                                               Where((NetItemData data) => data.Keyring == keyringName).
                                               Select((NetItemData data) => data.ItemID).ToList());
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #9
0
        public void SetItemAttributesPersists()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                int id = Ring.CreateItem(keyringName, ItemType.Note, "test", new Hashtable(), "secret", false);

                Hashtable attributes = new Hashtable();
                attributes["stringAttr"] = "astring";
                attributes["meaning"]    = 42;
                attributes["UTF8"]       = "♪ “The sun is a mass of incandescent gas” ♫";

                Ring.SetItemAttributes(keyringName, id, attributes);

                CollectionAssert.IsSubsetOf(attributes, Ring.GetItemAttributes(keyringName, id));
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
コード例 #10
0
        static void Main()
        {
            if (!Ring.Available)
            {
                Console.WriteLine("The gnome-keyring-daemon cannot be reached.");
                return;
            }

            string deflt = Ring.GetDefaultKeyring();

            Console.WriteLine("The default keyring is '{0}'", deflt);
            Console.Write("Other rings available: ");

            foreach (string s in Ring.GetKeyrings())
            {
                if (s != deflt)
                {
                    Console.Write("'{0}' ", s);
                }
            }
            Console.WriteLine();

            // This is equivalent to...
            foreach (ItemData s in Ring.FindNetworkPassword("gonzalo", null, null, null, null, null, 0))
            {
                Console.WriteLine("HERE");
                Console.WriteLine(s);
            }

            // ... this other search.
            Hashtable tbl = new Hashtable();

            tbl ["user"] = "******";
            foreach (ItemData s in Ring.Find(ItemType.NetworkPassword, tbl))
            {
                Console.WriteLine(s);
            }

            tbl            = new Hashtable();
            tbl ["user"]   = "******";
            tbl ["domain"] = "MiDomain";
            Console.WriteLine("Creating item");
            int      i  = Ring.CreateItem(null, ItemType.NetworkPassword, "*****@*****.**", tbl, "laclave", true);
            ItemData d2 = Ring.GetItemInfo(deflt, i);

            Ring.SetItemInfo(deflt, d2.ItemID, ItemType.NetworkPassword, "cambioesto@lalala", "otraclave");
            Hashtable atts = Ring.GetItemAttributes(deflt, i);

            foreach (string key in atts.Keys)
            {
                Console.WriteLine("{0}: {1}", key, atts [key]);
            }

            atts ["object"] = "new attributes";
            Ring.SetItemAttributes(deflt, i, atts);
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();

            Console.WriteLine("Deleting it (ID = {0})", i);
            Ring.DeleteItem(Ring.GetDefaultKeyring(), i);
            Console.WriteLine("Existing IDs...");
            foreach (int nn in Ring.ListItemIDs(deflt))
            {
                Console.WriteLine(nn);
            }

            KeyringInfo info = new KeyringInfo(true, 15);

            Ring.SetKeyringInfo(deflt, info);

            info = Ring.GetKeyringInfo(deflt);
            Console.WriteLine(info);
            ArrayList acl_list = Ring.GetItemACL(deflt, 3);

            foreach (ItemACL acl in acl_list)
            {
                Console.WriteLine(acl);
            }

            ArrayList list2 = new ArrayList(acl_list);

            list2.Add(new ItemACL("test", "/test", AccessRights.Read));
            Ring.SetItemACL(deflt, 3, list2);
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
            Ring.SetItemACL(deflt, 3, acl_list);
        }