11<?php
22
3- namespace Kirby \Cms ;
3+ namespace Kirby \Auth ;
44
5+ use Kirby \Cms \App ;
56use Kirby \Filesystem \Dir ;
7+ use Kirby \TestCase ;
68use PHPUnit \Framework \Attributes \CoversClass ;
79
8- #[CoversClass(Auth ::class)]
9- class AuthCsrfTest extends TestCase
10+ #[CoversClass(Csrf ::class)]
11+ class CsrfTest extends TestCase
1012{
11- public const string TMP = KIRBY_TMP_DIR . '/Cms.AuthCsrf ' ;
13+ public const string TMP = KIRBY_TMP_DIR . '/Auth.Csrf ' ;
1214
13- protected Auth $ auth ;
15+ protected Csrf $ csrf ;
1416
1517 public function setUp (): void
1618 {
@@ -20,7 +22,7 @@ public function setUp(): void
2022 ],
2123 ]);
2224
23- $ this ->auth = new Auth ($ this ->app );
25+ $ this ->csrf = new Csrf ($ this ->app );
2426 }
2527
2628 public function tearDown (): void
@@ -30,96 +32,96 @@ public function tearDown(): void
3032 $ _GET = [];
3133 }
3234
33- public function testCsrfFromSession1 (): void
35+ public function testFromSession1 (): void
3436 {
3537 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
3638
3739 $ _GET = [];
38- $ this ->assertFalse ($ this ->auth -> csrf ());
40+ $ this ->assertFalse ($ this ->csrf -> get ());
3941 }
4042
41- public function testCsrfFromSession2 (): void
43+ public function testFromSession2 (): void
4244 {
4345 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
4446
4547 $ _GET = ['csrf ' => '' ];
46- $ this ->assertFalse ($ this ->auth -> csrf ());
48+ $ this ->assertFalse ($ this ->csrf -> get ());
4749 }
4850
49- public function testCsrfFromSession3 (): void
51+ public function testFromSession3 (): void
5052 {
5153 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
5254
5355 $ _GET = ['csrf ' => 'session-csrf ' ];
54- $ this ->assertSame ('session-csrf ' , $ this ->auth -> csrf ());
56+ $ this ->assertSame ('session-csrf ' , $ this ->csrf -> get ());
5557 }
5658
57- public function testCsrfFromSession4 (): void
59+ public function testFromSession4 (): void
5860 {
5961 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
6062
6163 $ _GET = ['csrf ' => 'invalid-csrf ' ];
62- $ this ->assertFalse ($ this ->auth -> csrf ());
64+ $ this ->assertFalse ($ this ->csrf -> get ());
6365 }
6466
65- public function testCsrfFromOption1 (): void
67+ public function testGet1 (): void
6668 {
6769 $ this ->app = $ this ->app ->clone ([
6870 'options ' => [
6971 'api.csrf ' => 'option-csrf '
7072 ]
7173 ]);
72- $ this ->auth = new Auth ($ this ->app );
7374
75+ $ this ->csrf = new Csrf ($ this ->app );
7476 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
7577
7678 $ _GET = [];
77- $ this ->assertFalse ($ this ->auth -> csrf ());
79+ $ this ->assertFalse ($ this ->csrf -> get ());
7880 }
7981
80- public function testCsrfFromOption2 (): void
82+ public function testGet2 (): void
8183 {
8284 $ this ->app = $ this ->app ->clone ([
8385 'options ' => [
8486 'api.csrf ' => 'option-csrf '
8587 ]
8688 ]);
87- $ this ->auth = new Auth ($ this ->app );
8889
90+ $ this ->csrf = new Csrf ($ this ->app );
8991 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
9092
9193 $ _GET = ['csrf ' => 'option-csrf ' ];
92- $ this ->assertSame ('option-csrf ' , $ this ->auth -> csrf ());
94+ $ this ->assertSame ('option-csrf ' , $ this ->csrf -> get ());
9395 }
9496
95- public function testCsrfFromOption3 (): void
97+ public function testGet3 (): void
9698 {
9799 $ this ->app = $ this ->app ->clone ([
98100 'options ' => [
99101 'api.csrf ' => 'option-csrf '
100102 ]
101103 ]);
102- $ this ->auth = new Auth ($ this ->app );
103104
105+ $ this ->csrf = new Csrf ($ this ->app );
104106 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
105107
106108 $ _GET = ['csrf ' => 'session-csrf ' ];
107- $ this ->assertFalse ($ this ->auth -> csrf ());
109+ $ this ->assertFalse ($ this ->csrf -> get ());
108110 }
109111
110- public function testCsrfFromOption4 (): void
112+ public function testGet4 (): void
111113 {
112114 $ this ->app = $ this ->app ->clone ([
113115 'options ' => [
114116 'api.csrf ' => 'option-csrf '
115117 ]
116118 ]);
117- $ this ->auth = new Auth ($ this ->app );
118119
120+ $ this ->csrf = new Csrf ($ this ->app );
119121 $ this ->app ->session ()->set ('kirby.csrf ' , 'session-csrf ' );
120122
121123 $ _GET = ['csrf ' => 'invalid-csrf ' ];
122- $ this ->assertFalse ($ this ->auth -> csrf ());
124+ $ this ->assertFalse ($ this ->csrf -> get ());
123125 }
124126
125127 public function testCsrfFromSessionPanelDevOption (): void
@@ -129,7 +131,9 @@ public function testCsrfFromSessionPanelDevOption(): void
129131 'panel.dev ' => true
130132 ]
131133 ]);
132- $ this ->auth = new Auth ($ this ->app );
133- $ this ->assertSame ('dev ' , $ this ->auth ->csrfFromSession ());
134+
135+ $ this ->csrf = new Csrf ($ this ->app );
136+
137+ $ this ->assertFalse ($ this ->csrf ->get ());
134138 }
135139}
0 commit comments