|
| 1 | +<?php |
| 2 | + |
| 3 | +use Laravel\Passport\Passport; |
| 4 | +use PHPUnit\Framework\TestCase; |
| 5 | +use Illuminate\Config\Repository as Config; |
| 6 | +use Laravel\Passport\PassportServiceProvider; |
| 7 | +use Illuminate\Contracts\Foundation\Application as App; |
| 8 | + |
| 9 | +class PassportServiceProviderTest extends TestCase |
| 10 | +{ |
| 11 | + public function test_can_use_crypto_keys_from_config() |
| 12 | + { |
| 13 | + $config = Mockery::mock(Config::class, function ($config) { |
| 14 | + $config->shouldReceive('get') |
| 15 | + ->with('passport.private_key') |
| 16 | + ->andReturn('-----BEGIN RSA PRIVATE KEY-----\nconfig\n-----END RSA PRIVATE KEY-----'); |
| 17 | + }); |
| 18 | + |
| 19 | + $provider = new PassportServiceProvider( |
| 20 | + Mockery::mock(App::class, ['make' => $config]) |
| 21 | + ); |
| 22 | + |
| 23 | + // Call protected makeCryptKey method |
| 24 | + $cryptKey = (function () { |
| 25 | + return $this->makeCryptKey('private'); |
| 26 | + })->call($provider); |
| 27 | + |
| 28 | + $this->assertSame( |
| 29 | + "-----BEGIN RSA PRIVATE KEY-----\nconfig\n-----END RSA PRIVATE KEY-----", |
| 30 | + file_get_contents($cryptKey->getKeyPath()) |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function test_can_use_crypto_keys_from_local_disk() |
| 35 | + { |
| 36 | + Passport::loadKeysFrom(__DIR__.'/files'); |
| 37 | + |
| 38 | + file_put_contents( |
| 39 | + __DIR__.'/files/oauth-private.key', |
| 40 | + "-----BEGIN RSA PRIVATE KEY-----\ndisk\n-----END RSA PRIVATE KEY-----" |
| 41 | + ); |
| 42 | + |
| 43 | + $config = Mockery::mock(Config::class, function ($config) { |
| 44 | + $config->shouldReceive('get')->with('passport.private_key')->andReturn(null); |
| 45 | + }); |
| 46 | + |
| 47 | + $provider = new PassportServiceProvider( |
| 48 | + Mockery::mock(App::class, ['make' => $config]) |
| 49 | + ); |
| 50 | + |
| 51 | + // Call protected makeCryptKey method |
| 52 | + $cryptKey = (function () { |
| 53 | + return $this->makeCryptKey('private'); |
| 54 | + })->call($provider); |
| 55 | + |
| 56 | + $this->assertSame( |
| 57 | + "-----BEGIN RSA PRIVATE KEY-----\ndisk\n-----END RSA PRIVATE KEY-----", |
| 58 | + file_get_contents($cryptKey->getKeyPath()) |
| 59 | + ); |
| 60 | + |
| 61 | + @unlink(__DIR__.'/files/oauth-private.key'); |
| 62 | + } |
| 63 | +} |
0 commit comments