1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Spiral Framework. |
4
|
|
|
* |
5
|
|
|
* @license MIT |
6
|
|
|
* @author Anton Titov (Wolfy-J) |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Spiral\Framework\Encrypter; |
11
|
|
|
|
12
|
|
|
use Spiral\Encrypter\EncrypterFactory; |
13
|
|
|
use Spiral\Framework\ConsoleTest; |
14
|
|
|
|
15
|
|
|
class KeyCommandTest extends ConsoleTest |
16
|
|
|
{ |
17
|
|
|
public function testKey() |
18
|
|
|
{ |
19
|
|
|
$key = $this->runCommand('encrypt:key'); |
20
|
|
|
$this->assertNotEmpty($key); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testMountFileNotFound() |
24
|
|
|
{ |
25
|
|
|
$out = $this->runCommand('encrypt:key', [ |
26
|
|
|
'-m' => __DIR__ . '/.env' |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
$this->assertContains('Unable to find', $out); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testReplace() |
33
|
|
|
{ |
34
|
|
|
file_put_contents(__DIR__ . '/.env', '{encrypt-key}'); |
35
|
|
|
|
36
|
|
|
$out = $this->runCommand('encrypt:key', [ |
37
|
|
|
'-m' => __DIR__ . '/.env' |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$this->assertContains('key has been updated', $out); |
41
|
|
|
|
42
|
|
|
$body = file_get_contents(__DIR__ . '/.env'); |
43
|
|
|
$this->assertContains($body, $out); |
44
|
|
|
|
45
|
|
|
unlink(__DIR__ . '/.env'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testReplaceCurrent() |
49
|
|
|
{ |
50
|
|
|
$key = $this->app->get(EncrypterFactory::class)->generateKey(); |
51
|
|
|
|
52
|
|
|
$app = $this->makeApp([ |
53
|
|
|
'ENCRYPTER_KEY' => $key |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
file_put_contents(__DIR__ . '/.env', $key); |
57
|
|
|
|
58
|
|
|
$out = $app->console()->run('encrypt:key', [ |
59
|
|
|
'-m' => __DIR__ . '/.env' |
60
|
|
|
]); |
61
|
|
|
$out = $out->getOutput()->fetch(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->assertContains('key has been updated', $out); |
64
|
|
|
|
65
|
|
|
$body = file_get_contents(__DIR__ . '/.env'); |
66
|
|
|
$this->assertContains($body, $out); |
67
|
|
|
|
68
|
|
|
unlink(__DIR__ . '/.env'); |
69
|
|
|
} |
70
|
|
|
} |