39 lines
2.1 KiB
C#
39 lines
2.1 KiB
C#
using Xunit;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Sql.IntegrationTests;
|
|
|
|
/// <summary>Tests local blackhole identity validation without Docker or SQL.</summary>
|
|
[Trait("Category", "Unit")]
|
|
[Trait("Feature", "GrpcData"), Trait("Phase", "P12")]
|
|
public sealed class OwnedBlackholeControlGuardTests
|
|
{
|
|
/// <summary>Passes exact resource identity as arguments, without a shell.</summary>
|
|
[Fact]
|
|
public void Owned_control_uses_an_exact_id_and_argument_list()
|
|
{
|
|
var script = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "local_fixtures.py"));
|
|
var environment = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "owned environment.json"));
|
|
var identity = new string('a', 64);
|
|
var command = SqlBlackholeTimeoutTests.CreateOwnedControlStartInfo("pause", script, environment, "run-a", identity, "127.0.0.1,34567");
|
|
Assert.Equal("python3", command.FileName);
|
|
Assert.False(command.UseShellExecute);
|
|
Assert.Contains(identity, command.ArgumentList);
|
|
Assert.Contains(environment, command.ArgumentList);
|
|
Assert.DoesNotContain("otopcua-sql-blackhole", command.ArgumentList);
|
|
}
|
|
|
|
/// <summary>Rejects names, injected verbs and unsafe owners before any process is launched.</summary>
|
|
[Theory]
|
|
[InlineData("pause", "run-a", "otopcua-sql-blackhole")]
|
|
[InlineData("pause; docker rm", "run-a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
|
|
[InlineData("pause", "../foreign", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
|
|
[InlineData("pause", "", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
|
|
public void Invalid_control_metadata_is_rejected(string verb, string owner, string identity)
|
|
{
|
|
var script = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "local_fixtures.py"));
|
|
var environment = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "owned.json"));
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
SqlBlackholeTimeoutTests.CreateOwnedControlStartInfo(verb, script, environment, owner, identity, "127.0.0.1,34567"));
|
|
}
|
|
}
|