File tree 4 files changed +37
-90
lines changed
4 files changed +37
-90
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class KeysCommand extends Command
29
29
/**
30
30
* Execute the console command.
31
31
*
32
- * @return void
32
+ * @return int
33
33
*/
34
34
public function handle ()
35
35
{
@@ -40,6 +40,8 @@ public function handle()
40
40
41
41
if ((file_exists ($ publicKey ) || file_exists ($ privateKey )) && ! $ this ->option ('force ' )) {
42
42
$ this ->error ('Encryption keys already exist. Use the --force option to overwrite them. ' );
43
+
44
+ return 1 ;
43
45
} else {
44
46
if (class_exists (LegacyRSA::class)) {
45
47
$ keys = (new LegacyRSA )->createKey ($ this ->input ? (int ) $ this ->option ('length ' ) : 4096 );
@@ -55,5 +57,7 @@ public function handle()
55
57
56
58
$ this ->info ('Encryption keys generated successfully. ' );
57
59
}
60
+
61
+ return 0 ;
58
62
}
59
63
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ abstract class PassportTestCase extends TestCase
12
12
{
13
13
use RefreshDatabase;
14
14
15
- const KEYS = __DIR__ .'/keys ' ;
15
+ const KEYS = __DIR__ .'/../ keys ' ;
16
16
const PUBLIC_KEY = self ::KEYS .'/oauth-public.key ' ;
17
17
const PRIVATE_KEY = self ::KEYS .'/oauth-private.key ' ;
18
18
@@ -24,6 +24,8 @@ protected function setUp(): void
24
24
25
25
Passport::routes ();
26
26
27
+ Passport::loadKeysFrom (self ::KEYS );
28
+
27
29
@unlink (self ::PUBLIC_KEY );
28
30
@unlink (self ::PRIVATE_KEY );
29
31
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments