-
Notifications
You must be signed in to change notification settings - Fork 55
Add sshdconfig match to export #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveL-MSFT
merged 12 commits into
PowerShell:main
from
tgauth:add-sshdconfig-match-to-export
Jan 8, 2026
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93b5f8a
make get actually ignore input properties
tgauth 95309da
update gramar for empty line and comment edge cases
tgauth cc4eb41
add test for Include warning
tgauth ed320ad
enable sshdconfig tests for other platforms
tgauth 44e24eb
cleanup grammar changes
tgauth 3629e6e
fix grammar regression
tgauth b435362
Update resources/sshdconfig/tests/sshdconfig.get.tests.ps1
tgauth f780fd0
simplify grammar and add additional tests
tgauth 75fdd6a
Merge branch 'add-sshdconfig-match-to-export' of https://github.com/t…
tgauth 3a41472
rename var for clarity
tgauth 58d41d8
further simplify grammar
tgauth 78e6cad
fix typo
tgauth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| BeforeDiscovery { | ||
| if ($IsWindows) { | ||
| $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | ||
| $principal = [System.Security.Principal.WindowsPrincipal]::new($identity) | ||
| $isElevated = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) | ||
| } | ||
| else { | ||
| $isElevated = (id -u) -eq 0 | ||
| } | ||
|
|
||
| $sshdExists = ($null -ne (Get-Command sshd -CommandType Application -ErrorAction Ignore)) | ||
| $skipTest = !$isElevated -or !$sshdExists | ||
| } | ||
|
|
||
|
|
||
| Describe 'sshd_config Get and Export Tests' -Skip:($skipTest) { | ||
| BeforeAll { | ||
| $TestConfigPath = Join-Path $TestDrive 'test_sshd_config' | ||
| "LogLevel Debug3`nPasswordAuthentication no" | Set-Content -Path $TestConfigPath | ||
| $configWithMatch = @" | ||
| Port 2222 | ||
| PasswordAuthentication no | ||
| Match User testuser | ||
| PasswordAuthentication yes | ||
| AllowTcpForwarding no | ||
| Match Address 192.168.1.0/24 | ||
| X11Forwarding yes | ||
| MaxAuthTries 3 | ||
| "@ | ||
| $TestConfigPathWithMatch = Join-Path $TestDrive 'test_sshd_config_match' | ||
| $configWithMatch | Set-Content -Path $TestConfigPathWithMatch | ||
| $configWithInclude = @" | ||
| Port 3333 | ||
| Include /etc/ssh/sshd_config.d/*.conf | ||
| PasswordAuthentication no | ||
| "@ | ||
| $TestConfigPathWithInclude = Join-Path $TestDrive 'test_sshd_config_include' | ||
| $configWithInclude | Set-Content -Path $TestConfigPathWithInclude | ||
| } | ||
|
|
||
| AfterAll { | ||
| if (Test-Path $TestConfigPath) { | ||
| Remove-Item -Path $TestConfigPath -Force -ErrorAction SilentlyContinue | ||
| } | ||
| if (Test-Path $TestConfigPathWithMatch) { | ||
| Remove-Item -Path $TestConfigPathWithMatch -Force -ErrorAction SilentlyContinue | ||
| } | ||
| if (Test-Path $TestConfigPathWithInclude) { | ||
| Remove-Item -Path $TestConfigPathWithInclude -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
|
||
| It '<Command> command <Description>' -TestCases @( | ||
| @{ | ||
| Command = 'get' | ||
| Description = 'ignores input filtering and returns all properties' | ||
| } | ||
| @{ | ||
| Command = 'export' | ||
| Description = 'uses input filtering and returns only specified properties' | ||
| } | ||
| ) { | ||
| param($Command, $Description) | ||
|
|
||
| $inputData = @{ | ||
| _metadata = @{ | ||
| filepath = $TestConfigPath | ||
| } | ||
| passwordAuthentication = $false | ||
| } | ConvertTo-Json | ||
|
|
||
| if ($Command -eq 'get') { | ||
| $result = sshdconfig $Command --input $inputData -s sshd-config 2>$null | ConvertFrom-Json | ||
| } | ||
| else { | ||
| $result = sshdconfig $Command --input $inputData 2>$null | ConvertFrom-Json | ||
| } | ||
|
|
||
| if ($command -eq 'get') { | ||
tgauth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Get should return all properties regardless of input | ||
| $result.LogLevel | Should -Be "Debug3" | ||
| $result.PasswordAuthentication | Should -Be $false | ||
| } | ||
| else { | ||
| # Export should return only specified properties | ||
| $result.PasswordAuthentication | Should -Be $false | ||
| $result.PSObject.Properties.Name | Should -Not -Contain "loglevel" | ||
| } | ||
| } | ||
|
|
||
| It '<Command> command returns config with match blocks' -TestCases @( | ||
| @{ Command = 'get' } | ||
| @{ Command = 'export' } | ||
| ) { | ||
| param($Command) | ||
|
|
||
| $inputData = @{ | ||
| _metadata = @{ | ||
| filepath = $TestConfigPathWithMatch | ||
| } | ||
| } | ConvertTo-Json | ||
|
|
||
| if ($Command -eq 'get') { | ||
| $result = sshdconfig $Command --input $inputData -s sshd-config 2>$null | ConvertFrom-Json | ||
| } | ||
| else { | ||
| $result = sshdconfig $Command --input $inputData 2>$null | ConvertFrom-Json | ||
| } | ||
| $result.Port | Should -Be "2222" | ||
| $result.PasswordAuthentication | Should -Be $false | ||
| $result.Match | Should -Not -BeNullOrEmpty | ||
| $result.Match.Count | Should -Be 2 | ||
| $result.Match[0].Criteria.User | Should -Be "testuser" | ||
| $result.Match[0].PasswordAuthentication | Should -Be $true | ||
| $result.Match[0].AllowTcpForwarding | Should -Be $false | ||
| $result.Match[1].Criteria.Address | Should -Be "192.168.1.0/24" | ||
| $result.Match[1].X11Forwarding | Should -Be $true | ||
| $result.Match[1].MaxAuthTries | Should -Be "3" | ||
| } | ||
|
|
||
| It '<Command> command displays warning when Include directive is present' -TestCases @( | ||
| @{ Command = 'get' } | ||
| @{ Command = 'export' } | ||
| ) { | ||
| param($Command) | ||
|
|
||
| $inputData = @{ | ||
| _metadata = @{ | ||
| filepath = $TestConfigPathWithInclude | ||
| } | ||
| } | ConvertTo-Json | ||
|
|
||
| $stderrFile = Join-Path $TestDrive "stderr_$Command.txt" | ||
| if ($Command -eq 'get') { | ||
| $result = sshdconfig $Command --input $inputData -s sshd-config 2>$stderrFile | ConvertFrom-Json | ||
| } | ||
| else { | ||
| $result = sshdconfig $Command --input $inputData 2>$stderrFile | ConvertFrom-Json | ||
| } | ||
|
|
||
| $stderr = Get-Content -Path $stderrFile -Raw -ErrorAction SilentlyContinue | ||
| $stderr | Should -BeLike "*WARN*Include directive found in sshd_config*" | ||
| Remove-Item -Path $stderrFile -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.