Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Remove square brackets from ipv6 host on PostgreSQL, refactor changes from PR 310 and move options modifications to constructor #317

Open
wants to merge 2 commits into
base: 3.x-dev
Choose a base branch
from

Conversation

richard67
Copy link
Contributor

Pull Request for CMS Issue joomla/joomla-cms#43902

Alternative to #315 and #316 .

Summary of Changes

This pull request (PR) moves the adjustment of connection-specific options like e.g. host, port and socket from the connect method of the PDO and MySQLi database drivers to the constructor.

The setHostPortSocket method which was added to the base driver with PR #310 is changed to use function parameters and return the modified parameters in an array, and that method is renamed to extractHostPortSocket to reflect that change.

A new boolean parameter is added to that method to control if the square brackets around an IP v6 address in the host parameter should be kept ("MySQLi" and "MySQL (PDO)") or if they should be removed ("PostgreSQL (PDO)") in the connection parameters. The default is true to keep the square brackets. For "PosgreSQL (PDO)" it is set to false so the quare brackets are removed. This makes it possible to specify an IP v6 address together with a port number for "PostgreSQL (PDO)" in the same way as it already works for "MySQLi" and "MySQL (PDO)".

Testing Instructions

See CMS issue joomla/joomla-cms#43902 and joomla-projects/joomla-cypress#36 .

Documentation Changes Required

Don't know.

Move adjustment of connection-specific options like e.g. host, port and socket from connect method to constructor and refactor the extractHostPortSocket for that purpose and add handling of ipv6 squared brackets
@richard67
Copy link
Contributor Author

@alikon @muhme Could you test this one here? Just check if the changes from #310 are still working and if IP v6 addresses enclosed into square brackets are working. That would be much appreciated.

@muhme
Copy link

muhme commented Nov 9, 2024

Running System Tests with current 5.2-dev and JBT development branch version 2.0.18 and bash command line:

  1. Create 5.2-dev IPv6 installation with all needed patches
# joomla-cms-43968 and joomla-cms-44084 are already merged in 5.2
scripts/create 52 IPv6 database-310 database-317 joomla-cypress-33 joomla-cypress-36
  1. Preparing tests with non-default database ports by setting up three port forwardings in the Cypress container:
docker exec jbt-cypress bash -c 'apt-get update && apt-get upgrade -y && apt-get install socat -y'
docker exec -d jbt-cypress socat 'TCP6-LISTEN:4711,fork,reuseaddr' 'TCP6:[fd00::11]:3306'
docker exec -d jbt-cypress socat 'TCP6-LISTEN:4712,fork,reuseaddr' 'TCP6:[fd00::12]:3306'
docker exec -d jbt-cypress socat 'TCP6-LISTEN:4713,fork,reuseaddr' 'TCP6:[fd00::13]:5432'
  1. ✅ Test IPv6 with non-default port number using test2.sh.txt as one-liner script with Cypress configuration, the Web Installer installation step, and one test specification that uses custom database commands.

  2. ✅ Test IPv6 with unset port number by adapting test2.sh and running it again:

types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("fd00::11" "fd00::11" "fd00::12" "fd00::12" "fd00::13")
ports=("" "" "" "" "")
  1. ✅ Test IPv4 with unset port number by adapting test2.sh and running it again:
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("10.0.0.11" "10.0.0.11" "10.0.0.12" "10.0.0.12" "10.0.0.13")
ports=("" "" "" "" "")
  1. ✅ Test IPv4 with non-default port number by adapting test2.sh and running it again:
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("10.0.0.7" "10.0.0.7" "10.0.0.7" "10.0.0.7" "10.0.0.7")
ports=("4711" "4711" "4712" "4712" "4713")
  1. ✅ Test hostname with unset port number by adapting test2.sh and running it again:
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("jbt-mysql" "jbt-mysql" "jbt-madb" "jbt-madb" "jbt-pg")
ports=("" "" "" "" "")
  1. ✅ Test hostname with non-default port number by adapting test2.sh and running it again:
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("jbt-cypress" "jbt-cypress" "jbt-cypress" "jbt-cypress" "jbt-cypress")
ports=("4711" "4711" "4712" "4712" "4713")
  1. ✅ Test Unix sockets by adapting test2.sh and running it again:
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("unix:/var/run/mysql-socket/mysqld.sock" "unix:/var/run/mysql-socket/mysqld.sock" "unix:/var/run/mariadb-socket/mysqld.sock" "unix:/var/run/mariadb-socket/mysqld.sock" "unix:/var/run/postgresql-socket")
ports=("" "" "" "" "")

Running the 36 Joomla installations it's a bit like baking rolls 😄

@richard67
Copy link
Contributor Author

@muhme It seems the link test2.sh.txt opens the download for a GitHub attachment which is empty, so I don't really know what your test script does in detail. Do your tests cover the case that the port is not given as a separate driver option but encoded in the host name, like e.g. 10.0.0.11:4711 or jbt-mysql:4711?

@muhme
Copy link

muhme commented Nov 10, 2024

@richard67 the link still works for me, however here is the source

#!/bin/bash -e
types=("MySQLi" "MySQL (PDO)" "MySQLi" "MySQL (PDO)" "PostgreSQL (PDO)")
hosts=("fd00::7" "fd00::7" "fd00::7" "fd00::7" "fd00::7")
ports=("4711" "4711" "4712" "4712" "4713")
for i in "${!types[@]}"; do
  echo "TESTING type=[${types[$i]}] host=[${hosts[$i]}] port=[${ports[$i]}]"
  docker exec jbt-cypress bash -c "sed -i -e \"s|db_type: '.*'|db_type: '${types[$i]}'|\" \
                                          -e \"s|db_host: '.*'|db_host: '${hosts[$i]}'|\" \
                                          -e \"s|db_port: '.*'|db_port: '${ports[$i]}'|\" /jbt/joomla-52/cypress.config.mjs"
  scripts/test 52 system novnc tests/System/integration/install/Installation.cy.js,tests/System/integration/administrator/components/com_banners/Banner.cy.js
done

And yes, the 6. test covers IPv4 with non-default port e.g. 10.0.0.7:4711 and 8. test step covers hostname and port jbt-cypress:4711. In using JBT you can watch the tests with http://host.docker.internal:7005/vnc.html?autoconnect=true&resize=scale and see host field filled

@richard67
Copy link
Contributor Author

I see. You have tested all cases. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants