Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion resources/sshdconfig/src/repeat_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ pub struct NameValueEntry {
pub value: Option<String>,
}

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")]
Expand Down
18 changes: 18 additions & 0 deletions resources/sshdconfig/tests/sshdconfigRepeat.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Loading