* Add standalone Linux bootstrap foundation * Record bootstrap foundation progress * Add single-code Node enrollment * Validate bootstrap release payloads * Add managed WireGuard mesh bootstrap * Exercise repeated systemd installation in CI * Expose systemd smoke failure diagnostics * Fix bootstrap os-release variable collision * Create policy helper directory during install * Capture systemd smoke healthcheck errors * Report Control listener diagnostics in CI * Capture stalled Control process diagnostics * Set service working directories * Run protected CA healthcheck as root * Add local Mesh emergency recovery * Add multi-architecture Linux system matrix * Add provisioning job control plane * Stabilize Debian systemd smoke files * Add node-scoped provisioning job channel * Add provisioning progress state machine * Reconcile expired provisioning jobs * Add provisioning rollback workflow * Add redacted provisioning event history * Add restricted provisioning preflight helper * Persist typed provisioning preflight facts * Add preflight desired state drift detection * Define strict base install schema catalog * Add safe base install plan generation * Add pre-confirmation base install plans * Test base install plan API flow * Authorize confirmed provisioning execution --------- Co-authored-by: Ochenstarik <ochenstarik@inbox.ru>
91 lines
3.5 KiB
C#
91 lines
3.5 KiB
C#
using System.Text.Json;
|
|
using ServerMonitorManager.Core;
|
|
using ServerMonitorManager.Provisioning.Helper;
|
|
using Xunit;
|
|
|
|
namespace ServerMonitorManager.Control.Tests;
|
|
|
|
public sealed class ProvisioningHelperTests
|
|
{
|
|
[Fact]
|
|
public void HelperRejectsEveryActionOutsideFixedAllowlist()
|
|
{
|
|
using var document = JsonDocument.Parse("{}");
|
|
var response = ProvisioningHelperServer.Execute(new ProvisioningHelperRequest(
|
|
"1", new string('a', 32), "shell", 1,
|
|
ProvisioningActionCatalog.PreflightModuleHash, document.RootElement.Clone()));
|
|
|
|
Assert.False(response.Success);
|
|
Assert.Equal("action.denied", response.Code);
|
|
Assert.Null(response.Preflight);
|
|
}
|
|
|
|
[Fact]
|
|
public void HelperAcceptsOnlyEmptyPreflightSchemaOne()
|
|
{
|
|
if (!OperatingSystem.IsLinux())
|
|
{
|
|
return;
|
|
}
|
|
|
|
using var document = JsonDocument.Parse("{}");
|
|
var response = ProvisioningHelperServer.Execute(new ProvisioningHelperRequest(
|
|
"1", new string('b', 32), "preflight", 1,
|
|
ProvisioningActionCatalog.PreflightModuleHash, document.RootElement.Clone()));
|
|
|
|
Assert.True(response.Success);
|
|
Assert.Equal("preflight.completed", response.Code);
|
|
Assert.NotNull(response.Preflight);
|
|
Assert.NotEmpty(response.Preflight.OperatingSystem);
|
|
Assert.NotEmpty(response.Preflight.Architecture);
|
|
}
|
|
|
|
[Fact]
|
|
public void HelperContractRejectsUnknownJsonMembers()
|
|
{
|
|
const string json = """
|
|
{"protocolVersion":"1","jobId":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
"actionType":"preflight","schemaVersion":1,
|
|
"moduleHash":"2dc48fb4528a291221954fc2dd3478d431b66fe34228f29684ce1648dbe2f32b",
|
|
"parameters":{},"command":"id"}
|
|
""";
|
|
|
|
Assert.Throws<JsonException>(() =>
|
|
JsonSerializer.Deserialize(json, SmmJsonContext.Default.ProvisioningHelperRequest));
|
|
}
|
|
|
|
[Fact]
|
|
public void BaseInstallSchemaRejectsCommandText()
|
|
{
|
|
const string json = """
|
|
{"timezone":"UTC","locale":"en_US.UTF-8","aptUpdate":true,"aptUpgrade":false,
|
|
"packageCatalogVersion":1,"packageGroupIds":["core"],"swapMode":"disabled",
|
|
"swapSizeMiB":null,"vmSwappiness":60,"enableUnattendedUpgrades":true,
|
|
"rebootPolicy":"never","command":"id"}
|
|
""";
|
|
|
|
Assert.Throws<JsonException>(() =>
|
|
JsonSerializer.Deserialize(json, SmmJsonContext.Default.SystemBaseInstallParameters));
|
|
}
|
|
|
|
[Fact]
|
|
public void HelperBuildsDeterministicBaseInstallPlanWithoutCommands()
|
|
{
|
|
var parameters = new SystemBaseInstallParameters(
|
|
"UTC", "en_US.UTF-8", true, false, 1,
|
|
["development", "core"], "disabled", null, 60, true, "never");
|
|
var json = JsonSerializer.SerializeToElement(
|
|
parameters, SmmJsonContext.Default.SystemBaseInstallParameters);
|
|
var response = ProvisioningHelperServer.Execute(new ProvisioningHelperRequest(
|
|
"1", new string('c', 32), "system.base-install", 1,
|
|
ProvisioningActionCatalog.SystemBaseInstallModuleHash, json));
|
|
|
|
Assert.True(response.Success);
|
|
Assert.Equal("system.base-install.plan-ready", response.Code);
|
|
Assert.Null(response.Preflight);
|
|
Assert.Equal(
|
|
["ca-certificates", "curl", "jq", "build-essential", "git"],
|
|
response.BaseInstallPlan!.Packages);
|
|
Assert.Equal("never", response.BaseInstallPlan.RebootPolicy);
|
|
}
|
|
}
|