Files
PCL-ISE/tests/Check-BuildCredentials.cs
T
Coldsmile_7 e831d0dfe0
Release PCL-ISE / release (push) Canceled after 0s
feat: prepare PCL-ISE 0.1.2 update test release
2026-10-27 23:57:25 +08:00

49 lines
2.6 KiB
C#

using System;
using System.IO;
using System.Reflection;
// Compile with the .NET Framework csc.exe. No UI startup or network calls.
internal static class CheckBuildCredentials {
[STAThread]
private static int Main(string[] args) {
try {
string expectedClientId = (Environment.GetEnvironmentVariable("PCL_MS_CLIENT_ID") ?? "").Trim();
string expectedApiKey = Environment.GetEnvironmentVariable("PCL_CURSEFORGE_API_KEY") ?? "";
string mode = args[1];
if (mode == "override") {
expectedClientId = "11111111-1111-4111-8111-111111111111";
expectedApiKey = "synthetic-override-only-$\"&\\";
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", expectedClientId);
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", expectedApiKey);
} else if (mode == "blank-override") {
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", " ");
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", " ");
} else if (mode == "packaged" || mode == "empty") {
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", null);
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", null);
if (mode == "empty") { expectedClientId = ""; expectedApiKey = ""; }
} else {
throw new ArgumentException("Unknown test mode");
}
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
using (Stream resource = launcher.GetManifestResourceStream("PCL.BuildCredentials.json")) {
if ((resource == null) != (mode == "empty"))
throw new InvalidDataException("Unexpected build configuration resource");
}
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
Type module = launcher.GetType("PCL.ModSecret", true);
string actualClientId = (string)module.GetField("OAuthClientId").GetValue(null);
string actualApiKey = (string)module.GetField("CurseForgeAPIKey").GetValue(null);
if (actualClientId != expectedClientId || actualApiKey != expectedApiKey)
throw new InvalidDataException("Build configuration did not match expected values");
Console.WriteLine("PASS: build configuration " + mode);
return 0;
} catch (Exception ex) {
// Never include credential values in diagnostic output.
Console.Error.WriteLine(ex.GetType().Name + ": build configuration check failed");
return 1;
}
}
}