mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-13 07:36:52 +00:00
fix: remediate findings F045, F047, F048, F064, F070, F071, F076-F079
Phase 1 — Trivial fixes: - F071: Add Uri.EscapeDataString to GetPveTemplateCmdlet node path - F077: Add ValidateRange(100, 999999999) to GetPveTaskListCmdlet.VmId - F076: Create .github/dependabot.yml (nuget + github-actions, weekly) - F079: Fix unit-tests.yml dotnet SDK from 9.0.x to 10.0.x - F048: Mark wont_fix — sync-over-async accepted for PS 5.1 compat Phase 2 — Framework targeting (D009 compliance): - F047: Reduce publishable csproj to netstandard2.0 only, remove all #if NET48/NETSTANDARD2_0 conditionals from PveHttpClient.cs, restructure build.yml for netstandard2.0 publish + net10.0/net48 tests - F064: Resolved by F047 — SMA 7.5.0 ItemGroup removed with net10.0 TFM - F070: Add PS 5.1 smoke-test job to publish.yml (windows-latest) Phase 3 — IPveHttpClient interface extraction (F045): - Extract IPveHttpClient interface from PveHttpClient - Add constructor injection to all 14 service classes - Services use injected client when available, create+dispose when not Phase 4 — Service unit tests (F078): - 196 new xUnit tests across 10 service test files - All services tested via Moq-mocked IPveHttpClient - Total test count: 382 (was 186) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,10 +11,8 @@ using Newtonsoft.Json.Linq;
|
||||
using PSProxmoxVE.Core.Authentication;
|
||||
using PSProxmoxVE.Core.Exceptions;
|
||||
|
||||
#if NET48 || NETSTANDARD2_0
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
|
||||
namespace PSProxmoxVE.Core.Client
|
||||
{
|
||||
@@ -22,7 +20,7 @@ namespace PSProxmoxVE.Core.Client
|
||||
/// Low-level HTTP client for communicating with the Proxmox VE API.
|
||||
/// Handles authentication headers, error parsing, and the ISO upload workaround.
|
||||
/// </summary>
|
||||
public class PveHttpClient : IDisposable
|
||||
public class PveHttpClient : IPveHttpClient
|
||||
{
|
||||
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type
|
||||
private readonly PveSession? _session;
|
||||
@@ -44,7 +42,6 @@ namespace PSProxmoxVE.Core.Client
|
||||
_session = session ?? throw new ArgumentNullException(nameof(session));
|
||||
_baseUrl = session.BaseUrl;
|
||||
|
||||
#if NET48 || NETSTANDARD2_0
|
||||
var handler = new HttpClientHandler();
|
||||
if (session.SkipCertificateCheck)
|
||||
{
|
||||
@@ -52,21 +49,6 @@ namespace PSProxmoxVE.Core.Client
|
||||
(HttpRequestMessage _, X509Certificate2 _, X509Chain _, SslPolicyErrors _) => true;
|
||||
}
|
||||
_httpClient = new HttpClient(handler);
|
||||
#else
|
||||
if (session.SkipCertificateCheck)
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback =
|
||||
(_, _, _, _) => true
|
||||
};
|
||||
_httpClient = new HttpClient(handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
}
|
||||
#endif
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
@@ -84,7 +66,6 @@ namespace PSProxmoxVE.Core.Client
|
||||
_session = null;
|
||||
_baseUrl = $"https://{hostname}:{port}";
|
||||
|
||||
#if NET48 || NETSTANDARD2_0
|
||||
var handler = new HttpClientHandler();
|
||||
if (skipCertificateCheck)
|
||||
{
|
||||
@@ -92,21 +73,6 @@ namespace PSProxmoxVE.Core.Client
|
||||
(HttpRequestMessage _, X509Certificate2 _, X509Chain _, SslPolicyErrors _) => true;
|
||||
}
|
||||
_httpClient = new HttpClient(handler);
|
||||
#else
|
||||
if (skipCertificateCheck)
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback =
|
||||
(_, _, _, _) => true
|
||||
};
|
||||
_httpClient = new HttpClient(handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
}
|
||||
#endif
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
@@ -295,11 +261,7 @@ namespace PSProxmoxVE.Core.Client
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if NET48 || NETSTANDARD2_0
|
||||
fileStream.Dispose();
|
||||
#else
|
||||
await fileStream.DisposeAsync().ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,12 +359,8 @@ namespace PSProxmoxVE.Core.Client
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var bytes = new byte[32];
|
||||
#if NET48 || NETSTANDARD2_0
|
||||
using (var rng = RandomNumberGenerator.Create())
|
||||
rng.GetBytes(bytes);
|
||||
#else
|
||||
RandomNumberGenerator.Fill(bytes);
|
||||
#endif
|
||||
var sb = new StringBuilder(32);
|
||||
for (int i = 0; i < 32; i++)
|
||||
sb.Append(chars[bytes[i] % chars.Length]);
|
||||
|
||||
Reference in New Issue
Block a user