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 RemovingKeyringRemovesItFromKeyringList()
        {
            string keyringName = "akeyring";

            Ring.CreateKeyring(keyringName, "password");
            Assert.Contains(keyringName, Ring.GetKeyrings());
            Ring.DeleteKeyring(keyringName);
            TestHelpers.NotContains(keyringName, Ring.GetKeyrings());
        }
        public void CreatedKeyringAppearsInKeyringList()
        {
            Ring.ApplicationName = "Tests";
            string keyringName = "atestkeyring";

            Ring.CreateKeyring(keyringName, "password");
            Assert.Contains(keyringName, Ring.GetKeyrings());
            Ring.DeleteKeyring(keyringName);
        }
        public void CreatingTheSameKeyringTwiceRaisesException()
        {
            string keyringName = "anothertestkeyring";

            Ring.CreateKeyring(keyringName, "password");
            try {
                Ring.CreateKeyring(keyringName, "password");
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
 public void SetUp()
 {
     try {
         Ring.CreateKeyring("keyring1", "password");
     } catch (KeyringException e) {
         if (e.ResultCode != ResultCode.AlreadyExists)
         {
             throw;
         }
     }
     Ring.SetDefaultKeyring("keyring1");
 }
        public void SetDefaultKeyringUpdatesGetDefaultKeyring()
        {
            string prevDefault = Ring.GetDefaultKeyring();

            Ring.CreateKeyring("test1", "password");
            try {
                Ring.SetDefaultKeyring("test1");
                Assert.AreEqual("test1", Ring.GetDefaultKeyring());
            } finally {
                Ring.DeleteKeyring("test1");
                Ring.SetDefaultKeyring(prevDefault);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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 SetKeyringLockOnIdleUpdatesInfo()
        {
            string keyringName = "theamazingtestkeyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                KeyringInfo info = Ring.GetKeyringInfo(keyringName);
                info.LockOnIdle = !info.LockOnIdle;
                Assert.AreNotEqual(info.LockOnIdle, Ring.GetKeyringInfo(keyringName).LockOnIdle);

                Ring.SetKeyringInfo(keyringName, info);
                Assert.AreEqual(info.LockOnIdle, Ring.GetKeyringInfo(keyringName).LockOnIdle);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
        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);
            }
        }
        public void SetKeyringInfoUpdatesLockTimeout()
        {
            string keyringName = "testkeyring";

            Ring.CreateKeyring(keyringName, "password");

            try {
                KeyringInfo info = Ring.GetKeyringInfo(keyringName);
                info.LockTimeoutSeconds++;
                Assert.AreNotEqual(info.LockTimeoutSeconds, Ring.GetKeyringInfo(keyringName).LockTimeoutSeconds);

                Ring.Unlock(keyringName, null);
                Ring.SetKeyringInfo(keyringName, info);
                Assert.AreEqual(info.LockTimeoutSeconds, Ring.GetKeyringInfo(keyringName).LockTimeoutSeconds);
            } finally {
                Ring.DeleteKeyring(keyringName);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }