-
Notifications
You must be signed in to change notification settings - Fork 784
/
Copy pathKeysCommandTest.php
84 lines (64 loc) · 2.12 KB
/
KeysCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Laravel\Passport\Tests\Unit;
use Illuminate\Container\Container;
use Laravel\Passport\Console\KeysCommand;
use Laravel\Passport\Passport;
use Mockery as m;
use phpseclib\Crypt\RSA;
use PHPUnit\Framework\TestCase;
class KeysCommandTest extends TestCase
{
const KEYS = __DIR__.'/../keys';
const PUBLIC_KEY = self::KEYS.'/oauth-public.key';
const PRIVATE_KEY = self::KEYS.'/oauth-private.key';
protected function setUp(): void
{
parent::setUp();
@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);
}
protected function tearDown(): void
{
m::close();
@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);
}
public function testPrivateAndPublicKeysAreGenerated()
{
$command = m::mock(KeysCommand::class)
->makePartial()
->shouldReceive('info')
->with('Encryption keys generated successfully.')
->getMock();
Container::getInstance()->instance('path.storage', self::KEYS);
$rsa = new RSA();
$command->handle($rsa);
$this->assertFileExists(self::PUBLIC_KEY);
$this->assertFileExists(self::PRIVATE_KEY);
}
public function testPrivateAndPublicKeysAreGeneratedInCustomPath()
{
Passport::loadKeysFrom(self::KEYS);
$command = m::mock(KeysCommand::class)
->makePartial()
->shouldReceive('info')
->with('Encryption keys generated successfully.')
->getMock();
$command->handle(new RSA);
$this->assertFileExists(self::PUBLIC_KEY);
$this->assertFileExists(self::PRIVATE_KEY);
return $command;
}
/**
* @depends testPrivateAndPublicKeysAreGeneratedInCustomPath
*/
public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice($command)
{
$command->shouldReceive('option')
->with('force')
->andReturn(false);
$command->shouldReceive('error')
->with('Encryption keys already exist. Use the --force option to overwrite them.');
$command->handle(new RSA);
}
}