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"); }
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"); }
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"); }
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"); }