Skip to content

Commit 348963c

Browse files
committed
Tests and ECS
1 parent 633e88a commit 348963c

File tree

10 files changed

+44
-43
lines changed

10 files changed

+44
-43
lines changed

rector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
2626
$parameters->set(Option::PARALLEL, true);
2727
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
28-
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
2928

3029
$services = $containerConfigurator->services();
3130
$services->set(TypedPropertyRector::class);

src/Component/Console/EcKeysetGeneratorCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use function is_string;
109
use Jose\Component\Core\JWKSet;
1110
use Jose\Component\KeyManagement\JWKFactory;
@@ -28,7 +27,7 @@ protected function configure(): void
2827

2928
protected function execute(InputInterface $input, OutputInterface $output): int
3029
{
31-
$quantity = (int)$input->getArgument('quantity');
30+
$quantity = (int) $input->getArgument('quantity');
3231
if ($quantity < 1) {
3332
throw new InvalidArgumentException('Invalid quantity');
3433
}

src/Component/Console/OctKeyGeneratorCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use Jose\Component\KeyManagement\JWKFactory;
109
use Symfony\Component\Console\Input\InputArgument;
1110
use Symfony\Component\Console\Input\InputInterface;
@@ -25,7 +24,7 @@ protected function configure(): void
2524

2625
protected function execute(InputInterface $input, OutputInterface $output): int
2726
{
28-
$size = (int)$input->getArgument('size');
27+
$size = (int) $input->getArgument('size');
2928
if ($size < 1) {
3029
throw new InvalidArgumentException('Invalid size');
3130
}

src/Component/Console/OctKeysetGeneratorCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use Jose\Component\Core\JWKSet;
109
use Jose\Component\KeyManagement\JWKFactory;
1110
use Symfony\Component\Console\Input\InputArgument;
@@ -27,8 +26,8 @@ protected function configure(): void
2726

2827
protected function execute(InputInterface $input, OutputInterface $output): int
2928
{
30-
$quantity = (int)$input->getArgument('quantity');
31-
$size = (int)$input->getArgument('size');
29+
$quantity = (int) $input->getArgument('quantity');
30+
$size = (int) $input->getArgument('size');
3231
if ($quantity < 1) {
3332
throw new InvalidArgumentException('Invalid quantity');
3433
}

src/Component/Console/OkpKeysetGeneratorCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use function is_string;
109
use Jose\Component\Core\JWKSet;
1110
use Jose\Component\KeyManagement\JWKFactory;
@@ -28,7 +27,7 @@ protected function configure(): void
2827

2928
protected function execute(InputInterface $input, OutputInterface $output): int
3029
{
31-
$quantity = (int)$input->getArgument('quantity');
30+
$quantity = (int) $input->getArgument('quantity');
3231
$curve = $input->getArgument('curve');
3332
if ($quantity < 1) {
3433
throw new InvalidArgumentException('Invalid quantity');

src/Component/Console/RsaKeyGeneratorCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use Jose\Component\KeyManagement\JWKFactory;
109
use Symfony\Component\Console\Input\InputArgument;
1110
use Symfony\Component\Console\Input\InputInterface;
@@ -25,7 +24,7 @@ protected function configure(): void
2524

2625
protected function execute(InputInterface $input, OutputInterface $output): int
2726
{
28-
$size = (int)$input->getArgument('size');
27+
$size = (int) $input->getArgument('size');
2928
$args = $this->getOptions($input);
3029
if ($size < 1) {
3130
throw new InvalidArgumentException('Invalid size');

src/Component/Console/RsaKeysetGeneratorCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Jose\Component\Console;
66

77
use InvalidArgumentException;
8-
use function is_int;
98
use Jose\Component\Core\JWKSet;
109
use Jose\Component\KeyManagement\JWKFactory;
1110
use Symfony\Component\Console\Input\InputArgument;
@@ -27,8 +26,8 @@ protected function configure(): void
2726

2827
protected function execute(InputInterface $input, OutputInterface $output): int
2928
{
30-
$quantity = (int)$input->getArgument('quantity');
31-
$size = (int)$input->getArgument('size');
29+
$quantity = (int) $input->getArgument('quantity');
30+
$size = (int) $input->getArgument('size');
3231
if ($quantity < 1) {
3332
throw new InvalidArgumentException('Invalid quantity');
3433
}

src/Component/Encryption/Algorithm/KeyEncryption/KeyWrapping.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ interface KeyWrapping extends KeyEncryptionAlgorithm
1212
/**
1313
* Encrypt the CEK.
1414
*
15-
* @param \Jose\Component\Core\JWK $key The key used to wrap the CEK
16-
* @param string $cek The CEK to encrypt
17-
* @param array $completeHeader The complete header of the JWT
18-
* @param array $additionalHeader The complete header of the JWT
15+
* @param JWK $key The key used to wrap the CEK
16+
* @param string $cek The CEK to encrypt
17+
* @param array $completeHeader The complete header of the JWT
18+
* @param array $additionalHeader The complete header of the JWT
1919
*/
2020
public function wrapKey(JWK $key, string $cek, array $completeHeader, array &$additionalHeader): string;
2121

2222
/**
2323
* Decrypt de CEK.
2424
*
25-
* @param \Jose\Component\Core\JWK $key The key used to wrap the CEK
26-
* @param string $encrypted_cek The CEK to decrypt
27-
* @param array $completeHeader The complete header of the JWT
25+
* @param JWK $key The key used to wrap the CEK
26+
* @param string $encrypted_cek The CEK to decrypt
27+
* @param array $completeHeader The complete header of the JWT
2828
*/
2929
public function unwrapKey(JWK $key, string $encrypted_cek, array $completeHeader): string;
3030
}

src/Component/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@ public function analyze(JWK $jwk, MessageBag $bag): void
2323
return;
2424
}
2525
$k = Base64UrlSafe::decode($k);
26-
if (class_exists(Zxcvbn::class)) {
27-
$zxcvbn = new Zxcvbn();
28-
$strength = $zxcvbn->passwordStrength($k);
26+
if (! class_exists(Zxcvbn::class)) {
27+
return;
28+
}
29+
$zxcvbn = new Zxcvbn();
30+
$strength = $zxcvbn->passwordStrength($k);
2931

30-
switch (true) {
31-
case $strength['score'] < 3:
32-
$bag->add(
33-
Message::high(
34-
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
35-
)
36-
);
32+
switch (true) {
33+
case $strength['score'] < 3:
34+
$bag->add(
35+
Message::high(
36+
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
37+
)
38+
);
3739

38-
break;
40+
break;
3941

40-
case $strength['score'] === 3:
41-
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));
42+
case $strength['score'] === 3:
43+
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));
4244

43-
break;
45+
break;
4446

45-
default:
46-
break;
47-
}
47+
default:
48+
break;
4849
}
4950
}
5051
}

tests/Component/Console/KeySetCreationCommandTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function iCanCreateAnEllipticCurveKeySetWithCurveP256(): void
7878

7979
$command->run($input, $output);
8080
$content = $output->fetch();
81-
JWKSet::createFromJson($content);
81+
$jwkset = JWKSet::createFromJson($content);
82+
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
8283
}
8384

8485
/**
@@ -96,6 +97,9 @@ public function iCannotCreateAnOctetKeySetWithoutKeySetSize(): void
9697
$command = new OctKeysetGeneratorCommand();
9798

9899
$command->run($input, $output);
100+
$content = $output->fetch();
101+
$jwkset = JWKSet::createFromJson($content);
102+
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
99103
}
100104

101105
/**
@@ -113,7 +117,8 @@ public function iCanCreateAnOctetKeySet(): void
113117

114118
$command->run($input, $output);
115119
$content = $output->fetch();
116-
JWKSet::createFromJson($content);
120+
$jwkset = JWKSet::createFromJson($content);
121+
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
117122
}
118123

119124
/**
@@ -148,7 +153,8 @@ public function iCanCreateAnOctetKeySetPair(): void
148153

149154
$command->run($input, $output);
150155
$content = $output->fetch();
151-
JWKSet::createFromJson($content);
156+
$jwkset = JWKSet::createFromJson($content);
157+
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
152158
}
153159

154160
/**
@@ -183,6 +189,7 @@ public function iCanCreateAnRsaKeySet(): void
183189

184190
$command->run($input, $output);
185191
$content = $output->fetch();
186-
JWKSet::createFromJson($content);
192+
$jwkset = JWKSet::createFromJson($content);
193+
static::assertCount(2, $jwkset, 'Invalid number of keys in the keyset');
187194
}
188195
}

0 commit comments

Comments
 (0)