Skip to content

Commit e0bb657

Browse files
authored
Add FTPS directory listing regression test (#135077)
## Summary - Add enterprise coverage for synchronous `FtpWebRequest` `ListDirectoryDetails` requests with and without TLS. - Verify that the returned listing is plaintext, contains the uploaded fixture, and completes with `FtpStatusCode.ClosingData`. - Clean up the uploaded fixture even when the listing assertion fails. - Document the additional FTPS directory-listing coverage. This directly covers the scenario reported in #134130. The product fix is already present on `main` via #123234; this PR adds coverage for the specific listing operation from the newer report. ## Testing - `./build.sh clr+libs -rc release` in the Linux enterprise test client: succeeded with 0 warnings and 0 errors. - `/repo/dotnet.sh build /t:Test /p:XunitMethodName=System.Net.Tests.FtpWebRequestStreamDisposalTest.FtpListDirectoryDetails_ReturnsPlainText`: 2 passed, 0 failed, 0 skipped. - Negative control: temporarily restored the old synchronous stream-selection expression and rebuilt `System.Net.Requests`; the non-TLS case passed while the TLS case failed in `StreamReader.ReadToEnd` with `ObjectDisposedException`. - The attached issue repro's request sequence was also verified against controlled ProFTPD: .NET 10.0.0 returned TLS ciphertext despite status 226, while .NET 11 RC1 returned the expected plaintext listing. > [!NOTE] > This pull request description was generated with GitHub Copilot.
1 parent b60e14a commit e0bb657

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎src/libraries/System.Net.Requests/tests/EnterpriseTests/FtpWebRequestStreamDisposalTest.cs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,63 @@ public async Task FtpDownload_StreamDisposal(bool useSsl)
159159
_output.WriteLine($"Cleanup failed: {ex.Message}");
160160
}
161161
}
162+
163+
[ConditionalTheory(typeof(EnterpriseTestConfiguration), nameof(EnterpriseTestConfiguration.Enabled))]
164+
[InlineData(false)]
165+
[InlineData(true)]
166+
public async Task FtpListDirectoryDetails_ReturnsPlainText(bool useSsl)
167+
{
168+
string fileName = $"test_{Guid.NewGuid()}.txt";
169+
string fileUrl = GetFtpUrl(fileName);
170+
171+
FtpWebRequest uploadRequest = (FtpWebRequest)WebRequest.Create(fileUrl);
172+
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
173+
uploadRequest.EnableSsl = useSsl;
174+
uploadRequest.Credentials = EnterpriseTestConfiguration.FtpNetworkCredentials;
175+
176+
using (Stream requestStream = await uploadRequest.GetRequestStreamAsync())
177+
{
178+
await requestStream.WriteAsync("test"u8.ToArray());
179+
}
180+
181+
using (FtpWebResponse uploadResponse = (FtpWebResponse)await uploadRequest.GetResponseAsync())
182+
{
183+
Assert.Equal(FtpStatusCode.ClosingData, uploadResponse.StatusCode);
184+
}
185+
186+
try
187+
{
188+
FtpWebRequest listRequest = (FtpWebRequest)WebRequest.Create(GetFtpUrl(string.Empty));
189+
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
190+
listRequest.EnableSsl = useSsl;
191+
listRequest.Credentials = EnterpriseTestConfiguration.FtpNetworkCredentials;
192+
193+
using (FtpWebResponse response = (FtpWebResponse)listRequest.GetResponse())
194+
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
195+
{
196+
string listing = reader.ReadToEnd();
197+
Assert.Contains(fileName, listing);
198+
Assert.Equal(FtpStatusCode.ClosingData, response.StatusCode);
199+
}
200+
}
201+
finally
202+
{
203+
try
204+
{
205+
FtpWebRequest deleteRequest = (FtpWebRequest)WebRequest.Create(fileUrl);
206+
deleteRequest.Method = WebRequestMethods.Ftp.DeleteFile;
207+
deleteRequest.EnableSsl = useSsl;
208+
deleteRequest.Credentials = EnterpriseTestConfiguration.FtpNetworkCredentials;
209+
210+
using FtpWebResponse deleteResponse = (FtpWebResponse)await deleteRequest.GetResponseAsync();
211+
Assert.Equal(FtpStatusCode.FileActionOK, deleteResponse.StatusCode);
212+
}
213+
catch (Exception ex)
214+
{
215+
_output.WriteLine($"Cleanup failed: {ex.Message}");
216+
}
217+
}
218+
}
162219
#pragma warning restore SYSLIB0014
163220
}
164221
}

‎src/libraries/System.Net.Requests/tests/EnterpriseTests/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ These tests validate FTP operations with SSL/TLS (FTPS) against a ProFTPD server
1111
The tests cover:
1212
- FTP file upload with explicit SSL/TLS
1313
- FTP file download with explicit SSL/TLS
14+
- FTP directory listing with explicit SSL/TLS
1415
- Proper SSL/TLS stream closure to prevent protocol violations

0 commit comments

Comments
 (0)