Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c10e9c6

Browse files
committedNov 26, 2021
wip
1 parent 08f0b94 commit c10e9c6

File tree

4 files changed

+37
-90
lines changed

4 files changed

+37
-90
lines changed
 

‎src/Console/KeysCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class KeysCommand extends Command
2929
/**
3030
* Execute the console command.
3131
*
32-
* @return void
32+
* @return int
3333
*/
3434
public function handle()
3535
{
@@ -40,6 +40,8 @@ public function handle()
4040

4141
if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) {
4242
$this->error('Encryption keys already exist. Use the --force option to overwrite them.');
43+
44+
return 1;
4345
} else {
4446
if (class_exists(LegacyRSA::class)) {
4547
$keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096);
@@ -55,5 +57,7 @@ public function handle()
5557

5658
$this->info('Encryption keys generated successfully.');
5759
}
60+
61+
return 0;
5862
}
5963
}

‎tests/Feature/KeysCommandTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Laravel\Passport\Tests\Feature;
4+
5+
use Mockery as m;
6+
7+
class KeysCommandTest extends PassportTestCase
8+
{
9+
protected function tearDown(): void
10+
{
11+
m::close();
12+
13+
@unlink(self::PUBLIC_KEY);
14+
@unlink(self::PRIVATE_KEY);
15+
}
16+
17+
public function testPrivateAndPublicKeysAreGenerated()
18+
{
19+
$this->assertFileExists(self::PUBLIC_KEY);
20+
$this->assertFileExists(self::PRIVATE_KEY);
21+
}
22+
23+
public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice()
24+
{
25+
$this->artisan('passport:keys')
26+
->assertFailed()
27+
->expectsOutput('Encryption keys already exist. Use the --force option to overwrite them.');
28+
}
29+
}

‎tests/Feature/PassportTestCase.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class PassportTestCase extends TestCase
1212
{
1313
use RefreshDatabase;
1414

15-
const KEYS = __DIR__.'/keys';
15+
const KEYS = __DIR__.'/../keys';
1616
const PUBLIC_KEY = self::KEYS.'/oauth-public.key';
1717
const PRIVATE_KEY = self::KEYS.'/oauth-private.key';
1818

@@ -24,6 +24,8 @@ protected function setUp(): void
2424

2525
Passport::routes();
2626

27+
Passport::loadKeysFrom(self::KEYS);
28+
2729
@unlink(self::PUBLIC_KEY);
2830
@unlink(self::PRIVATE_KEY);
2931

‎tests/Unit/KeysCommandTest.php

-88
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.