コード例 #1
0
        public async Task RequestFailRegex_UnbanIp_ReturnsNotFound()
        {
            IPBanningModule.TryUnbanIP(Localhost);

            _ = await Client.SendAsync(GetNotFoundRequest());

            _ = await Client.SendAsync(GetNotFoundRequest());

            _ = await Client.SendAsync(GetNotFoundRequest());

            // Giving some time for logging
            await Task.Delay(200);

            var response = await Client.SendAsync(GetNotFoundRequest());

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "Status Code Forbidden");

            var bannedIps = IPBanningModule.GetBannedIPs();

            foreach (var address in bannedIps)
            {
                IPBanningModule.TryUnbanIP(address.IPAddress);
            }

            response = await Client.SendAsync(GetNotFoundRequest());

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode, "Status Code NotFound");
        }
コード例 #2
0
        public async Task MaxRps_ReturnsForbidden()
        {
            IPBanningModule.TryUnbanIP(Localhost);

            foreach (var _ in Enumerable.Range(0, 100))
            {
                await Client.SendAsync(GetEmptyRequest());
            }

            var response = await Client.SendAsync(GetEmptyRequest());

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "Status Code Forbidden");
        }
コード例 #3
0
        public async Task BanIpDateTime_ReturnsForbidden()
        {
            IPBanningModule.TryUnbanIP(Localhost);

            var response = await Client.SendAsync(GetNotFoundRequest());

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode, "Status Code NotFound");

            IPBanningModule.TryBanIP(Localhost, DateTime.Now.AddMinutes(10));

            response = await Client.SendAsync(GetNotFoundRequest());

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "Status Code Forbidden");
        }
コード例 #4
0
        public async Task RequestFailRegex_ReturnsForbidden()
        {
            IPBanningModule.TryUnbanIP(Localhost);

            _ = await Client.SendAsync(GetNotFoundRequest());

            _ = await Client.SendAsync(GetUnauthorizedRequest());

            _ = await Client.SendAsync(GetNotFoundRequest());

            // Giving some time for logging
            await Task.Delay(200);

            var response = await Client.SendAsync(GetNotFoundRequest());

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "Status Code Forbidden");
        }