Skip to content

Commit

Permalink
4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsedivy committed Jan 2, 2020
2 parents dd9e8e1 + 478eebd commit 1a9c4d6
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/FilipSedivy/EET/Dispatcher.php
Expand Up @@ -4,6 +4,7 @@

use FilipSedivy\EET\Enum;
use FilipSedivy\EET\Exceptions;
use FilipSedivy\EET\Utils\Debugger;
use FilipSedivy\EET\Utils\Format;
use RobRichards\XMLSecLibs\XMLSecurityKey;
use Symfony\Component\Validator\Validation;
Expand Down Expand Up @@ -93,6 +94,15 @@ public function check(Receipt $receipt): bool
}
}

public function test(Receipt $receipt, bool $hiddenSensitiveData = true): void
{
$this->check($receipt);

$debugger = new Debugger\LastRequest($this->soapClient->lastRequest);
$debugger->hiddenSensitiveData = $hiddenSensitiveData;
$debugger->out();
}

public function getCheckCodes(Receipt $receipt): array
{
if (isset($this->validator)) {
Expand Down
105 changes: 105 additions & 0 deletions src/FilipSedivy/EET/Utils/Debugger/LastRequest.php
@@ -0,0 +1,105 @@
<?php declare(strict_types=1);

namespace FilipSedivy\EET\Utils\Debugger;

use DOMDocument;

class LastRequest
{
private const SENSITIVE_TAGS = [
'DigestValue',
'SignatureValue',
'BinarySecurityToken'
];

/** @var bool */
public $highlight = true;

/** @var bool */
public $format = true;

/** @var bool */
public $hiddenSensitiveData = true;

/** @var string */
public $sensitiveValue = '**** CENSURE ****';

/** @var string */
private $lastRequest;

public function __construct(string $lastRequest)
{
$this->lastRequest = $lastRequest;
}

public function out(): void
{
if ($this->hiddenSensitiveData) {
$this->doHiddenSensitiveData();
}

if ($this->format) {
$this->doFormat();
}

if ($this->highlight) {
$this->doHighlight();
}

printf('<pre>%s</pre>', $this->lastRequest);
}

private function doFormat(): void
{
$dom = new DOMDocument;

$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

$dom->loadXML($this->lastRequest);

$this->lastRequest = $dom->saveXML();
}

private function doHighlight(): void
{
$s = htmlspecialchars($this->lastRequest);

$s = preg_replace("#&lt;([/]*?)(.*)([\s]*?)&gt;#sU",
"<span style=\"color: #0000FF\">&lt;\\1\\2\\3&gt;</span>", $s);

$s = preg_replace("#&lt;([\?])(.*)([\?])&gt;#sU",
"<span style=\"color: #800000\">&lt;\\1\\2\\3&gt;</span>", $s);

$s = preg_replace("#&lt;([^\s\?/=])(.*)([\[\s/]|&gt;)#iU",
"&lt;<span style=\"color: #808000\">\\1\\2</span>\\3", $s);

$s = preg_replace("#&lt;([/])([^\s]*?)([\s\]]*?)&gt;#iU",
"&lt;\\1<span style=\"color: #808000\">\\2</span>\\3&gt;", $s);

$s = preg_replace("#([^\s]*?)\=(&quot;|')(.*)(&quot;|')#isU",
"<span style=\"color: #800080\">\\1</span>=<span style=\"color: #FF00FF\">\\2\\3\\4</span>", $s);

$s = preg_replace("#&lt;(.*)(\[)(.*)(\])&gt;#isU",
"&lt;\\1<span style=\"color: #800080\">\\2\\3\\4</span>&gt;", $s);

$this->lastRequest = nl2br($s);
}

private function doHiddenSensitiveData(): void
{
$dom = new DOMDocument;
$dom->loadXML($this->lastRequest);

foreach (self::SENSITIVE_TAGS as $tag) {
$nodeList = $dom->getElementsByTagName($tag);

for ($i = 0; $i < $nodeList->length; $i++) {
$node = $nodeList->item($i);
$node->nodeValue = $this->sensitiveValue;
}
}

$this->lastRequest = $dom->saveXML();
}
}
Binary file modified tests/Data/EET_CA1_Playground-CZ00000019.p12
Binary file not shown.
Binary file added tests/Data/EET_CA1_Playground-CZ1212121218.p12
Binary file not shown.
Binary file added tests/Data/EET_CA1_Playground-CZ683555118.p12
Binary file not shown.
Binary file added tests/Data/EET_CA1_Playground-ca.crt
Binary file not shown.

0 comments on commit 1a9c4d6

Please sign in to comment.