File tree Expand file tree Collapse file tree 3 files changed +41
-9
lines changed Expand file tree Collapse file tree 3 files changed +41
-9
lines changed Original file line number Diff line number Diff line change 2222 "illuminate/http" : " ~5.3" ,
2323 "illuminate/support" : " ~5.3" ,
2424 "league/oauth2-server" : " ~5.0" ,
25- "symfony/process" : " ~3.1" ,
2625 "symfony/psr-http-message-bridge" : " ^0.3.0" ,
27- "zendframework/zend-diactoros" : " ~1.0"
26+ "zendframework/zend-diactoros" : " ~1.0" ,
27+ "phpseclib/phpseclib" : " ^2.0"
2828 },
2929 "require-dev" : {
3030 "mockery/mockery" : " ~0.9" ,
Original file line number Diff line number Diff line change 22
33namespace Laravel \Passport \Console ;
44
5+ use phpseclib \Crypt \RSA ;
56use Illuminate \Console \Command ;
6- use Symfony \Component \Process \Process ;
77
88class KeysCommand extends Command
99{
@@ -24,16 +24,15 @@ class KeysCommand extends Command
2424 /**
2525 * Execute the console command.
2626 *
27+ * @param RSA $rsa
2728 * @return mixed
2829 */
29- public function handle ()
30+ public function handle (RSA $ rsa )
3031 {
31- $ callback = function ($ type , $ line ) {
32- $ this ->output ->write ($ line );
33- };
32+ $ keys = $ rsa ->createKey (4096 );
3433
35- ( new Process ( ' openssl genrsa -out oauth-private.key 4096 ' , storage_path ()))-> run ( $ callback );
36- ( new Process ( ' openssl rsa -in oauth-private.key -pubout -out oauth- public.key ', storage_path ()))-> run ( $ callback );
34+ file_put_contents ( storage_path ( ' oauth-private.key ' ), array_get ( $ keys , ' privatekey ' ) );
35+ file_put_contents ( storage_path ( ' oauth-public.key '), array_get ( $ keys , ' publickey ' ) );
3736
3837 $ this ->info ('Encryption keys generated successfully. ' );
3938 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ function storage_path ($ file = null )
4+ {
5+ return __DIR__ . DIRECTORY_SEPARATOR . $ file ;
6+ }
7+
8+ class KeysCommandTest extends PHPUnit_Framework_TestCase
9+ {
10+ public function tearDown ()
11+ {
12+ Mockery::close ();
13+
14+ @unlink (storage_path ('oauth-private.key ' ));
15+ @unlink (storage_path ('oauth-public.key ' ));
16+ }
17+
18+ public function testPrivateAndPublicKeysAreGenerated ()
19+ {
20+ $ command = Mockery::mock (\Laravel \Passport \Console \KeysCommand::class)
21+ ->makePartial ()
22+ ->shouldReceive ('info ' )
23+ ->with ('Encryption keys generated successfully. ' )
24+ ->getMock ();
25+
26+ $ rsa = new \phpseclib \Crypt \RSA ();
27+
28+ $ command ->handle ($ rsa );
29+
30+ $ this ->assertFileExists (storage_path ('oauth-private.key ' ));
31+ $ this ->assertFileExists (storage_path ('oauth-public.key ' ));
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments