2FAuth/tests/Feature/Http/Middlewares/AuthenticateMiddlewareTest.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2022-03-31 08:38:35 +02:00
<?php
namespace Tests\Feature\Http\Middlewares;
use Illuminate\Support\Facades\Config;
2022-11-22 15:15:52 +01:00
use Tests\FeatureTestCase;
2022-03-31 08:38:35 +02:00
class AuthenticateMiddlewareTest extends FeatureTestCase
{
private const USER_NAME = 'John';
2022-11-22 15:15:52 +01:00
2022-03-31 08:38:35 +02:00
private const USER_EMAIL = 'john@example.com';
/**
* @test
*/
public function test_it_always_authenticates_with_reverse_proxy_guard()
{
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
2022-11-22 15:15:52 +01:00
2022-03-31 08:38:35 +02:00
$this->app['auth']->shouldUse('reverse-proxy-guard');
$this->json('GET', '/api/v1/groups', [], ['HTTP_REMOTE_USER' => self::USER_NAME]);
$this->assertAuthenticated('reverse-proxy-guard');
}
/**
* @test
*/
public function test_it_does_not_authenticate_with_empty_header()
{
Config::set('auth.auth_proxy_headers.user', 'HTTP_REMOTE_USER');
Config::set('auth.auth_proxy_headers.email', 'HTTP_REMOTE_EMAIL');
$this->app['auth']->shouldUse('reverse-proxy-guard');
$this->json('GET', '/api/v1/groups', [], [
2022-11-22 15:15:52 +01:00
'HTTP_REMOTE_USER' => '',
'HTTP_REMOTE_EMAIL' => '',
2022-05-23 11:39:10 +02:00
])->assertStatus(407);
2022-03-31 08:38:35 +02:00
}
/**
* @test
*/
public function test_it_does_not_authenticate_with_missing_header()
{
$this->app['auth']->shouldUse('reverse-proxy-guard');
$this->json('GET', '/api/v1/groups', [], [])
2022-05-23 11:39:10 +02:00
->assertStatus(407);
2022-03-31 08:38:35 +02:00
}
2022-11-22 15:15:52 +01:00
}