1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

[PM-6141] Remove rate limiting ip blocker (#3754)

* remove rate limiting ip blocker

* remove using

* fix tests
This commit is contained in:
Kyle Spearrin
2024-02-07 12:23:26 -05:00
committed by GitHub
parent 6e6b50fd86
commit a019355ab4
15 changed files with 2 additions and 643 deletions

View File

@ -1,76 +0,0 @@
using Amazon.SQS;
using Bit.Core.Services;
using Bit.Core.Settings;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.Services;
public class AmazonSqsBlockIpServiceTests : IDisposable
{
private readonly AmazonSqsBlockIpService _sut;
private readonly GlobalSettings _globalSettings;
private readonly IAmazonSQS _amazonSqs;
public AmazonSqsBlockIpServiceTests()
{
_globalSettings = new GlobalSettings
{
Amazon =
{
AccessKeyId = "AccessKeyId-AmazonSesMailDeliveryServiceTests",
AccessKeySecret = "AccessKeySecret-AmazonSesMailDeliveryServiceTests",
Region = "Region-AmazonSesMailDeliveryServiceTests"
}
};
_amazonSqs = Substitute.For<IAmazonSQS>();
_sut = new AmazonSqsBlockIpService(_globalSettings, _amazonSqs);
}
public void Dispose()
{
_sut?.Dispose();
}
[Fact]
public async Task BlockIpAsync_UnblockCalled_WhenNotPermanent()
{
const string expectedIp = "ip";
await _sut.BlockIpAsync(expectedIp, false);
await _amazonSqs.Received(2).SendMessageAsync(
Arg.Any<string>(),
Arg.Is(expectedIp));
}
[Fact]
public async Task BlockIpAsync_UnblockNotCalled_WhenPermanent()
{
const string expectedIp = "ip";
await _sut.BlockIpAsync(expectedIp, true);
await _amazonSqs.Received(1).SendMessageAsync(
Arg.Any<string>(),
Arg.Is(expectedIp));
}
[Fact]
public async Task BlockIpAsync_NotBlocked_WhenAlreadyBlockedRecently()
{
const string expectedIp = "ip";
await _sut.BlockIpAsync(expectedIp, true);
// The second call should hit the already blocked guard clause
await _sut.BlockIpAsync(expectedIp, true);
await _amazonSqs.Received(1).SendMessageAsync(
Arg.Any<string>(),
Arg.Is(expectedIp));
}
}

View File

@ -1,27 +0,0 @@
using Bit.Core.Services;
using Bit.Core.Settings;
using Xunit;
namespace Bit.Core.Test.Services;
public class AzureQueueBlockIpServiceTests
{
private readonly AzureQueueBlockIpService _sut;
private readonly GlobalSettings _globalSettings;
public AzureQueueBlockIpServiceTests()
{
_globalSettings = new GlobalSettings();
_sut = new AzureQueueBlockIpService(_globalSettings);
}
// Remove this test when we add actual tests. It only proves that
// we've properly constructed the system under test.
[Fact(Skip = "Needs additional work")]
public void ServiceExists()
{
Assert.NotNull(_sut);
}
}

View File

@ -139,11 +139,6 @@ public abstract class WebApplicationFactoryBase<T> : WebApplicationFactory<T>
services.Remove(captchaValidationService);
services.AddSingleton<ICaptchaValidationService, NoopCaptchaValidationService>();
// Disable blocking
var blockingService = services.First(sd => sd.ServiceType == typeof(IBlockIpService));
services.Remove(blockingService);
services.AddSingleton<IBlockIpService, NoopBlockIpService>();
// TODO: Install and use azurite in CI pipeline
var installationDeviceRepository =
services.First(sd => sd.ServiceType == typeof(IInstallationDeviceRepository));