From 1214b3d1eeebcc12596adf520a63f819d277c6d1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sun, 29 Sep 2024 10:25:44 +0330 Subject: [PATCH] formatting --- src/PassportServiceProvider.php | 3 +- tests/Feature/PassportServiceProviderTest.php | 56 ++++++++++++++ tests/Unit/PassportServiceProviderTest.php | 77 ------------------- 3 files changed, 57 insertions(+), 79 deletions(-) create mode 100644 tests/Feature/PassportServiceProviderTest.php delete mode 100644 tests/Unit/PassportServiceProviderTest.php diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index 6d10a915..d2abfd45 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -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; @@ -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'); diff --git a/tests/Feature/PassportServiceProviderTest.php b/tests/Feature/PassportServiceProviderTest.php new file mode 100644 index 00000000..37ccab41 --- /dev/null +++ b/tests/Feature/PassportServiceProviderTest.php @@ -0,0 +1,56 @@ + $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()) + ); + } +} diff --git a/tests/Unit/PassportServiceProviderTest.php b/tests/Unit/PassportServiceProviderTest.php deleted file mode 100644 index f4ad5459..00000000 --- a/tests/Unit/PassportServiceProviderTest.php +++ /dev/null @@ -1,77 +0,0 @@ -shouldReceive('get') - ->with('passport.private_key') - ->andReturn($privateKeyString); - }); - - $provider = new PassportServiceProvider( - m::mock(App::class, ['make' => $config]) - ); - - // Call protected makeCryptKey method - $cryptKey = (function () { - return $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 = m::mock(Config::class, function ($config) { - $config->shouldReceive('get')->with('passport.private_key')->andReturn(null); - }); - - $provider = new PassportServiceProvider( - m::mock(App::class, ['make' => $config]) - ); - - // Call protected makeCryptKey method - $cryptKey = (function () { - return $this->makeCryptKey('private'); - })->call($provider); - - $this->assertSame( - $privateKeyString, - file_get_contents($cryptKey->getKeyPath()) - ); - } -}