Skip to content

Commit 267b23f

Browse files
authored
Merge pull request #67 from Seros/allow-dependency-updates
Allow updates for Symfony and Doctrine bundles
2 parents 2a78cd1 + 83b7181 commit 267b23f

9 files changed

Lines changed: 122 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
test:
11+
name: PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php:
18+
- 8.2
19+
- 8.3
20+
- 8.4
21+
symfony:
22+
- 6.4.*
23+
- 7.4.*
24+
- 8.0.*
25+
exclude:
26+
# Symfony 8.0 requires PHP 8.4+
27+
- php: '8.2'
28+
symfony: '8.0.*'
29+
- php: '8.3'
30+
symfony: '8.0.*'
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Setup PHP and install Symfony Flex globally
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
coverage: none
41+
extensions: mbstring, openssl, sodium
42+
tools: flex
43+
44+
- name: Install dependencies
45+
env:
46+
SYMFONY_REQUIRE: ${{ matrix.symfony }}
47+
run: composer update --prefer-dist --no-progress --no-interaction
48+
49+
- name: Run tests
50+
run: vendor/bin/phpunit

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
],
1616
"require" : {
1717
"php": ">=8.2",
18-
"symfony/framework-bundle": "^6.4||^7.0",
19-
"symfony/console": "^6.4||^7.0",
20-
"doctrine/orm": "^2.12||^3.2",
21-
"doctrine/doctrine-bundle": "^2.12",
22-
"symfony/monolog-bundle": "^3.7",
18+
"symfony/framework-bundle": "^6.4||^7.4||^8.0",
19+
"symfony/console": "^6.4||^7.4||^8.0",
20+
"doctrine/orm": "^2.12||^3.2||^4.0",
21+
"doctrine/doctrine-bundle": "^2.12||^3.0",
22+
"symfony/monolog-bundle": "^3.7||^4.0",
2323
"ext-mbstring": "*",
2424
"ext-openssl": "*",
2525
"ext-sodium": "*"
2626
},
2727
"require-dev": {
28-
"symfony/phpunit-bridge": "^6.0"
28+
"symfony/phpunit-bridge": "^6.0",
29+
"phpunit/phpunit": "^11.2"
2930
},
3031
"autoload": {
3132
"psr-4": {

phpunit.xml.dist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
cacheDirectory=".phpunit.cache"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1"/>
13+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
14+
</php>
15+
16+
<testsuites>
17+
<testsuite name="Project Test Suite">
18+
<directory>tests</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<source>
23+
<include>
24+
<directory>src</directory>
25+
</include>
26+
</source>
27+
</phpunit>

src/Command/GenKeyCommand.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ protected function configure(): void
2121

2222
protected function execute(InputInterface $input, OutputInterface $output): int
2323
{
24-
$encryption_key_256bit = base64_encode(openssl_random_pseudo_bytes(32));
24+
do {
25+
$encryption_key_256bit = openssl_random_pseudo_bytes(
26+
32,
27+
$innerStrong
28+
);
29+
// $bytes needs to be verified as well
30+
} while (!$encryption_key_256bit || !$innerStrong);
31+
$encryption_key_256bit = base64_encode($encryption_key_256bit);
32+
2533
$io = new SymfonyStyle($input, $output);
2634
$io->title('Generated Key');
2735
$io->success('Key is: ' . $encryption_key_256bit);

src/Encryptors/AesCbcEncryptor.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ public function encrypt(?string $data, ?string $columnName = null): ?string
6060
$key = $this->getSecretKey();
6161

6262
// Create a cipher of the appropriate length for this method.
63-
$ivsize = openssl_cipher_iv_length(self::METHOD);
64-
$iv = openssl_random_pseudo_bytes($ivsize);
63+
do {
64+
$iv = openssl_random_pseudo_bytes(
65+
openssl_cipher_iv_length(
66+
self::METHOD
67+
),
68+
$innerStrong
69+
);
70+
// $bytes needs to be verified as well
71+
} while (!$iv || !$innerStrong);
6572

6673
// Create the encryption.
6774
$ciphertext = openssl_encrypt(

src/Encryptors/AesGcmEncryptor.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ public function encrypt(?string $data, ?string $columnName = null): ?string
5858
}
5959

6060
$key = $this->getSecretKey();
61-
$ivsize = openssl_cipher_iv_length(self::METHOD);
62-
$iv = openssl_random_pseudo_bytes($ivsize);
61+
do {
62+
$iv = openssl_random_pseudo_bytes(
63+
openssl_cipher_iv_length(
64+
self::METHOD
65+
),
66+
$innerStrong
67+
);
68+
// $bytes needs to be verified as well
69+
} while (!$iv || !$innerStrong);
6370
$tag = '';
6471
$associatedData = $columnName ?? $this->defaultAssociatedData;
6572

@@ -70,7 +77,7 @@ public function encrypt(?string $data, ?string $columnName = null): ?string
7077
OPENSSL_RAW_DATA,
7178
$iv,
7279
$tag,
73-
$associatedData
80+
$associatedData ?? ''
7481
);
7582

7683
if ($ciphertext === false) {
@@ -112,7 +119,7 @@ public function decrypt(?string $data, ?string $columnName = null): ?string
112119
OPENSSL_RAW_DATA,
113120
$iv,
114121
$tag,
115-
$columnName
122+
$columnName ?? $this->defaultAssociatedData ?? ''
116123
);
117124

118125
if ($plaintext === false) {
@@ -154,4 +161,4 @@ private function getSecretKey(): string
154161

155162
return $key;
156163
}
157-
}
164+
}

tests/Unit/Command/GenKeyCommandTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace tests\Unit;
3+
namespace SpecShaper\EncryptBundle\Tests\Unit\Command;
44

55
use PHPUnit\Framework\TestCase;
66
use SpecShaper\EncryptBundle\Command\GenKeyCommand;
@@ -12,13 +12,15 @@ class GenKeyCommandTest extends TestCase
1212
{
1313
/**
1414
* Test that an encryption key of 43 characters (ending with =) is created.
15-
*
16-
* @test
1715
*/
1816
public function testExecute()
1917
{
2018
$application = new Application();
21-
$application->add(new GenKeyCommand());
19+
if (method_exists($application, 'addCommand')) {
20+
$application->addCommand(new GenKeyCommand());
21+
} else {
22+
$application->add(new GenKeyCommand());
23+
}
2224

2325
$command = $application->find('encrypt:genkey');
2426

tests/Unit/Encryptors/AesCbcEncryptorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 22:55.
77
*/
88

9-
namespace SpecShaper\EncryptBundle\tests\Unit\Encryptors;
9+
namespace SpecShaper\EncryptBundle\Tests\Unit\Encryptors;
1010

1111
use SpecShaper\EncryptBundle\Encryptors\AesCbcEncryptor;
1212
use Symfony\Component\EventDispatcher\EventDispatcher;

tests/Unit/Encryptors/AesGcmEncryptorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace SpecShaper\EncryptBundle\tests\Unit\Encryptors;
5+
namespace SpecShaper\EncryptBundle\Tests\Unit\Encryptors;
66

77
use SpecShaper\EncryptBundle\Encryptors\AesGcmEncryptor;
88
use Symfony\Component\EventDispatcher\EventDispatcher;

0 commit comments

Comments
 (0)