feat(license): implement Hardware-ID v2, multi-platform Linux support, StateStore LLS2 hardening, and AI Agent docs
This commit is contained in:
@@ -8,4 +8,8 @@
|
||||
<AppName>Deploymentcenter Test Suite</AppName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Deploymentcenter.Client\Deploymentcenter.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Deploymentcenter.Client;
|
||||
|
||||
namespace Deploymentcenter.TestClient;
|
||||
|
||||
@@ -17,6 +19,13 @@ class Program
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
await HandleCliArgsAsync(args);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine("=================================================");
|
||||
Console.WriteLine(" 🚀 Deploymentcenter Unified Client Test Suite ");
|
||||
@@ -24,6 +33,8 @@ class Program
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($" Server Base URL: {BaseUrl}\n");
|
||||
|
||||
await TestHardwareIdV2ModuleAsync();
|
||||
await TestStateStoreHardeningAsync();
|
||||
await TestLicenseModuleAsync();
|
||||
await TestWatchdogModuleAsync();
|
||||
await TestUpdateServiceModuleAsync();
|
||||
@@ -33,42 +44,176 @@ class Program
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private static async Task TestLicenseModuleAsync()
|
||||
private static async Task HandleCliArgsAsync(string[] args)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("1. Teste Module: Lizenzen (License Validation)...");
|
||||
Console.ResetColor();
|
||||
string cmd = args[0].ToLowerInvariant();
|
||||
|
||||
try
|
||||
if (cmd == "--license-status")
|
||||
{
|
||||
var payload = new
|
||||
{
|
||||
product = "myapp",
|
||||
license_key = "LLAB1-98A72-B3C4D-5E6F7-89012",
|
||||
hardware_id = "HWID-TEST-CLI-CSHARP-01",
|
||||
nonce = Guid.NewGuid().ToString("N"),
|
||||
hostname = Environment.MachineName,
|
||||
app_version = "1.0.0"
|
||||
};
|
||||
var hwInfo = HardwareId.GetHardwareId("myapp");
|
||||
string storageDir = LicenseConfig.GetStorageDirectory("myapp");
|
||||
var cache = StateStore.Load("myapp", hwInfo.HardwareId);
|
||||
|
||||
string json = JsonSerializer.Serialize(payload);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine("=================================================");
|
||||
Console.WriteLine(" 🔑 Deploymentcenter Lizenz & HWID Status ");
|
||||
Console.WriteLine("=================================================");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($" Platform: {hwInfo.Platform.ToUpperInvariant()}");
|
||||
Console.WriteLine($" HWID v2: {hwInfo.HardwareId}");
|
||||
Console.WriteLine($" HWID Source: {hwInfo.HwidSource}");
|
||||
Console.WriteLine($" Legacy HWID (v1): {hwInfo.LegacyHardwareId}");
|
||||
Console.WriteLine($" Storage Directory:{storageDir}");
|
||||
Console.WriteLine($" Local Cache: {(cache != null ? $"VALID (Status: {cache.Status}, Schema: {cache.SchemaVersion})" : "NONE / MISSING")}");
|
||||
return;
|
||||
}
|
||||
|
||||
HttpResponseMessage response = await Client.PostAsync($"{BaseUrl}/api/license/v1/validate", content);
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
if (cmd == "--license-deactivate")
|
||||
{
|
||||
string key = args.Length > 1 ? args[1] : "LLAB1-98A72-B3C4D-5E6F7-89012";
|
||||
Console.WriteLine($"Deaktiviere Lizenz '{key}' für diesen Host...");
|
||||
var licClient = new LicenseClient(Client);
|
||||
bool success = await licClient.DeactivateAsync("myapp", key, BaseUrl, "dc_shared_master_secret");
|
||||
|
||||
Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}");
|
||||
Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}");
|
||||
|
||||
if (response.IsSuccessStatusCode && responseBody.Contains("\"status\": \"valid\""))
|
||||
if (success)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(" ✔ Lizenzen Modul Test: GÜLTIG!");
|
||||
Console.WriteLine("✔ Lizenz-Aktivierung erfolgreich am Server aufgehoben!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(" ✖ Lizenzen Modul Test: Fehler oder Ungültig!");
|
||||
Console.WriteLine("✖ Fehler bei der Lizenz-Deaktivierung.");
|
||||
}
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd == "--license-set-key")
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Fehler: Bitte Lizenzschlüssel angeben. Beispiel: --license-set-key LLAB1-XXXXX");
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
string key = args[1].Trim();
|
||||
Console.WriteLine($"Prüfe neuen Lizenzschlüssel '{key}'...");
|
||||
var licClient = new LicenseClient(Client);
|
||||
var res = await licClient.ValidateAsync("myapp", key, BaseUrl);
|
||||
if (res.IsValid)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine($"✔ Lizenz '{key}' erfolgreich aktiviert! Status: {res.Status}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"✖ Lizenzprüfung fehlgeschlagen: {res.Message} (Status: {res.Status})");
|
||||
}
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Unbekanntes Argument: {args[0]}");
|
||||
Console.WriteLine("Verfügbare Befehle:");
|
||||
Console.WriteLine(" --license-status");
|
||||
Console.WriteLine(" --license-deactivate [KEY]");
|
||||
Console.WriteLine(" --license-set-key <KEY>");
|
||||
}
|
||||
|
||||
private static Task TestHardwareIdV2ModuleAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("1. Teste Modul: HardwareId v2 Berechnungen & Quellenerkennung...");
|
||||
Console.ResetColor();
|
||||
|
||||
var hwInfo = HardwareId.GetHardwareId("myapp");
|
||||
Console.WriteLine($" Platform: {hwInfo.Platform}");
|
||||
Console.WriteLine($" Hardware ID v2: {hwInfo.HardwareId}");
|
||||
Console.WriteLine($" HWID Source: {hwInfo.HwidSource}");
|
||||
Console.WriteLine($" Legacy HWID v1: {hwInfo.LegacyHardwareId}");
|
||||
|
||||
if (hwInfo.HardwareId.StartsWith("2:") && hwInfo.HardwareId.Length == 70)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(" ✔ Hardware-ID v2 Format validiert! (2:<plat>:<64 hex>)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(" ✖ Fehlerhaftes Hardware-ID v2 Format!");
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.WriteLine();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static Task TestStateStoreHardeningAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("2. Teste Modul: StateStore LLS2 AES-GCM Verschlüsselung & Integrität...");
|
||||
Console.ResetColor();
|
||||
|
||||
string slug = "test_app_hardening";
|
||||
var hwInfo = HardwareId.GetHardwareId(slug);
|
||||
|
||||
var testCache = new LocalCacheData
|
||||
{
|
||||
SchemaVersion = 2,
|
||||
ProductSlug = slug,
|
||||
LicenseKey = "LLAB-TEST-12345",
|
||||
HardwareId = hwInfo.HardwareId,
|
||||
Status = "valid",
|
||||
IssuedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
||||
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds(),
|
||||
MaxSeenTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
||||
Checksum = hwInfo.HardwareId
|
||||
};
|
||||
|
||||
bool saved = StateStore.Save(slug, hwInfo.HardwareId, testCache);
|
||||
var loaded = StateStore.Load(slug, hwInfo.HardwareId);
|
||||
|
||||
if (saved && loaded != null && loaded.Status == "valid" && loaded.SchemaVersion == 2)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(" ✔ StateStore LLS2 AES-GCM Speicher & Entschlüsselung OK!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(" ✖ Fehler beim StateStore Test!");
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.WriteLine();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task TestLicenseModuleAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("3. Teste Modul: Lizenzen (Online Validation & v1 Migration)...");
|
||||
Console.ResetColor();
|
||||
|
||||
try
|
||||
{
|
||||
var licClient = new LicenseClient(Client);
|
||||
var result = await licClient.ValidateAsync("myapp", "LLAB1-98A72-B3C4D-5E6F7-89012", BaseUrl);
|
||||
|
||||
Console.WriteLine($" Status: {result.Status}");
|
||||
Console.WriteLine($" Hardware ID: {result.HardwareId}");
|
||||
Console.WriteLine($" Message: {result.Message}");
|
||||
|
||||
if (result.IsValid)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(" ✔ License Validation Server Test: ERFOLGREICH!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($" ✖ License Validation Server Test: {result.Message}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -83,7 +228,7 @@ class Program
|
||||
private static async Task TestWatchdogModuleAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("2. Teste Module: Watchdog (Heartbeat Ping)...");
|
||||
Console.WriteLine("4. Teste Modul: Watchdog (Heartbeat Ping)...");
|
||||
Console.ResetColor();
|
||||
|
||||
try
|
||||
@@ -97,7 +242,7 @@ class Program
|
||||
message = "C# Client Test Suite running smoothly",
|
||||
interval = 60,
|
||||
group = "TestRunner",
|
||||
os = Environment.OSVersion.ToString()
|
||||
os = OperatingSystemHelpers.GetPlatformCode()
|
||||
};
|
||||
|
||||
string json = JsonSerializer.Serialize(payload);
|
||||
@@ -113,7 +258,6 @@ class Program
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}");
|
||||
Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -138,7 +282,7 @@ class Program
|
||||
private static async Task TestUpdateServiceModuleAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("3. Teste Module: UpdateService (Release Check)...");
|
||||
Console.WriteLine("5. Teste Modul: UpdateService (Release Check)...");
|
||||
Console.ResetColor();
|
||||
|
||||
try
|
||||
@@ -147,7 +291,6 @@ class Program
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}");
|
||||
Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user