forked from statamic/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneHomeTest.php
82 lines (63 loc) · 2.37 KB
/
PhoneHomeTest.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
<?php
namespace Tests;
use Statamic\Licensing\Outpost;
class PhoneHomeTest extends TestCase
{
/**
* @test
*
* @dataProvider algorithmProvider
*/
public function it_contacts_the_outpost($algo)
{
$this->assertTrue(app('router')->getRoutes()->hasNamedRoute('statamic.phone-home'));
config(['statamic.system.license_key' => 'test-key']);
// Assume that the key is hashed and base64 encoded. The base 64 encoding is necessary
// because the hash might include a slash which would screw with the route parameter.
$key = base64_encode(password_hash('test-key', $algo));
$this->mock(Outpost::class)->shouldReceive('radio')->once();
$this->get($url = '/et/phone/home/'.$key)->assertOk();
// Assert that the route is rate limited to once per minute.
$this->get($url)->assertStatus(429);
}
public static function algorithmProvider()
{
return [
'default' => [PASSWORD_DEFAULT],
'bcrypt' => [PASSWORD_BCRYPT],
'argon2i' => [PASSWORD_ARGON2I],
'argon2id' => [PASSWORD_ARGON2ID],
];
}
/**
* @test
*
* @define-env disablePhoneHome
*/
public function it_does_not_contact_the_outpost_if_disabled()
{
config(['statamic.system.license_key' => 'test-key']);
$key = base64_encode(password_hash('test-key', PASSWORD_BCRYPT));
$this->mock(Outpost::class)->shouldReceive('radio')->never();
$this->assertFalse(app('router')->getRoutes()->hasNamedRoute('statamic.phone-home'));
$this->get('/et/phone/home/'.$key)->assertNotFound();
}
public function disablePhoneHome($app)
{
$app['config']->set('statamic.system.phone_home_route_enabled', false);
}
/** @test */
public function it_does_not_contact_the_outpost_when_an_incorrect_key_is_provided()
{
config(['statamic.system.license_key' => 'test-key']);
$this->mock(Outpost::class)->shouldReceive('radio')->never();
$this->get('/et/phone/home/invalid')->assertNotFound();
}
/** @test */
public function it_does_not_contact_the_outpost_when_key_is_missing()
{
config(['statamic.system.license_key' => 'test-key']);
$this->mock(Outpost::class)->shouldReceive('radio')->never();
$this->get('/et/phone/home')->assertNotFound();
}
}