- Introduced `sink-detect.js` with various security sink detection patterns categorized by type (e.g., command injection, SQL injection, file operations). - Implemented functions to build a lookup map for fast sink detection and to match sink calls against known patterns. - Added `package-lock.json` for dependency management.
125 lines
3.4 KiB
C#
125 lines
3.4 KiB
C#
// -----------------------------------------------------------------------------
|
|
// RouterTestFixture.cs
|
|
// Sprint: SPRINT_5100_0005_0001_router_chaos_suite
|
|
// Task: T2 - Backpressure Verification Tests
|
|
// Description: Test fixture for router chaos testing with Valkey support.
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using System.Net.Http.Json;
|
|
|
|
namespace StellaOps.Chaos.Router.Tests.Fixtures;
|
|
|
|
/// <summary>
|
|
/// Test fixture providing an HTTP client for router chaos testing.
|
|
/// </summary>
|
|
public class RouterTestFixture : IAsyncLifetime
|
|
{
|
|
private readonly HttpClient _client;
|
|
private readonly string _routerUrl;
|
|
|
|
public RouterTestFixture()
|
|
{
|
|
_routerUrl = Environment.GetEnvironmentVariable("ROUTER_URL") ?? "http://localhost:8080";
|
|
|
|
_client = new HttpClient
|
|
{
|
|
BaseAddress = new Uri(_routerUrl),
|
|
Timeout = TimeSpan.FromSeconds(30)
|
|
};
|
|
}
|
|
|
|
public HttpClient CreateClient() => _client;
|
|
|
|
public string RouterUrl => _routerUrl;
|
|
|
|
/// <summary>
|
|
/// Configure router with lower limits for overload testing.
|
|
/// </summary>
|
|
public async Task ConfigureLowLimitsAsync()
|
|
{
|
|
// In real scenario, this would configure the router via admin endpoint
|
|
// For now, assume limits are pre-configured for chaos testing
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a scan request payload.
|
|
/// </summary>
|
|
public static HttpContent CreateScanRequest(string? scanId = null)
|
|
{
|
|
var request = new
|
|
{
|
|
image = "alpine:latest",
|
|
scanId = scanId ?? Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToString("O")
|
|
};
|
|
|
|
return JsonContent.Create(request);
|
|
}
|
|
|
|
public Task InitializeAsync()
|
|
{
|
|
// Verify router is reachable
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
_client.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extended fixture with Valkey container support for failure injection.
|
|
/// </summary>
|
|
public class RouterWithValkeyFixture : RouterTestFixture
|
|
{
|
|
private Testcontainers.Redis.RedisContainer? _valkeyContainer;
|
|
private bool _valkeyRunning;
|
|
|
|
public async Task StartValkeyAsync()
|
|
{
|
|
if (_valkeyContainer is null)
|
|
{
|
|
_valkeyContainer = new Testcontainers.Redis.RedisBuilder()
|
|
.WithImage("valkey/valkey:7-alpine")
|
|
.WithName($"chaos-valkey-{Guid.NewGuid():N}")
|
|
.Build();
|
|
}
|
|
|
|
if (!_valkeyRunning)
|
|
{
|
|
await _valkeyContainer.StartAsync();
|
|
_valkeyRunning = true;
|
|
}
|
|
}
|
|
|
|
public async Task StopValkeyAsync()
|
|
{
|
|
if (_valkeyContainer is not null && _valkeyRunning)
|
|
{
|
|
await _valkeyContainer.StopAsync();
|
|
_valkeyRunning = false;
|
|
}
|
|
}
|
|
|
|
public async Task ConfigureValkeyLatencyAsync(TimeSpan latency)
|
|
{
|
|
// Configure artificial latency via Valkey DEBUG SLEEP
|
|
// In production, use network simulation tools like tc or toxiproxy
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
public new async Task DisposeAsync()
|
|
{
|
|
if (_valkeyContainer is not null)
|
|
{
|
|
await _valkeyContainer.StopAsync();
|
|
await _valkeyContainer.DisposeAsync();
|
|
}
|
|
|
|
await base.DisposeAsync();
|
|
}
|
|
}
|