This commit is contained in:
1 parent
5d549ff66a
commit
e831d0dfe0
28 files changed
+1026
-286
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user