|
10 | 10 |
|
11 | 11 | use DateTime; |
12 | 12 | use DateTimeInterface; |
| 13 | +use OCA\Libresign\Db\File; |
| 14 | +use OCA\Libresign\Db\IdentifyMethod; |
| 15 | +use OCA\Libresign\Db\SignRequest; |
13 | 16 | use OCA\Libresign\Db\SignRequestMapper; |
14 | 17 | use OCA\Libresign\Enum\CrlValidationStatus; |
| 18 | +use OCA\Libresign\Service\File\FileResponseOptions; |
15 | 19 | use OCA\Libresign\Service\File\SignersLoader; |
| 20 | +use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; |
16 | 21 | use OCA\Libresign\Service\IdentifyMethodService; |
17 | 22 | use OCA\Libresign\Service\SubjectAlternativeNameService; |
18 | 23 | use OCA\Libresign\Tests\Unit\TestCase; |
19 | 24 | use OCP\Accounts\IAccountManager; |
| 25 | +use OCP\IUser; |
20 | 26 | use OCP\IUserManager; |
21 | 27 | use PHPUnit\Framework\Attributes\DataProvider; |
22 | 28 | use PHPUnit\Framework\MockObject\MockObject; |
@@ -47,6 +53,63 @@ private function getService(): SignersLoader { |
47 | 53 | ); |
48 | 54 | } |
49 | 55 |
|
| 56 | + public function testLoadLibreSignSignersUsesCanonicalSignerUuidWithoutSettingsLeak(): void { |
| 57 | + $file = new File(); |
| 58 | + $file->setId(10); |
| 59 | + |
| 60 | + $signRequest = new SignRequest(); |
| 61 | + $signRequest->setId(52); |
| 62 | + $signRequest->setFileId(10); |
| 63 | + $signRequest->setUuid('sign-request-uuid'); |
| 64 | + $signRequest->setDisplayName('Signer User'); |
| 65 | + $signRequest->setCreatedAt(new DateTime('2026-01-01T00:00:00Z')); |
| 66 | + $signRequest->setStatus(1); |
| 67 | + |
| 68 | + $identifyEntity = new IdentifyMethod(); |
| 69 | + $identifyEntity->setIdentifierKey(IdentifyMethodService::IDENTIFY_EMAIL); |
| 70 | + $identifyEntity->setIdentifierValue('signer@example.com'); |
| 71 | + $identifyEntity->setMandatory(1); |
| 72 | + |
| 73 | + $identifyMethod = $this->createMock(IIdentifyMethod::class); |
| 74 | + $identifyMethod->method('getEntity')->willReturn($identifyEntity); |
| 75 | + |
| 76 | + $currentIdentifyMethod = $this->createMock(IIdentifyMethod::class); |
| 77 | + $currentIdentifyMethod->method('getSignatureMethods')->willReturn([]); |
| 78 | + |
| 79 | + $currentUser = $this->createMock(IUser::class); |
| 80 | + $currentUser->method('getUID')->willReturn('signer-user'); |
| 81 | + $currentUser->method('getEMailAddress')->willReturn('signer@example.com'); |
| 82 | + |
| 83 | + $options = new FileResponseOptions(); |
| 84 | + $options->setMe($currentUser); |
| 85 | + |
| 86 | + $fileData = new \stdClass(); |
| 87 | + $fileData->settings = [ |
| 88 | + 'canSign' => false, |
| 89 | + 'canRequestSign' => false, |
| 90 | + 'phoneNumber' => '', |
| 91 | + ]; |
| 92 | + |
| 93 | + $this->signRequestMapper->method('getByFileId')->with(10)->willReturn([$signRequest]); |
| 94 | + $this->signRequestMapper->method('getTextOfSignerStatus')->willReturn('pending'); |
| 95 | + $this->identifyMethodService->method('setIsRequest')->willReturnSelf(); |
| 96 | + $this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([ |
| 97 | + 52 => [ |
| 98 | + IdentifyMethodService::IDENTIFY_EMAIL => [$identifyMethod], |
| 99 | + ], |
| 100 | + ]); |
| 101 | + $this->identifyMethodService->method('setCurrentIdentifyMethod')->willReturnSelf(); |
| 102 | + $this->identifyMethodService->method('getInstanceOfIdentifyMethod')->willReturn($currentIdentifyMethod); |
| 103 | + |
| 104 | + $this->getService()->loadLibreSignSigners($file, $fileData, $options); |
| 105 | + |
| 106 | + $this->assertCount(1, $fileData->signers); |
| 107 | + $this->assertSame('sign-request-uuid', $fileData->signers[0]->sign_request_uuid); |
| 108 | + $this->assertObjectNotHasProperty('sign_uuid', $fileData->signers[0]); |
| 109 | + $this->assertTrue($fileData->settings['canSign']); |
| 110 | + $this->assertArrayNotHasKey('signerFileUuid', $fileData->settings); |
| 111 | + } |
| 112 | + |
50 | 113 | #[DataProvider('dataLoadSignersFromCertData')] |
51 | 114 | public function testLoadSignersFromCertData(array $certData, string $host, string $resolveUidReturn, array $expected): void { |
52 | 115 | $this->signRequestMapper->method('getTextOfSignerStatus')->willReturn('status-text'); |
|
0 commit comments