diff --git a/resources/sshdconfig/src/repeat_keyword.rs b/resources/sshdconfig/src/repeat_keyword.rs index edf8d4cc5..e27f51c9e 100644 --- a/resources/sshdconfig/src/repeat_keyword.rs +++ b/resources/sshdconfig/src/repeat_keyword.rs @@ -78,11 +78,13 @@ pub struct NameValueEntry { pub value: Option, } +fn default_true() -> bool { true } + /// Input for name-value keyword single-entry operations (e.g., subsystem). #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct RepeatInput { /// Whether the entry should exist (true) or be removed (false) - #[serde(rename = "_exist", default)] + #[serde(rename = "_exist", default = "default_true")] pub exist: bool, /// Metadata for the operation #[serde(rename = "_metadata", skip_serializing_if = "Option::is_none")] diff --git a/resources/sshdconfig/tests/sshdconfigRepeat.tests.ps1 b/resources/sshdconfig/tests/sshdconfigRepeat.tests.ps1 index ac39caf23..8a2a34d7b 100644 --- a/resources/sshdconfig/tests/sshdconfigRepeat.tests.ps1 +++ b/resources/sshdconfig/tests/sshdconfigRepeat.tests.ps1 @@ -212,5 +212,23 @@ PasswordAuthentication yes Remove-Item -Path $stderrFile -Force -ErrorAction SilentlyContinue } + + It 'Should default to _exist=true when not specified explicitly' { + $inputConfig = @{ + _metadata = @{ + filepath = $TestConfigPath + } + subsystem = @{ + name = "testExistDefault" + value = "/path/to/subsystem" + } + } | ConvertTo-Json + + $output = sshdconfig set --input $inputConfig -s sshd-config-repeat 2>$null + $LASTEXITCODE | Should -Be 0 + # verify subsystem was added (defaulting to _exist=true) + $subsystems = Get-Content $TestConfigPath | Where-Object { $_ -match '^\s*subsystem\s+' } + $subsystems | Should -Contain "subsystem testExistDefault /path/to/subsystem" + } } }