@@ -14,11 +14,14 @@ class SessionBasedTest {
1414 *
1515 * @param [:var] $headers
1616 * @param web.Handler $handler
17+ * @return web.Response
1718 */
1819 private function handle ($ headers , $ handler ) {
1920 $ req = new Request (new TestInput ('GET ' , '/ ' , $ headers ));
2021 $ res = new Response (new TestOutput ());
21- $ handler ->handle ($ req , $ res );
22+
23+ foreach ($ handler ->handle ($ req , $ res ) ?? [] as $ _ ) { }
24+ return $ res ;
2225 }
2326
2427 private function authenticate ($ result ) {
@@ -28,7 +31,8 @@ private function authenticate($result) {
2831
2932 // Redirect to SSO
3033 $ session ->transmit ($ res );
31- $ this ->redirect ($ res , 'https://sso.example.com/ ' , 'document.location.replace("%1$s"); ' );
34+ $ res ->answer (302 );
35+ $ res ->header ('Location ' , 'https://sso.example.com/ ' );
3236 return null ;
3337 }
3438 ]);
@@ -39,6 +43,16 @@ public function can_create() {
3943 new SessionBased ($ this ->authenticate (null ), new ForTesting ());
4044 }
4145
46+ #[Test]
47+ public function redirects_to_sso () {
48+ $ auth = new SessionBased ($ this ->authenticate (null ), new ForTesting ());
49+ $ res = $ this ->handle ([], $ auth ->required (function ($ req , $ res ) use (&$ user ) {
50+ throw new IllegalStateException ('Should not be reached ' );
51+ }));
52+
53+ Assert::equals ('https://sso.example.com/ ' , $ res ->headers ()['Location ' ]);
54+ }
55+
4256 #[Test]
4357 public function required () {
4458 $ sessions = new ForTesting ();
0 commit comments