lucatume / wp-browser

The easy and reliable way to test WordPress with Codeception. 10 years of proven success.
https://wpbrowser.wptestkit.dev/
MIT License
603 stars 86 forks source link

[BUG] Empty < Invalid database name: > when trying to add WPLoader #671

Closed mwei0210 closed 10 months ago

mwei0210 commented 11 months ago

Environment Environment OS: Linux PHP version: 8.0.30 Installed Codeception version: 5.0.12 Installed wp-browser version: 4.0.10 WordPress version: 6.3.2 Local development environment: Nginx WordPress structure and management: default

Can you perform the test manually? N/A

Codeception configuration file

namespace: Tests
support_namespace: Support
paths:
    tests: tests
    output: tests/_output
    data: tests/Support/Data
    support: tests/Support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
params:
    - .env.testing
settings:
    memory_limit: 2048m

Suite configuration file Paste, in a fenced YAML block, the content of the suite configuration file; remove any sensitive data!

actor: AcceptanceTester
modules:
    enabled:
        - WPDb
        - WPWebDriver
        - WPLoader
    config:
        WPWebDriver:
            url: 'https://mywebsite.com'
            adminUsername: '%WORDPRESS_ADMIN_USER%'
            adminPassword: '%WORDPRESS_ADMIN_PASSWORD%'
            adminPath: '/wp-admin'
            browser: chrome
            host: 'x.x.x.x'
            port: '8080'
            path: '/'
            window_size: false
            wait: 5
            capabilities:
              "goog:chromeOptions":
                args:
                  - "--headless"
                  - "--disable-gpu"
                  - "--disable-dev-shm-usage"
                  - "--proxy-server='direct://'"
                  - "--proxy-bypass-list=*"
                  - "--no-sandbox"
        WPDb:
            dsn: '%TEST_SITE_DB_DSN%'
            user: '%TEST_SITE_DB_USER%'
            password: '%TEST_SITE_DB_PASSWORD%'
            dump: 'tests/_data/dump.sql'
            #import the dump before the tests; this means the test site database will be repopulated before the tests.
            populate: false
            # re-import the dump between tests; this means the test site database will be repopulated between the tests.
            populator: 'mysql -u $user -p$password -h $host < $dump'
            cleanup: false
            waitlock: 10
            url: '%TEST_SITE_WP_URL%'
            urlReplacement: false #replace the hardcoded dump URL with the one above
            tablePrefix: '%TEST_SITE_TABLE_PREFIX%'
        WPLoader:
            wpRootFolder: "%WP_ROOT_FOLDER%"
            domain: "%TEST_SITE_WP_DOMAIN%"
            dbName: "%TEST_DB_NAME%"
            dbHost: "%TEST_DB_HOST%"
            dbUser: "%TEST_DB_USER%"
            dbPassword: "%TEST_DB_PASSWORD%"
            loadOnly: true

Describe the bug Got the error when trying to add WPLoader into the suite config

If i try to add var_dump in WPLoader.php like below, I can see the dbName in config:

image

Output

In MysqlDatabase.php line 34:

  [lucatume\WPBrowser\WordPress\DbException (1)]  
  Invalid database name:                          

To Reproduce vendor/bin/codecept run acceptance -d

Expected behavior Run the test suite loading WPLoader

Screenshots

image
lucatume commented 11 months ago

Thanks @mwei0210 for taking the time to report an issue. This is likely related to the database name not passing the validation for safe names, what is the database name? If you cannot provide the real database name, could you provide an anonymized version of it I could test with. To immediately solve the issue, you can just use a database name that passes the current validation logic.

mwei0210 commented 11 months ago

I tried passing the dbName into the regex, it returned true

The db name is my_dbname_n8h96prxar4r