public void CreatedNetworkPasswordSetsAppropriateData()
        {
            string keyringName = "keyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                Hashtable data = new Hashtable();
                data["user"]     = "******";
                data["domain"]   = "divination";
                data["server"]   = "jeeves";
                data["object"]   = "subject";
                data["protocol"] = "droid";
                data["authtype"] = "smtp";
                data["port"]     = 42;

                //Password is stored in the secret.
                int id = Ring.CreateOrModifyNetworkPassword(keyringName, (string)data["user"], (string)data["domain"], (string)data["server"],
                                                            (string)data["object"], (string)data["protocol"], (string)data["authtype"], (int)data["port"], "password");

                CollectionAssert.IsSubsetOf(data, Ring.GetItemAttributes(keyringName, id));
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
        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);
            }
        }
        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);
            }
        }
Esempio n. 4
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);
        }