Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Nov 26, 2021
1 parent 6113d63 commit 6ed9408
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 90 deletions.
6 changes: 5 additions & 1 deletion src/Console/KeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KeysCommand extends Command
/**
* Execute the console command.
*
* @return void
* @return int
*/
public function handle()
{
Expand All @@ -40,6 +40,8 @@ public function handle()

if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) {
$this->error('Encryption keys already exist. Use the --force option to overwrite them.');

return 1;
} else {
if (class_exists(LegacyRSA::class)) {
$keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096);
Expand All @@ -55,5 +57,7 @@ public function handle()

$this->info('Encryption keys generated successfully.');
}

return 0;
}
}
29 changes: 29 additions & 0 deletions tests/Feature/KeysCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Laravel\Passport\Tests\Feature;

use Mockery as m;

class KeysCommandTest extends PassportTestCase
{
protected function tearDown(): void
{
m::close();

@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);
}

public function testPrivateAndPublicKeysAreGenerated()
{
$this->assertFileExists(self::PUBLIC_KEY);
$this->assertFileExists(self::PRIVATE_KEY);
}

public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice()
{
$this->artisan('passport:keys')
->assertFailed()
->expectsOutput('Encryption keys already exist. Use the --force option to overwrite them.');
}
}
4 changes: 3 additions & 1 deletion tests/Feature/PassportTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class PassportTestCase extends TestCase
{
use RefreshDatabase;

const KEYS = __DIR__.'/keys';
const KEYS = __DIR__.'/../keys';
const PUBLIC_KEY = self::KEYS.'/oauth-public.key';
const PRIVATE_KEY = self::KEYS.'/oauth-private.key';

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

Passport::routes();

Passport::loadKeysFrom(self::KEYS);

@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);

Expand Down
88 changes: 0 additions & 88 deletions tests/Unit/KeysCommandTest.php

This file was deleted.

0 comments on commit 6ed9408

Please sign in to comment.