From 25776abf61b7a0f6c79d9f297e413b307946ac7f Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 23 Aug 2023 18:04:22 +0100 Subject: [PATCH] Fix address rules reading the wrong config key Should be max_websocket_message, not just websocket_message. Also add some additional validation to address rules, to check no unrecognised keys are present. Closes #1566. --- .../shared/config/AddressRuleConfig.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java b/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java index c063569a7..5ee6ce442 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java @@ -26,6 +26,10 @@ class AddressRuleConfig { private static final AddressRule REJECT_ALL = AddressRule.parse("*", OptionalInt.empty(), Action.DENY.toPartial()); + private static final Set knownKeys = Set.of( + "host", "action", "max_download", "max_upload", "max_websocket_message", "use_proxy" + ); + public static List defaultRules() { return List.of( makeRule(config -> { @@ -88,9 +92,20 @@ class AddressRuleConfig { var port = unboxOptInt(get(builder, "port", Number.class)); var maxUpload = unboxOptLong(get(builder, "max_upload", Number.class).map(Number::longValue)); var maxDownload = unboxOptLong(get(builder, "max_download", Number.class).map(Number::longValue)); - var websocketMessage = unboxOptInt(get(builder, "websocket_message", Number.class).map(Number::intValue)); + var websocketMessage = unboxOptInt( + get(builder, "max_websocket_message", Number.class) + // Fallback to (incorrect) websocket_message option. + .or(() -> get(builder, "websocket_message", Number.class)) + .map(Number::intValue) + ); var useProxy = get(builder, "use_proxy", Boolean.class); + // Find unknown keys and warn about them. + var unknownKeys = builder.entrySet().stream().map(UnmodifiableConfig.Entry::getKey).filter(x -> !knownKeys.contains(x)).toList(); + if (!unknownKeys.isEmpty()) { + LOG.warn("Unknown config {} {} in address rule.", unknownKeys.size() == 1 ? "option" : "options", String.join(", ", unknownKeys)); + } + var options = new PartialOptions( action, maxUpload,