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

Pdo driver interface/password sensitive param #874

Merged
Merged
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);
}
Tigrov marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading