mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Add tests for new config value
This commit is contained in:
1 parent
762212747e
commit
c5841b17a0
5 files changed
+26
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in new issue
Block a user