bneradt commented on code in PR #13807:
URL: https://github.com/apache/trafficserver/pull/13807#discussion_r4482904157


##########
plugins/experimental/jax_fingerprint/plugin.cc:
##########
@@ -27,195 +27,187 @@
 #include "header.h"
 #include "log.h"
 
-#ifdef ENABLE_JAX_METHOD_JA4
-#include "ja4/method.h"
-#endif
-#ifdef ENABLE_JAX_METHOD_JA4H
-#include "ja4h/method.h"
-#endif
-#ifdef ENABLE_JAX_METHOD_JA3
-#include "ja3/method.h"
-#endif
-
 #include <ts/apidefs.h>
 #include <ts/ts.h>
 #include <ts/remap.h>
 #include <ts/remap_version.h>
 
-#include <getopt.h>
-
-#include <cstddef>
-#include <cstdint>
 #include <cstdio>
-#include <cstring>
 #include <memory>
 #include <string>
 #include <string_view>
+#include <vector>
 #include <version>
 
 DbgCtl dbg_ctl{PLUGIN_NAME};
 
 namespace
 {
-constexpr Method const *METHODS[] = {
-#ifdef ENABLE_JAX_METHOD_JA4
-  &ja4::method,
-#endif
-#ifdef ENABLE_JAX_METHOD_JA4H
-  &ja4h::method,
-#endif
-#ifdef ENABLE_JAX_METHOD_JA3
-  &ja3::method,
-#endif
-};
-} // namespace
+bool
+prepare_config(PluginConfig &config)
+{
+  if (!config.log_filename.empty()) {
+    if (!create_log_file(config.log_filename, config.log_handle)) {
+      TSError("[%s] Failed to create log.", PLUGIN_NAME);

Review Comment:
   Done in ee9c4d663f: the error now names the log file that couldn't be 
created.



##########
tests/uranium_tests/pluginTest/jax_fingerprint/test_jax_fingerprint_invalid_config.py:
##########
@@ -0,0 +1,176 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import re
+
+import pytest
+
+from tools.uranium.services import ATSFactory, wait_for_file_lines
+
+CASES = [
+    (
+        'Reject unknown configuration keys',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4H
+      standalone: true
+      via-header: x-jax-via
+""",
+        "Unknown key 'via-header' in fingerprint entry",
+    ),
+    (
+        'Reject duplicate fingerprint settings',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4H
+      standalone: false
+      standalone: true
+""",
+        "Duplicate key 'standalone' in fingerprint entry",
+    ),
+    (
+        'Reject duplicate fingerprints lists',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4H
+      standalone: true
+  fingerprints:
+    - method: JA3
+""",
+        "Duplicate key 'fingerprints' in jax_fingerprint",
+    ),
+    (
+        'Reject empty server names',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4
+      servernames:
+        - ""
+""",
+        "Each 'servernames' entry must be a non-empty server name",
+    ),
+    (
+        'Reject servernames for request-based methods',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4H
+      standalone: true
+      servernames:
+        - abc.example
+""",
+        "'servernames' is not supported for JA4H",
+    ),
+    (
+        'Reject a method listed twice for one registry',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA4
+      standalone: true
+      header: x-ja4-a
+    - method: JA4
+      standalone: true
+      header: x-ja4-b
+      export: jax_fingerprint
+""",
+        "method JA4 is listed more than once for registry 'jax_fingerprint'",
+    ),
+    (
+        'Reject a log_field listed twice',
+        """
+jax_fingerprint:
+  fingerprints:
+    - method: JA3
+      log_field: jaxfp
+    - method: JA4
+      log_field: jaxfp
+""",
+        "log_field 'jaxfp' is listed more than once",
+    ),
+]
+
+
[email protected]("name,config,expected_error", CASES, ids=[case[0] for 
case in CASES])
+def test_jax_fingerprint_invalid_config(ats_factory: ATSFactory, name: str, 
config: str, expected_error: str) -> None:
+    """Reject ineffective configuration without crashing the proxy.
+
+    :param ats_factory: Factory owning the proxy.
+    :param name: Description of the invalid input.
+    :param config: Invalid YAML content, including duplicate keys when 
relevant.
+    :param expected_error: Required diagnostic regular expression.
+    """
+    ats = ats_factory.create("ts", enable_cache=False)
+    if not ats.plugin_exists("jax_fingerprint.so"):
+        pytest.skip("jax_fingerprint.so is required")
+    ats.write_config_file("jax_fingerprint.yaml", config)
+    ats.plugin_config.add_line("jax_fingerprint.so jax_fingerprint.yaml")
+    failed = r"Failed to load configuration from .*jax_fingerprint\.yaml"
+    context_error = (
+        "'jax_fingerprint' must be a map containing 'fingerprints'"
+        if name == "Reject duplicate fingerprints lists" else "invalid 
fingerprint entry at line 4")
+    for expression in (expected_error, failed, 
re.escape(f"{ats.config_directory / 'jax_fingerprint.yaml'}: {context_error}")):

Review Comment:
   Done in ee9c4d663f: the allowed context error now matches `invalid 
fingerprint entry at line \d+` instead of a fixed line number.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to