-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrustProxiesTest.php
executable file
·49 lines (39 loc) · 1.29 KB
/
TrustProxiesTest.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
<?php
namespace GeTracker\LaravelVaporTrustedProxies\Tests;
use GeTracker\LaravelVaporTrustedProxies\LaravelVaporTrustedProxiesServiceProvider;
use Orchestra\Testbench\TestCase;
class TrustProxiesTest extends TestCase
{
protected function getPackageProviders($app)
{
return [LaravelVaporTrustedProxiesServiceProvider::class];
}
protected function setUp(): void
{
parent::setUp();
$_SERVER['VAPOR_ARTIFACT_NAME'] = 'laravel-vapor';
}
/** @test */
public function returns_localhost_when_not_running_in_vapor(): void
{
// Remove Vapor server variable
unset($_SERVER['VAPOR_ARTIFACT_NAME']);
$response = $this->get('/test-ip', [
'X-VAPOR-SOURCE-IP' => '2.2.2.2',
'X-FORWARDED-FOR' => '1.2.3.4, 2.2.2.2, 3.3.3.3',
]);
$response->assertStatus(200)
->assertJson(['127.0.0.1']);
}
/** @test */
public function returns_actual_user_ip_by_resolving_vapor_proxies(): void
{
$response = $this->get('/test-ip', [
'REMOTE_ADDR' => '127.0.0.1',
'X-VAPOR-SOURCE-IP' => '2.2.2.2',
'X-FORWARDED-FOR' => '1.2.3.4, 2.2.2.2, 3.3.3.3',
]);
$response->assertStatus(200)
->assertJson(['1.2.3.4']);
}
}