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

refactor: Migrate away from deprecated ILogger to PSR-3 #641

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions lib/Compliance/HistoryCompliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,22 @@
use OCA\Password_Policy\PasswordPolicyConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\PreConditionNotMetException;
use OCP\Security\IHasher;
use Psr\Log\LoggerInterface;

class HistoryCompliance implements IAuditor, IUpdatable {
/** @var string */
protected $uid;

/** @var PasswordPolicyConfig */
private $policyConfig;
/** @var IConfig */
private $config;
/** @var IUserSession */
private $session;
/** @var IHasher */
private $hasher;
/** @var IL10N */
private $l;
/** @var ILogger */
private $logger;

public function __construct(
PasswordPolicyConfig $policyConfig,
IConfig $config,
IUserSession $session,
IHasher $hasher,
IL10N $l,
ILogger $logger
protected PasswordPolicyConfig $policyConfig,
protected IConfig $config,
protected IUserSession $session,
protected IHasher $hasher,
protected IL10N $l,
protected LoggerInterface $logger
) {
$this->policyConfig = $policyConfig;
$this->config = $config;
$this->session = $session;
$this->hasher = $hasher;
$this->l = $l;
$this->logger = $logger;
}

/**
Expand Down
27 changes: 8 additions & 19 deletions lib/Validator/HIBPValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,16 @@
use OCA\Password_Policy\PasswordPolicyConfig;
use OCP\Http\Client\IClientService;
use OCP\IL10N;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class HIBPValidator implements IValidator {

/** @var PasswordPolicyConfig */
private $config;
/** @var IL10N */
private $l;
/** @var IClientService */
private $clientService;
/** @var ILogger */
private $logger;

public function __construct(PasswordPolicyConfig $config,
IL10N $l,
IClientService $clientService,
ILogger $logger) {
$this->config = $config;
$this->l = $l;
$this->clientService = $clientService;
$this->logger = $logger;
public function __construct(
private PasswordPolicyConfig $config,
private IL10N $l,
private IClientService $clientService,
private LoggerInterface $logger,
) {
}

public function validate(string $password): void {
Expand All @@ -54,7 +43,7 @@ public function validate(string $password): void {
]
);
} catch (\Exception $e) {
$this->logger->logException($e, ['level' => ILogger::INFO]);
$this->logger->info('Could not connect to HaveIBeenPwned API', ['exception' => $e]);
return;
}

Expand Down
26 changes: 13 additions & 13 deletions tests/lib/Compliance/HistoryComplianceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,19 @@
use OCA\Password_Policy\PasswordPolicyConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Security\IHasher;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

class HistoryComplianceTest extends TestCase {

/** @var HistoryCompliance */
protected $instance;
/** @var PasswordPolicyConfig|MockObject */
protected $policyConfig;
/** @var IConfig|MockObject */
protected $config;
/** @var IUserSession|MockObject */
protected $session;
/** @var IHasher|MockObject */
protected $hasher;
protected HistoryCompliance $instance;
protected PasswordPolicyConfig&MockObject $policyConfig;
protected IConfig&MockObject $config;
protected IUserSession&MockObject $session;
protected IHasher&MockObject $hasher;

public function setUp(): void {
parent::setUp();
Expand All @@ -58,13 +53,18 @@ public function setUp(): void {
$this->session = $this->createMock(IUserSession::class);
$this->hasher = $this->createMock(IHasher::class);

/** @var IL10N&MockObject */
$l10n = $this->createMock(IL10N::class);
/** @var LoggerInterface&MockObject */
$logger = $this->createMock(LoggerInterface::class);

$this->instance = new HistoryCompliance(
$this->policyConfig,
$this->config,
$this->session,
$this->hasher,
$this->createMock(IL10N::class),
$this->createMock(ILogger::class)
$l10n,
$logger,
);
}

Expand Down
Loading