Exemplo n.º 1
0
        public void TestKeyBlacklisting()
        {
            var key = GetRandomKey();
            var ip  = GetRandomIP();

            var interval = TimeSpan.FromMinutes(1);

            Assert.AreEqual(
                false,
                Hacker.IsKeyBlacklistedAsync(key).Run(),
                "Key must not be blacklisted");

            var startTime = DateTime.Now;

            Hacker.BlacklistKeyAsync(key, interval).Run();

            Assert.AreEqual(
                true,
                Hacker.IsKeyBlacklistedAsync(key).Run(),
                "Key must be blacklisted");

            string [] blacklistedKeys = Hacker.GetKeyBlacklists().Run();
            Assert.IsTrue(Array.Exists(blacklistedKeys, k => k == key),
                          "Key must be in the blacklist");

            WaitForIntervalToElapse(interval, startTime);

            Assert.AreEqual(
                false,
                Hacker.IsKeyBlacklistedAsync(key).Run(),
                "Key must not be blacklisted after expiration time");
        }