513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
40 lines
2.2 KiB
C#
40 lines
2.2 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using ZB.MOM.WW.ScadaBridge.CentralUI.ScriptAnalysis;
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.ScriptAnalysis;
|
|
[Collection("Sandbox worker processes")]
|
|
public class BoundedSandboxOutputTests
|
|
{
|
|
/// <summary>Verifies that oversized console output and return values are explicitly truncated.</summary>
|
|
/// <param name="returnExpression">The script expression whose value is returned.</param>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Theory]
|
|
[InlineData("block")]
|
|
[InlineData("new { Data = block }")]
|
|
public async Task Worker_OversizedConsoleAndReturn_AreExplicitlyBounded(string returnExpression)
|
|
{
|
|
using var services = new Microsoft.Extensions.DependencyInjection.ServiceCollection().BuildServiceProvider();
|
|
using var cache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
|
|
var runner = new ScriptAnalysisService(NSubstitute.Substitute.For<ISharedScriptCatalog>(), cache, services);
|
|
var result = await runner.RunInSandboxAsync(new SandboxRunRequest(
|
|
"var block = new string('x', 100000); for (int i=0; i<1000; i++) System.Console.Write(block); return " + returnExpression + ";", null, 10), CancellationToken.None);
|
|
Assert.True(result.Success, result.Error);
|
|
Assert.True(result.ConsoleOutput.Length < 32100);
|
|
Assert.Contains("truncated", result.ConsoleOutput);
|
|
Assert.Contains("truncated", result.ReturnValueJson!);
|
|
Assert.True(System.Text.Encoding.UTF8.GetByteCount(result.ReturnValueJson!) < 32000);
|
|
}
|
|
|
|
/// <summary>Verifies that concurrent large writes retain only the configured character budget.</summary>
|
|
[Fact]
|
|
public void ConcurrentRepeatedLargeWrites_RetainOnlyBudget()
|
|
{
|
|
var writer = new BoundedSandboxWriter(32000);
|
|
var block = new string('x', 100000);
|
|
Parallel.For(0, 1000, _ => writer.WriteLine(block));
|
|
Assert.Equal(32000, writer.RetainedCharacters);
|
|
Assert.True(writer.DroppedCharacters >= 99968000);
|
|
Assert.True(writer.ToString().Length < 32100);
|
|
Assert.Contains("truncated", writer.ToString());
|
|
}
|
|
}
|