Skip to content

Commit

Permalink
Pdo driver interface/password sensitive param (#874)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Tigrov <[email protected]>
  • Loading branch information
heap-s and Tigrov authored Sep 4, 2024
1 parent 4b2adc3 commit e6382dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
ini-values: date.timezone='UTC', zend.exception_ignore_args=0
coverage: pcov
tools: composer:v2, pecl

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Enh #862: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov)
- Enh #865: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov, @vjik)
- Enh #798: Allow `QueryInterface::one()` and `QueryInterface::all()` to return objects (@darkdef, @Tigrov)
- Enh #872: Use `#[\SensitiveParameter]` attribute to mark sensitive parameters (@heap-s)
- Enh #864: Realize column factory (@Tigrov)
- Enh #875: Ignore "Packets out of order..." warnings in `AbstractPdoCommand::internalExecute()` method (@Tigrov)

Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Pdo/AbstractPdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractPdoDriver implements PdoDriverInterface
public function __construct(
protected string $dsn,
protected string $username = '',
protected string $password = '',
#[\SensitiveParameter] protected string $password = '',
protected array $attributes = []
) {
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public function getUsername(): string
return $this->username;
}

public function password(string $password): void
public function password(#[\SensitiveParameter] string $password): void
{
$this->password = $password;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Db/Driver/PDO/PDODriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,23 @@ public function testGetUsername(): void

$this->assertSame('username', $pdoDriver->getUsername());
}

public function testSensitiveParameter(): void
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('SensitiveParameterValue is not available in PHP < 8.2');
}
$dsn = 'sqlite::memory:';
try {
new PDODriver($dsn, password: null);
} catch (\TypeError $e) {
$this->assertTrue($e->getTrace()[0]['args'][2] instanceof \SensitiveParameterValue);
}
$pdoDriver = new PDODriver($dsn);
try {
$pdoDriver->password(null);
} catch (\TypeError $e) {
$this->assertTrue($e->getTrace()[0]['args'][0] instanceof \SensitiveParameterValue);
}
}
}

0 comments on commit e6382dd

Please sign in to comment.