|
2 | 2 |
|
3 | 3 | namespace App\Tests\Functional; |
4 | 4 |
|
| 5 | +use App\Security\AdminUser; |
5 | 6 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6 | 7 |
|
7 | 8 | class DashboardTest extends WebTestCase |
@@ -91,4 +92,31 @@ public function testLoginCorrect(): void |
91 | 92 | $this->assertSelectorTextContains('h3.environment', 'Configured environment'); |
92 | 93 | $this->assertSelectorExists('nav.navbar'); |
93 | 94 | } |
| 95 | + |
| 96 | + /** |
| 97 | + * A plain `GET /logout` from any page the admin happens to visit used to end their session. |
| 98 | + */ |
| 99 | + public function testLogoutRequiresACsrfToken(): void |
| 100 | + { |
| 101 | + $client = static::createClient(); |
| 102 | + $client->loginUser(new AdminUser('admin', 'test')); |
| 103 | + |
| 104 | + $client->request('GET', '/logout'); |
| 105 | + $this->assertResponseStatusCodeSame(403); |
| 106 | + |
| 107 | + $client->request('GET', '/dashboard'); |
| 108 | + $this->assertResponseIsSuccessful('The session must survive a logout without a token'); |
| 109 | + } |
| 110 | + |
| 111 | + public function testLogoutWorksFromTheMenuLink(): void |
| 112 | + { |
| 113 | + $client = static::createClient(); |
| 114 | + $client->loginUser(new AdminUser('admin', 'test')); |
| 115 | + |
| 116 | + $crawler = $client->request('GET', '/dashboard'); |
| 117 | + $client->click($crawler->filter('a.dropdown-item')->selectLink('Logout')->link()); |
| 118 | + |
| 119 | + $client->request('GET', '/dashboard'); |
| 120 | + $this->assertResponseRedirects('/login'); |
| 121 | + } |
94 | 122 | } |
0 commit comments