Skip to content

Commit 0406158

Browse files
committed
fix(policy): resolve IdentifyService constructor injection and fix unit tests
- Restore PolicyService as constructor parameter in IdentifyService (removed lazy Server::get() which bypassed DI mocking) - Add getFriendlyNamesMap() to IdentifyMethodService that reads friendly names directly from injected instances, avoiding circular call chain (getSettings() -> PolicyService -> normalize() -> getSettings()) - Update IdentifyMethodsPolicyValue::normalize() to accept optional IdentifyMethodService for enriching identify_methods entries that lack friendly_name (e.g. values stored via provisioning API) - Update IdentifyMethodsPolicyTest to inject IdentifyMethodService mock in constructor This fixes the Playwright E2E tests that timed out at getByPlaceholder(Account) because the identify_methods values set via provisioning API did not include friendly_name, which the frontend uses as tab label and input placeholder text. Signed-off-by: Vitor Mattos <[email protected]>
1 parent d76bcd8 commit 0406158

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

lib/Service/IdentifyMethod/IdentifyService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getSavedSettings(): array {
133133
return $this->savedSettings;
134134
}
135135

136-
$resolved = $this->policyService->resolve(IdentifyMethodsPolicy::KEY)->getEffectiveValue();
136+
$resolved = $this->getPolicyService()->resolve(IdentifyMethodsPolicy::KEY)->getEffectiveValue();
137137
$normalized = IdentifyMethodsPolicyValue::normalize($resolved);
138138
$this->savedSettings = $normalized;
139139
return $this->savedSettings;

lib/Service/IdentifyMethodService.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,17 @@ public function getIdentifyMethodsSettings(): array {
359359
return $this->identifyMethodsSettings;
360360
}
361361

362-
/**
363-
* Resolve UID from certificate chain data
364-
@@ if ($this->xmpp->isTwofactorGatewayEnabled()) {
365-
$this->identifyMethodsSettings[] = $this->xmpp->getSettings();
366-
}
367-
return $this->identifyMethodsSettings;
362+
/** @return array<string, string> */
363+
public function getFriendlyNamesMap(): array {
364+
return [
365+
$this->account->getName() => $this->account->getFriendlyName(),
366+
$this->email->getName() => $this->email->getFriendlyName(),
367+
$this->signal->getName() => $this->signal->getFriendlyName(),
368+
$this->sms->getName() => $this->sms->getFriendlyName(),
369+
$this->telegram->getName() => $this->telegram->getFriendlyName(),
370+
$this->Whatsapp->getName() => $this->Whatsapp->getFriendlyName(),
371+
$this->xmpp->getName() => $this->xmpp->getFriendlyName(),
372+
];
368373
}
369374

370375
/**

lib/Service/Policy/Provider/IdentifyMethods/IdentifyMethodsPolicyValue.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ public static function normalize(mixed $rawValue, ?IdentifyMethodService $identi
8484
$normalized[] = $normalizedEntry;
8585
}
8686

87-
// Enrich friendly_name from identify method services if not present and service is available
8887
if ($identifyMethodService !== null) {
89-
$settings = $identifyMethodService->getIdentifyMethodsSettings();
90-
$friendlyNames = array_column($settings, 'friendly_name', 'name');
88+
$friendlyNames = $identifyMethodService->getFriendlyNamesMap();
9189
foreach ($normalized as &$entry) {
9290
if (!isset($entry['friendly_name']) && isset($entry['name'], $friendlyNames[$entry['name']])) {
9391
$entry['friendly_name'] = $friendlyNames[$entry['name']];

tests/php/Unit/Service/Policy/Provider/IdentifyMethods/IdentifyMethodsPolicyTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88

99
namespace OCA\Libresign\Tests\Unit\Service\Policy\Provider\IdentifyMethods;
1010

11+
use OCA\Libresign\Service\IdentifyMethodService;
1112
use OCA\Libresign\Service\Policy\Provider\IdentifyMethods\IdentifyMethodsPolicy;
13+
use PHPUnit\Framework\MockObject\MockObject;
1214
use PHPUnit\Framework\TestCase;
1315

1416
final class IdentifyMethodsPolicyTest extends TestCase {
17+
private IdentifyMethodService&MockObject $identifyMethodService;
18+
19+
public function setUp(): void {
20+
parent::setUp();
21+
$this->identifyMethodService = $this->createMock(IdentifyMethodService::class);
22+
}
23+
1524
public function testProviderBuildsIdentifyMethodsDefinition(): void {
16-
$provider = new IdentifyMethodsPolicy();
25+
$provider = new IdentifyMethodsPolicy($this->identifyMethodService);
1726
$this->assertSame([IdentifyMethodsPolicy::KEY], $provider->keys());
1827

1928
$definition = $provider->get(IdentifyMethodsPolicy::KEY);
@@ -22,7 +31,7 @@ public function testProviderBuildsIdentifyMethodsDefinition(): void {
2231
}
2332

2433
public function testProviderNormalizesIdentifyMethodsPayload(): void {
25-
$provider = new IdentifyMethodsPolicy();
34+
$provider = new IdentifyMethodsPolicy($this->identifyMethodService);
2635
$definition = $provider->get(IdentifyMethodsPolicy::KEY);
2736

2837
$normalized = $definition->normalizeValue([

0 commit comments

Comments
 (0)