Skip to content

Commit 489b0d1

Browse files
authored
Merge pull request #121 from eclipxe13/version-2.28.2
Fix openssl run not throwing an OpenSSLException (version 2.28.2)
2 parents 76c3c81 + eca2ffe commit 489b0d1

File tree

9 files changed

+61
-42
lines changed

9 files changed

+61
-42
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ name: build
22
on:
33
workflow_dispatch:
44
pull_request:
5-
branches:
6-
- master
5+
branches: [ "master" ]
76
push:
8-
branches:
9-
- master
7+
branches: [ "master" ]
108
schedule:
119
- cron: '0 16 * * 0' # sunday 16:00
1210

@@ -107,11 +105,11 @@ jobs:
107105
run: phpstan analyse --no-progress --verbose
108106

109107
tests-linux:
110-
name: Test PHP ${{ matrix.php-versions }} on Linux
108+
name: Test PHP ${{ matrix.php-version }} on Linux
111109
runs-on: "ubuntu-latest"
112110
strategy:
113111
matrix:
114-
php-versions: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
112+
php-version: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
115113
steps:
116114
- name: Checkout
117115
uses: actions/checkout@v4
@@ -127,7 +125,7 @@ jobs:
127125
- name: Setup PHP
128126
uses: shivammathur/setup-php@v2
129127
with:
130-
php-version: ${{ matrix.php-versions }}
128+
php-version: ${{ matrix.php-version }}
131129
extensions: soap, intl, xsl, fileinfo, bcmath
132130
coverage: xdebug
133131
tools: composer:v2
@@ -149,7 +147,7 @@ jobs:
149147
mv resources-sat-xml-cloned/resources build/resources
150148
rm -r -f resources-sat-xml-cloned
151149
- name: Remove genkgo/xsl on PHP 8.3
152-
if: matrix.php-versions == '8.3'
150+
if: matrix.php-version == '8.3'
153151
run: |
154152
composer remove genkgo/xsl --dev --no-interaction --no-progress --no-update
155153
- name: Install project dependencies
@@ -165,11 +163,11 @@ jobs:
165163
php build/scrutinizer/vendor/bin/ocular code-coverage:upload -vvv --no-interaction --format=php-clover build/coverage-clover.xml
166164
167165
tests-windows:
168-
name: Tests PHP ${{ matrix.php-versions }} on Windows
166+
name: Tests PHP ${{ matrix.php-version }} on Windows
169167
runs-on: "windows-latest"
170168
strategy:
171169
matrix:
172-
php-versions: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
170+
php-version: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
173171
steps:
174172
- name: Checkout
175173
uses: actions/checkout@v4
@@ -178,7 +176,7 @@ jobs:
178176
- name: Setup PHP
179177
uses: shivammathur/setup-php@v2
180178
with:
181-
php-version: ${{ matrix.php-versions }}
179+
php-version: ${{ matrix.php-version }}
182180
extensions: soap, intl, xsl, fileinfo, bcmath
183181
coverage: none
184182
tools: composer:v2
@@ -201,7 +199,7 @@ jobs:
201199
mv resources-sat-xml-cloned/resources build/resources
202200
rm -r -f resources-sat-xml-cloned
203201
- name: Remove genkgo/xsl on PHP 8.3
204-
if: matrix.php-versions == '8.3'
202+
if: matrix.php-version == '8.3'
205203
run: |
206204
composer remove genkgo/xsl --dev --no-interaction --no-progress --no-update
207205
- name: Install project dependencies

.readthedocs.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ version: 2
88
build:
99
os: ubuntu-22.04
1010
tools:
11-
python: "3.7"
11+
python: "3"
1212

1313
mkdocs:
1414
configuration: mkdocs.yml
15-
16-
# Optionally set the version of Python and requirements required to build your docs
17-
python:
18-
install:
19-
- requirements: docs/rtd-requirements.txt

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"require-dev": {
4646
"ext-bcmath": "*",
47+
"ext-curl": "*",
4748
"ext-soap": "*",
4849
"genkgo/xsl": "^1.0.8",
4950
"phpunit/phpunit": "^9.5",

docs/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
- Remove deprecated constant `CfdiUtils\Retenciones\Retenciones::RET_NAMESPACE`.
3434
- Remove deprecated class `CfdiUtils\Utils\Crp20277Fixer`.
3535

36+
## Version 2.28.2 2024-02-20
37+
38+
- Wrap OpenSSL command run on a *try/catch* block to throw OpenSSLException.
39+
- Refactor certificate downloader test helper. Now it uses curl instead of native PHP. It was failing on PHP 7.3.
40+
- Remove old dependencies for *ReadTheDocs*: `mkdocs:1.2.3` and `jinja2<3.1.0`. Thanks to `@dependabot`.
41+
- On build workflow:
42+
- Simplify "on" section.
43+
- Use `php-version` matrix value as singular.
44+
3645
## Version 2.28.1 2024-02-20
3746

3847
- Allow dependency on `symfony/process` branch `7.x`.

docs/rtd-requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"devDependencies": {
3-
"markdownlint-cli": "^0.34.0"
3+
"markdownlint-cli": "^0.41.0"
44
}
55
}

src/CfdiUtils/Internals/CommandTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Build a command array from a template
77
*
8-
* NOTE: Changes will not be considering a bracking compatibility change since this utility is for internal usage only
8+
* NOTE: Changes will not be considering a breaking compatibility change since this utility is for internal usage only
99
* @internal
1010
*/
1111
class CommandTemplate

src/CfdiUtils/OpenSSL/Caller.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function call(string $template, array $arguments, array $environment = []
3737
}
3838

3939
// execute process
40-
$execution = $process->run();
40+
try {
41+
$execution = $process->run();
42+
} catch (Throwable $exception) {
43+
throw new OpenSSLException('Unable to run command', 0, $exception);
44+
}
4145

4246
// build response
4347
$callResponse = new CallResponse(

tests/CfdiUtilsTests/Certificado/CertificateDownloaderHelper.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,61 @@
44

55
use Exception;
66
use XmlResourceRetriever\Downloader\DownloaderInterface;
7-
use XmlResourceRetriever\Downloader\PhpDownloader;
87

98
/**
109
* This class is a wrapper around PhpDownloader to retry the download if it fails (for any reason).
1110
*
1211
* The reason behind this is that the web server at https://rdc.sat.gob.mx/
13-
* has issues and sometimes it does not respond with the certificate file.
12+
* has issues, and sometimes it does not respond with the certificate file.
1413
*
1514
* @see https://www.phpcfdi.com/sat/problemas-conocidos/descarga-certificados/
1615
*/
1716
final class CertificateDownloaderHelper implements DownloaderInterface
1817
{
19-
/** @var PhpDownloader */
20-
private $realDownloader;
21-
22-
private $maxAttempts;
23-
24-
public function __construct()
25-
{
26-
$this->realDownloader = new PhpDownloader();
27-
$this->maxAttempts = 8;
28-
}
18+
public const MAX_DOWNLOAD_ATTEMPTS = 8;
2919

3020
public function downloadTo(string $source, string $destination)
3121
{
3222
$attempt = 1;
3323
while (true) {
3424
try {
35-
$this->realDownloader->downloadTo($source, $destination);
25+
$this->realDownloadTo($source, $destination);
3626
break;
3727
} catch (Exception $exception) {
38-
// TODO: change to scpecific download exception when it exists
39-
if ($exception->getMessage() !== "Unable to download $source to $destination") {
40-
throw $exception;
41-
}
42-
if ($attempt === $this->maxAttempts) {
43-
throw $exception;
28+
if (self::MAX_DOWNLOAD_ATTEMPTS === $attempt) {
29+
throw new Exception("Unable to download $source to $destination", 0, $exception);
4430
}
4531
$attempt = $attempt + 1;
4632
continue;
4733
}
4834
}
4935
}
36+
37+
private function realDownloadTo(string $source, string $destination)
38+
{
39+
$ch = curl_init();
40+
curl_setopt($ch, CURLOPT_URL, $source);
41+
curl_setopt($ch, CURLOPT_VERBOSE, 0); // set to 1 to debug
42+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
43+
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
44+
curl_setopt($ch, CURLOPT_HEADER, 0);
45+
$result = (string) curl_exec($ch);
46+
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
47+
curl_close($ch);
48+
49+
if ('' === $result) {
50+
throw new Exception('Response is empty');
51+
}
52+
if (! is_scalar($status)) {
53+
throw new Exception('Invalid status code');
54+
}
55+
$status = (int) $status;
56+
if (200 !== $status) {
57+
throw new Exception('Status code is not 200');
58+
}
59+
60+
if (false === @file_put_contents($destination, $result)) {
61+
throw new Exception('Cannot save certificate on destination');
62+
}
63+
}
5064
}

0 commit comments

Comments
 (0)