Skip to content

Commit

Permalink
Testando assinatura 2x do mesmo documento
Browse files Browse the repository at this point in the history
  • Loading branch information
gersonfs committed Jul 1, 2024
1 parent a2d7b6b commit 696fee8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function sign(
if (empty($node) || empty($root)) {
throw SignerException::tagNotFound($tagname);
}
if (!self::existsSignature($content)) {
if (!self::existsSignature($content, $rootname)) {
$dom = self::createSignature(
$certificate,
$dom,
Expand Down
10 changes: 10 additions & 0 deletions tests/SignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public function testSign()
$xmlsign = Signer::sign($certificate, $content, 'infNFe', 'Id');
$actual = Signer::isSigned($xmlsign);
$this->assertTrue($actual);

$xmlsign = Signer::sign($certificate, '<a><b><c>Teste Assinar mesmo documento 2x</c></b></a>', 'b', 'Id', OPENSSL_ALGO_SHA1, Signer::CANONICAL, 'b');
$this->assertTrue(Signer::existsSignature($xmlsign, 'b'));

$xmlsign2x = Signer::sign($certificate, $xmlsign, 'b', 'Id', OPENSSL_ALGO_SHA1, Signer::CANONICAL, 'a');
$this->assertTrue(Signer::existsSignature($xmlsign2x, 'a'));

$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadXML($xmlsign2x);
$this->assertEquals(2, $dom->getElementsByTagName('Signature')->count());
}

/**
Expand Down

0 comments on commit 696fee8

Please sign in to comment.