Add tests for new config value

This commit is contained in:
Cooldude2606 authored and Daniel committed 2024-11-21 08:46:22 -08:00
1 parent 762212747e
commit c5841b17a0
5 files changed
+26 -3

No files matched your search

+1
View File
@@ -74,6 +74,7 @@ Many thanks to the following for contributing to this release:
- Previously silent errors for controller.sendEvent now throw exceptions [#625](https://github.com/clusterio/clusterio/pull/625).
- @clusterio/controller export InstanceInfo has added factorioVersion parameter.
- Argument order for `Config.canAccess` changed to require an access mode passed as the second argument.
- Instances can now have `factorio.enable_script_commands` disabled which will throw an error when any script command is used over rcon. [#681](https://github.com/clusterio/clusterio/pull/681).
Many thanks to the following for contributing to this release:
[@CCpersonguy](https://github.com/CCpersonguy)
+2 -2
View File
@@ -18,7 +18,7 @@ const scriptCommands = [
"/cheat", "/editor",
"/command", "/c",
"/measured-command", "/mc",
"/silent-command", "/sc"
"/silent-command", "/sc",
];
const instanceRconCommandDuration = new lib.Histogram(
@@ -876,7 +876,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
this._loadedSave = saveName;
await this.server.start(saveName);
if (this.config.get("factorio.enable_save_patching")) {
if (this.config.get("factorio.enable_save_patching") && this.config.get("factorio.enable_script_commands")) {
await this.server.disableAchievements();
await this.updateInstanceData();
} else {
-1
View File
@@ -433,7 +433,6 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
"Allows achievement breaking commands to be executed over rcon. " +
"Required for Clusterio integrations and most plugins. " +
"This does not prevent players using script commands.",
restartRequired: true,
type: "boolean",
initialValue: true,
},
+22
View File
@@ -442,6 +442,10 @@ describe("Integration of Clusterio", function() {
});
describe("instance send-rcon", function() {
this.afterAll(async function() {
// Prevents cascading failure where enable_script_commands is expected to be true
await execCtl("instance config set test factorio.enable_script_commands true");
});
it("sends the command", async function() {
slowTest(this);
await execCtl("instance send-rcon test technobabble");
@@ -465,6 +469,24 @@ describe("Integration of Clusterio", function() {
}
assert(received, "InstanceSaveDetailsUpdatesEvent not sent");
});
it("should prevent execution of script commands when disabled", async function() {
slowTest(this);
await execCtl("instance send-rcon test /c");
const r1 = await getControl().send(
new lib.LogQueryRequest(false, false, [], [44], undefined, 10, "desc")
);
assert(r1.log.some(info => /\[COMMAND\]/.test(info.message)), "Command was not sent");
await execCtl("instance config set test factorio.enable_script_commands false");
assert.rejects(
execCtl("instance send-rcon test /c"),
new Error(
"Attempted to use script command while disabled. " +
"See config factorio.enable_script_commands.\nCommand: /c"
)
);
await execCtl("instance config set test factorio.enable_script_commands true");
});
});
describe("instance config set-prop", function() {
+1
View File
@@ -129,6 +129,7 @@ class MockInstance extends lib.Link {
this.mockConfigEntries = new Map([
["instance.id", 7357],
["factorio.enable_save_patching", true],
["factorio.enable_script_commands", true],
]);
this.config = {
get: (name) => {