Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-18861

[rhel-9.4.0] Custom cockpit plugins break with new release 300.1-1.el9_3

    • Icon: Bug Bug
    • Resolution: Done-Errata
    • Icon: Undefined Undefined
    • rhel-9.4
    • rhel-9.3.0
    • cockpit
    • None
    • cockpit-307-1.el9
    • Yes
    • Important
    • ZStream, Regression
    • rhel-sst-cockpit
    • ssg_front_door
    • None
    • False
    • Hide

      None

      Show
      None
    • None
    • Red Hat Enterprise Linux
    • None
    • Approved Blocker
    • None

      What were you trying to do that didn't work?

      There was a apparently a re-implementation of cockpit-bridge between 286.2-1.el9_2 and 300.1-1.el9_3: the new implementation is now in Python instead of C.
      This re-implementation broke the support of "minified" files:
      with older release, "foo.min.js.gz" or "foo.min.js" was served when cockpit UI was requesting "foo.js".
      It's not the case anymore because the code in /usr/lib/python3.9/site-packages/cockpit/packages.py doesn't implement this mapping:

      143 class Package:
      144     PO_JS_RE: ClassVar[Pattern] = re.compile(r'po\.([^.]+)\.js(\.gz)?')
       :
      162     def ensure_scanned(self) -> None:
       :
      180             po_match = Package.PO_JS_RE.fullmatch(name)
      181             if po_match:
      182                 locale = po_match.group(1)
      183                 # Accept-Language is case-insensitive and uses '-' to separate variants
      184                 lower_locale = locale.lower().replace('_', '-')
      185                 self.translations[lower_locale] = name
      186             else:
      187                 basename = name[:-3] if name.endswith('.gz') else name
      188                 self.files[basename] = name
       :
      

      Here above on line 187 there is support for ".gz" but not ".min" sub-extension.

      Digging into this, I'm proposing the attached generic code ("cockpit_packages.py"), handling both ".gz" and ".min" sub-extension more wisely.
      Note that it's not sufficient to just strip ".min" to get the base name, because potentially the cockpit UI can reference different names, for example:

      • "foo.js" requested by cockpit UI should be served as "foo.js.gz", but also "foo.min.js.gz" or "foo.min.js" if any of those exist
      • "foo.min.js" requested by cockpit UI should be served as "foo.min.js.gz" if file exists, or "foo.min.js" otherwise

      If just stripping ".min" from the file name, then requesting "foo.min.js" would fail.
      See also section Reproducer for ".min" as requested file for additional details.

      Please provide the package NVR for which bug is seen:

      cockpit-300.1-1.el9_3.x86_64

      How reproducible:

      Always

      Steps to reproduce

      1. Create a custom plugin based on "pinger" (https://raw.githubusercontent.com/cockpit-project/cockpit/master/examples/pinger/pinger.js)
          # mkdir -p /usr/local/share/cockpit/pinger
          # cd /usr/local/share/cockpit/pinger
          # curl -O https://raw.githubusercontent.com/cockpit-project/cockpit/master/examples/pinger/manifest.json
          # curl -O https://raw.githubusercontent.com/cockpit-project/cockpit/master/examples/pinger/ping.html
          # curl -O https://raw.githubusercontent.com/cockpit-project/cockpit/master/examples/pinger/pinger.js
          
      2. Compress "pinger.js" into "pinger.js.gz" then rename it to "pinger.min.js.gz"
          # gzip pinger.js
          # mv pinger.js.gz pinger.min.js.gz
          
      3. Restart cockpit.service

      Expected results

      "pinger.js" requested by cockpit UI loads

      Actual results

      "pinger.js" fails to load


      Reproducer for ".min" as requested file

      1. Create a custom module that will hold more custom files
          # mkdir -p /usr/local/share/cockpit/custom
          # cd /usr/local/share/cockpit/custom
          # cat > /usr/local/share/cockpit/custom/manifest.json << EOF
          {
            "version": "1",
            "version-note": "custom test"
          }
          EOF
          
      2. Upload some javascript there, intentionally named with ".min" inside
          # curl -O https://code.jquery.com/jquery-3.7.1.min.js
          
      3. Edit /usr/local/share/cockpit/ping/ping.html to reference the file (line 7)
          # vim /usr/local/share/cockpit/ping/ping.html
          [...]
            3 <head>
            4     <title>Pinger</title>
            5     <meta charset="utf-8">
            6     <script src="../base1/cockpit.js"></script>
            7     <script src="../custom/jquery-3.7.1.min.js"></script>
            8 </head>
          [...]
          
      4. Restart cockpit.service

      Expected results

      "jquery-3.7.1.min.js" requested by "ping.html" loads

      Actual results

      "jquery-3.7.1.min.js" fails to load

              allison.karlitskaya Allison Karlitskaya
              rhn-support-rmetrich Renaud Métrich
              Allison Karlitskaya Allison Karlitskaya
              Jan Scotka Jan Scotka
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: