|
1 | 1 | <?php namespace web\auth\unittest; |
2 | 2 |
|
3 | 3 | use lang\IllegalStateException; |
4 | | -use test\{Assert, Test}; |
| 4 | +use test\{Assert, Test, Values}; |
5 | 5 | use web\auth\{Flow, SessionBased}; |
6 | 6 | use web\io\{TestInput, TestOutput}; |
7 | 7 | use web\session\{ForTesting, ISession}; |
@@ -50,9 +50,32 @@ public function redirects_to_sso() { |
50 | 50 | throw new IllegalStateException('Should not be reached'); |
51 | 51 | })); |
52 | 52 |
|
| 53 | + Assert::equals(302, $res->status()); |
53 | 54 | Assert::equals('https://sso.example.com/', $res->headers()['Location']); |
54 | 55 | } |
55 | 56 |
|
| 57 | + #[Test, Values(['navigate', null])] |
| 58 | + public function redirects_for_top_level_requests($mode) { |
| 59 | + $auth= new SessionBased($this->authenticate(null), new ForTesting()); |
| 60 | + $res= $this->handle(['Sec-Fetch-Mode' => $mode], $auth->required(function($req, $res) use(&$user) { |
| 61 | + throw new IllegalStateException('Should not be reached'); |
| 62 | + })); |
| 63 | + |
| 64 | + Assert::equals(302, $res->status()); |
| 65 | + Assert::equals('https://sso.example.com/', $res->headers()['Location']); |
| 66 | + } |
| 67 | + |
| 68 | + #[Test, Values(['cors', 'no-cors', 'same-origin', 'websocket'])] |
| 69 | + public function sends_401_for_subrequests($mode) { |
| 70 | + $auth= new SessionBased($this->authenticate(null), new ForTesting()); |
| 71 | + $res= $this->handle(['Sec-Fetch-Mode' => $mode], $auth->required(function($req, $res) use(&$user) { |
| 72 | + throw new IllegalStateException('Should not be reached'); |
| 73 | + })); |
| 74 | + |
| 75 | + Assert::equals(401, $res->status()); |
| 76 | + Assert::equals('Authentication required', $res->output()->body()); |
| 77 | + } |
| 78 | + |
56 | 79 | #[Test] |
57 | 80 | public function required() { |
58 | 81 | $sessions= new ForTesting(); |
|
0 commit comments