1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 04:54:04 +00:00
tenancy/src
lukinovec aa9d1d7fcf
Parameter validation and other DB manager improvements (#1459)
### Parameter validation

In `statement()` calls of `TenantDatabaseManager`s, use parameter
binding when possible. When that's not possible, validate the parameters
using `validateParameter()` or `validatePassword()`.

Passwords use a less strict allowlist than other parameters (e.g. DB
names), since passwords tend to use more special characters but we can
afford to be more restrictive in the generic `validateParameter()`.

In `SQLiteDatabaseManager`, names of file-based databases are validated
(in `createDatabase`, `deleteDatabase` and `databaseExists`) using a
similar allowlist to the (non-password) parameters in other DB managers,
with an additional character: `.` (this addition is necessary since
file-based SQLite databases end with `.sqlite`).

### DatabaseTenancyBootstrapper - harden() and the lost test file

While checking for more places that could use validation, I realized
that it's possible to update tenant's db_name to the central DB or the
DB of another tenant. Added the `DatabaseTenancyBootstrapper::$harden`
property -- setting it to true prevents tenants from connecting to the
wrong databases (`RuntimeException` is thrown after connecting to the
wrong database).

Also, the DatabaseTenancyBootstrapper test file was ignored while
running tests because it lacked the `Test` suffix. Added the suffix and
fixed the broken `DATABASE_URL` test in the file.

### SQLiteDatabaseManager - respect static $path property in
makeConnectionConfig()

SQLiteDatabaseManager had a bug in `makeConnectionConfig`: the method
didn't respect the static `$path` property, it used `database_path()`
instead. Added a regression test for that. Also recognizing in-memory
SQLite databases (using `isInMemory()`) is more strict now so that
simply having a db_name with `_tenancy_inmemory_` somewhere in the name
doesn't make a file-based database considered in-memory.

### MySQLDatabaseManager - charset and collation defaulting

Creating databases with `null` charsets and collations resulted in a
`QueryException`, since null isn't a valid charset/collation. To solve
that, in the `CREATE DATABASE` statement in MySQLDatabaseManager, only
add charset/collation to the statement if they are not null.

MySQL defaults to the server's charset and collation, so it's safe to
not pass any charset/collation in the `CREATE DATABASE` statement and
let MySQL choose. Also, if e.g. collation is non-null and charset is
null, MySQL will use a charset compatible with the used collation, and
this works both ways.

---------

Co-authored-by: Samuel Stancl <samuel@archte.ch>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-06-27 19:51:30 -07:00
..
Actions Cloning: improve type annotations, add cloneRoutes() for convenience 2025-11-10 02:16:57 +01:00
Bootstrappers Parameter validation and other DB manager improvements (#1459) 2026-06-27 19:51:30 -07:00
Commands Add --skip-tenants option to HasTenantOptions (#1436) 2026-06-07 15:18:38 -07:00
Concerns Add --skip-tenants option to HasTenantOptions (#1436) 2026-06-07 15:18:38 -07:00
Contracts Features refactor 2025-08-31 23:18:44 +02:00
Controllers [4.x] General code cleanup (#1278) 2024-12-31 00:35:46 +01:00
Database Parameter validation and other DB manager improvements (#1459) 2026-06-27 19:51:30 -07:00
Enums Make RouteMode enum backed (#1362) 2025-06-02 20:34:49 +02:00
Events Pending tenants refactor (BC break) 2025-08-25 00:01:02 +02:00
Exceptions remove ignition dependencies 2025-06-18 23:29:24 +02:00
Facades [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
Features [MINOR BC] UserImpersonation: store auth guard in session, add $logout param to stopImpersonating() (#1437) 2026-06-05 14:15:19 -07:00
Jobs [MINOR BC] Create pending tenants with pending_since, improve --with-pending (#1458) 2026-06-05 15:36:57 -07:00
Listeners Change tenant storage listeners into jobs (#1446) 2026-04-22 16:45:54 +02:00
Middleware Remove redundant universal route check from PreventAccess MW (#1427) 2026-05-12 23:59:21 +02:00
Overrides TenancyUrlGenerator: override toRoute(), refactor (#1439) 2026-06-06 14:52:37 -07:00
Resolvers Correct DomainTenantResolver::isSubdomain() check (#1425) 2026-05-11 14:26:06 +02:00
ResourceSyncing [4.x] Add more relation type annotations (#1424) 2025-12-28 23:20:05 +01:00
RLS [4.x] TableRLSManager refactor, comment constraints (#1354) 2025-07-03 21:12:04 +02:00
UniqueIdentifierGenerators Add UUIDv7Generator 2025-11-04 15:45:48 +01:00
helpers.php resolve minor todos 2025-08-18 15:05:17 +02:00
Tenancy.php [4.x] Add Tenancy::reinitialize() method (#1449) 2026-04-08 19:21:43 +02:00
TenancyServiceProvider.php Make globalCache always use central conn with DB cache stores (#1462) 2026-06-27 18:30:01 -07:00