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