Skip to content

Commit de0bcae

Browse files
committed
more cleanup
1 parent fbbad1f commit de0bcae

File tree

5 files changed

+22
-53
lines changed

5 files changed

+22
-53
lines changed

test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ public void KeyboardInteractive_PasswordExpired()
352352
// Password expired, retype new password
353353
authenticationPrompt.Response = Users.Regular.Password;
354354
break;
355+
default:
356+
break;
355357
}
356358

357359
authenticationPromptCount++;

test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFrameworks>net48;net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsTestProject>true</IsTestProject>
7-
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>
87
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
98
</PropertyGroup>
109

@@ -18,7 +17,6 @@
1817
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1918
<PrivateAssets>all</PrivateAssets>
2019
</PackageReference>
21-
<PackageReference Include="Microsoft.Extensions.Logging" />
2220
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
2321
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2422
<PackageReference Include="MSTest.TestAdapter" />

test/Renci.SshNet.IntegrationTests/SshTests.cs

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.ComponentModel;
22
using System.Net;
3+
#if NETFRAMEWORK
4+
using System.Net.Http;
5+
#endif
36
using System.Net.Sockets;
47

58
using Renci.SshNet.Common;
@@ -537,29 +540,16 @@ public void Ssh_LocalPortForwardingCloseChannels()
537540

538541
try
539542
{
540-
var httpRequest = (HttpWebRequest)WebRequest.Create("http://" + localEndPoint);
541-
httpRequest.Host = hostName;
542-
httpRequest.Method = "GET";
543-
httpRequest.AllowAutoRedirect = false;
544-
545-
try
546-
{
547-
using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
548-
{
549-
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
550-
}
551-
}
552-
catch (WebException ex)
543+
using HttpClientHandler handler = new()
553544
{
554-
Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status);
555-
Assert.IsNotNull(ex.Response);
545+
AllowAutoRedirect = false
546+
};
556547

557-
using (var httpResponse = ex.Response as HttpWebResponse)
558-
{
559-
Assert.IsNotNull(httpResponse);
560-
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
561-
}
562-
}
548+
using HttpClient httpClient = new(handler);
549+
550+
using HttpResponseMessage httpResponse = httpClient.GetAsync("http://" + localEndPoint).Result;
551+
552+
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
563553
}
564554
finally
565555
{
@@ -606,30 +596,16 @@ public void Ssh_LocalPortForwarding()
606596

607597
try
608598
{
609-
var httpRequest = (HttpWebRequest)WebRequest.Create("http://" + localEndPoint);
610-
httpRequest.Host = hostName;
611-
httpRequest.Method = "GET";
612-
httpRequest.Accept = "text/html";
613-
httpRequest.AllowAutoRedirect = false;
614-
615-
try
616-
{
617-
using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
618-
{
619-
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
620-
}
621-
}
622-
catch (WebException ex)
599+
using HttpClientHandler handler = new()
623600
{
624-
Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status);
625-
Assert.IsNotNull(ex.Response);
601+
AllowAutoRedirect = false
602+
};
626603

627-
using (var httpResponse = ex.Response as HttpWebResponse)
628-
{
629-
Assert.IsNotNull(httpResponse);
630-
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
631-
}
632-
}
604+
using HttpClient httpClient = new(handler);
605+
606+
using HttpResponseMessage httpResponse = httpClient.GetAsync("http://" + localEndPoint).Result;
607+
608+
Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode);
633609
}
634610
finally
635611
{

test/Renci.SshNet.IntegrationTests/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected static void FillStream(Stream stream, int size)
3030

3131
protected static string CreateHash(Stream stream)
3232
{
33-
MD5 md5 = new MD5CryptoServiceProvider();
33+
using MD5 md5 = MD5.Create();
3434
var hash = md5.ComputeHash(stream);
3535
return Encoding.ASCII.GetString(hash);
3636
}

test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045</NoWarn>
87
</PropertyGroup>
98

10-
<ItemGroup>
11-
<Compile Remove="Properties\**" />
12-
<EmbeddedResource Remove="Properties\**" />
13-
<None Remove="Properties\**" />
14-
</ItemGroup>
15-
169
</Project>

0 commit comments

Comments
 (0)