Skip to content

Commit cffb1f8

Browse files
test(validation): cover invalid certificate chain stream handling
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent dfe7762 commit cffb1f8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/php/Unit/Service/File/CertificateChainServiceTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,33 @@ public function fopen($mode) {
5353
$this->assertIsArray($result);
5454
$this->assertArrayHasKey('chain', $result);
5555
}
56+
57+
public function testGetCertificateChainHandlesInvalidResourceGracefully(): void {
58+
$fileNode = new class() {
59+
public function fopen($mode) {
60+
return false;
61+
}
62+
};
63+
64+
$libreSignFile = new File();
65+
$libreSignFile->setSignedNodeId(1);
66+
67+
$pkcs12 = $this->createMock(Pkcs12Handler::class);
68+
$pkcs12->expects($this->never())->method('getCertificateChain');
69+
70+
$logger = $this->createMock(LoggerInterface::class);
71+
$logger
72+
->expects($this->once())
73+
->method('warning')
74+
->with($this->stringContains('unable to open signed file stream'));
75+
76+
$service = new CertificateChainService($pkcs12, $logger);
77+
78+
$options = new FileResponseOptions();
79+
$options->validateFile(true);
80+
81+
$result = $service->getCertificateChain($fileNode, $libreSignFile, $options);
82+
83+
$this->assertSame([], $result);
84+
}
5685
}

0 commit comments

Comments
 (0)