You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
// FIXME: Update this file to be null safe and then delete the line below |
|
#nullable disable |
|
|
|
using System.Net; |
|
using Bit.IntegrationTestCommon.Factories; |
|
using Microsoft.AspNetCore.Builder; |
|
using Microsoft.AspNetCore.Hosting; |
|
using Microsoft.AspNetCore.Http; |
|
|
|
namespace Bit.IntegrationTestCommon; |
|
|
|
public class FakeRemoteIpAddressMiddleware |
|
{ |
|
private readonly RequestDelegate _next; |
|
private readonly IPAddress _fakeIpAddress; |
|
|
|
public FakeRemoteIpAddressMiddleware(RequestDelegate next, IPAddress fakeIpAddress = null) |
|
{ |
|
_next = next; |
|
_fakeIpAddress = fakeIpAddress ?? IPAddress.Parse(FactoryConstants.WhitelistedIp); |
|
} |
|
|
|
public async Task Invoke(HttpContext httpContext) |
|
{ |
|
httpContext.Connection.RemoteIpAddress ??= _fakeIpAddress; |
|
await _next(httpContext); |
|
} |
|
} |
|
|
|
public class CustomStartupFilter : IStartupFilter |
|
{ |
|
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) |
|
{ |
|
return app => |
|
{ |
|
app.UseMiddleware<FakeRemoteIpAddressMiddleware>(); |
|
next(app); |
|
}; |
|
} |
|
}
|
|
|