-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Personal/degoswami/newflags #29154
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
Personal/degoswami/newflags #29154
Changes from all commits
e995bde
69571a4
7a7436f
2249f33
60ecbfc
91842de
0573b48
e9bb810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,3 +146,80 @@ function Test-ConnectAzSftpParameterValidation | |
| # Test certificate authentication requires both certificate and private key | ||
| Assert-Throws { Connect-AzSftp -StorageAccount "test" -CertificateFile "cert.pub" } "CertificateFile requires PrivateKeyFile" | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Test Connect-AzSftp with BufferSizeInBytes parameter | ||
| #> | ||
| function Test-ConnectAzSftpWithBufferSizeInBytes | ||
| { | ||
| $storageAccountName = Get-StorageAccountName | ||
| $resourceGroupName = Get-ResourceGroupName | ||
|
|
||
| try { | ||
| # Skip test in playback mode for now | ||
| if (IsPlayback) { | ||
| return | ||
| } | ||
|
|
||
| # Create test storage account | ||
| $storageAccount = New-TestStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName | ||
|
|
||
| # Test connection with custom buffer size (will fail in test environment but validates parameter parsing) | ||
| try { | ||
| $result = Connect-AzSftp -StorageAccount $storageAccountName -BufferSizeInBytes 524288 -SftpArg "-o", "ConnectTimeout=1" | ||
| } | ||
| catch { | ||
| # Expected to fail in test environment - this is acceptable | ||
| Write-Host "Connection failed as expected in test environment: $($_.Exception.Message)" | ||
| } | ||
|
|
||
| # Test with default buffer size (256*1024 = 262144) | ||
| try { | ||
| $result = Connect-AzSftp -StorageAccount $storageAccountName -SftpArg "-o", "ConnectTimeout=1" | ||
| } | ||
| catch { | ||
| Write-Host "Connection failed as expected in test environment: $($_.Exception.Message)" | ||
| } | ||
| } | ||
| finally { | ||
| # Cleanup | ||
| Remove-TestStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName | ||
| Remove-AzResourceGroup -Name $resourceGroupName -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Test Connect-AzSftp with StorageAccountEndpoint parameter | ||
| #> | ||
| function Test-ConnectAzSftpWithStorageAccountEndpoint | ||
| { | ||
| $storageAccountName = Get-StorageAccountName | ||
| $resourceGroupName = Get-ResourceGroupName | ||
| $customEndpoint = "blob.core.custom.endpoint.net" | ||
|
|
||
| try { | ||
| # Skip test in playback mode for now | ||
| if (IsPlayback) { | ||
| return | ||
| } | ||
|
|
||
| # Create test storage account | ||
| $storageAccount = New-TestStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName | ||
|
|
||
| # Test connection with custom storage account endpoint (will fail in test environment but validates parameter parsing) | ||
| try { | ||
| $result = Connect-AzSftp -StorageAccount $storageAccountName -StorageAccountEndpoint $customEndpoint -SftpArg "-o", "ConnectTimeout=1" | ||
| } | ||
| catch { | ||
| # Expected to fail in test environment - this is acceptable | ||
| Write-Host "Connection failed as expected in test environment: $($_.Exception.Message)" | ||
| } | ||
| } | ||
| finally { | ||
| # Cleanup | ||
| Remove-TestStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName | ||
| Remove-AzResourceGroup -Name $resourceGroupName -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
Comment on lines
150
to
225
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,5 +381,141 @@ public void AttemptConnection_WithInvalidCommand_ReturnsFalseWithError() | |
| Assert.NotNull(result.Item3); // Error message | ||
| Assert.Contains("Failed to start", result.Item3); | ||
| } | ||
|
|
||
| #region BufferSize Tests | ||
|
|
||
| [Fact] | ||
| public void BuildSftpCommand_WithDefaultBufferSize_DoesNotIncludeBufferFlag() | ||
| { | ||
| // Arrange - default buffer size is 256 * 1024 = 262144 | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22, | ||
| publicKeyFile: null, | ||
| privateKeyFile: null, | ||
| certFile: null, | ||
| sftpArgs: null, | ||
| sshClientFolder: null, | ||
| sshProxyFolder: null, | ||
| credentialsFolder: null, | ||
| yesWithoutPrompt: false, | ||
| bufferSizeBytes: 256 * 1024 // Default value | ||
| ); | ||
|
Comment on lines
+390
to
+405
|
||
|
|
||
| // Act | ||
| var command = SftpUtils.BuildSftpCommand(session); | ||
|
|
||
| // Assert - should NOT contain -B flag when using default buffer size | ||
| Assert.DoesNotContain("-B", command); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildSftpCommand_WithCustomBufferSize_IncludesBufferFlag() | ||
| { | ||
| // Arrange - custom buffer size | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22, | ||
| publicKeyFile: null, | ||
| privateKeyFile: null, | ||
| certFile: null, | ||
| sftpArgs: null, | ||
| sshClientFolder: null, | ||
| sshProxyFolder: null, | ||
| credentialsFolder: null, | ||
| yesWithoutPrompt: false, | ||
| bufferSizeBytes: 524288 // 512 KB - non-default value | ||
| ); | ||
|
|
||
| // Act | ||
| var command = SftpUtils.BuildSftpCommand(session); | ||
|
|
||
| // Assert - should contain -B flag with custom buffer size | ||
| Assert.Contains("-B", command); | ||
| Assert.Contains("524288", command); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildSftpCommand_WithSmallBufferSize_IncludesBufferFlag() | ||
| { | ||
| // Arrange - smaller buffer size | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22, | ||
| publicKeyFile: null, | ||
| privateKeyFile: null, | ||
| certFile: null, | ||
| sftpArgs: null, | ||
| sshClientFolder: null, | ||
| sshProxyFolder: null, | ||
| credentialsFolder: null, | ||
| yesWithoutPrompt: false, | ||
| bufferSizeBytes: 32768 // 32 KB | ||
| ); | ||
|
|
||
| // Act | ||
| var command = SftpUtils.BuildSftpCommand(session); | ||
|
|
||
| // Assert | ||
| Assert.Contains("-B", command); | ||
| Assert.Contains("32768", command); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SFTPSession_BufferSizeBytes_DefaultValue_Is256KB() | ||
| { | ||
| // Arrange & Act | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22 | ||
| ); | ||
|
|
||
| // Assert - default buffer size should be 256 * 1024 = 262144 | ||
| Assert.Equal(256 * 1024, session.BufferSizeBytes); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SFTPSession_BufferSizeBytes_CanBeSetViaConstructor() | ||
| { | ||
| // Arrange & Act | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22, | ||
| bufferSizeBytes: 1048576 // 1 MB | ||
| ); | ||
|
|
||
| // Assert | ||
| Assert.Equal(1048576, session.BufferSizeBytes); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SFTPSession_BufferSizeBytes_CanBeSetViaProperty() | ||
| { | ||
| // Arrange | ||
| var session = new SFTPSession( | ||
| storageAccount: "testaccount", | ||
| username: "testuser", | ||
| host: "testaccount.blob.core.windows.net", | ||
| port: 22 | ||
| ); | ||
|
|
||
| // Act | ||
| session.BufferSizeBytes = 2097152; // 2 MB | ||
|
|
||
| // Assert | ||
| Assert.Equal(2097152, session.BufferSizeBytes); | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default-value test duplicates the production constant as
256 * 1024and262144. Prefer asserting againstSftpConstants.DefaultBufferSizeBytesso tests remain correct if the default is ever adjusted, and you only have one source of truth.