Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Sep 29, 2024
1 parent bb68c3d commit 1214b3d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 79 deletions.
3 changes: 1 addition & 2 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DateInterval;
use Illuminate\Auth\Events\Logout;
use Illuminate\Config\Repository as Config;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
Expand Down Expand Up @@ -249,7 +248,7 @@ protected function registerResourceServer(): void
*/
protected function makeCryptKey(string $type): CryptKey
{
$key = str_replace('\\n', "\n", $this->app->make(Config::class)->get("passport.{$type}_key") ?? '');
$key = str_replace('\\n', "\n", config("passport.{$type}_key") ?? '');

if (! $key) {
$key = 'file://'.Passport::keyPath('oauth-'.$type.'.key');
Expand Down
56 changes: 56 additions & 0 deletions tests/Feature/PassportServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Laravel\Passport\Tests\Feature;

use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;

class PassportServiceProviderTest extends PassportTestCase
{
protected function tearDown(): void
{
@unlink(__DIR__.'/../keys/oauth-private.key');
}

public function test_can_use_crypto_keys_from_config()
{
$privateKey = openssl_pkey_new();

openssl_pkey_export($privateKey, $privateKeyString);

config(['passport.private_key' => $privateKeyString]);

$provider = new PassportServiceProvider($this->app);

// Call protected makeCryptKey method
$cryptKey = (fn () => $this->makeCryptKey('private'))->call($provider);

$this->assertSame(
$privateKeyString,
$cryptKey->getKeyContents()
);
}

public function test_can_use_crypto_keys_from_local_disk()
{
Passport::loadKeysFrom(__DIR__.'/../keys');

$privateKey = openssl_pkey_new();

openssl_pkey_export_to_file($privateKey, __DIR__.'/../keys/oauth-private.key');
openssl_pkey_export($privateKey, $privateKeyString);
chmod(__DIR__.'/../keys/oauth-private.key', 0600);

config(['passport.private_key' => null]);

$provider = new PassportServiceProvider($this->app);

// Call protected makeCryptKey method
$cryptKey = (fn () => $this->makeCryptKey('private'))->call($provider);

$this->assertSame(
$privateKeyString,
file_get_contents($cryptKey->getKeyPath())
);
}
}
77 changes: 0 additions & 77 deletions tests/Unit/PassportServiceProviderTest.php

This file was deleted.

0 comments on commit 1214b3d

Please sign in to comment.