File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed
Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,12 @@ public function getAdminUri(
111111 );
112112 }
113113
114- public function getLogoutUri ():UriInterface {
115- return new LogoutUri ($ this ->authwaveHost );
114+ public function getLogoutUri (string $ returnToPath = null ):UriInterface {
115+ if (is_null ($ returnToPath )) {
116+ $ returnToPath = $ this ->currentUriPath ;
117+ }
118+
119+ return new LogoutUri ($ this ->authwaveHost , $ returnToPath );
116120 }
117121
118122 private function completeAuth ():void {
Original file line number Diff line number Diff line change @@ -67,31 +67,48 @@ public function testIsLoggedInTrueWhenSessionDataSet() {
6767 self ::assertTrue ($ sut ->isLoggedIn ());
6868 }
6969
70- public function testLogoutClearsSessionAndRedirects () {
70+ public function testLogoutClearsSession () {
7171 $ sessionData = self ::createMock (SessionData::class);
7272 $ _SESSION = [
7373 Authenticator::SESSION_KEY => $ sessionData
7474 ];
7575
76+ $ redirectHandler = self ::createMock (RedirectHandler::class);
77+
78+ $ sut = new Authenticator (
79+ "example-app-id " ,
80+ "test-key " ,
81+ "/ " ,
82+ AuthUri::DEFAULT_BASE_REMOTE_URI ,
83+ null ,
84+ $ redirectHandler
85+ );
86+ $ sut ->logout ();
87+ self ::assertEmpty ($ _SESSION );
88+ }
89+
90+ public function testLogoutRedirectsToCurrentPath () {
91+ $ _SESSION = [];
92+ $ currentPath = "/current/example/path " ;
93+
7694 $ redirectHandler = self ::createMock (RedirectHandler::class);
7795 $ redirectHandler ->expects (self ::once ())
7896 ->method ("redirect " )
7997 ->with (self ::callback (fn (UriInterface $ uri ) =>
8098 $ uri ->getHost () === AuthUri::DEFAULT_BASE_REMOTE_URI
8199 && $ uri ->getPath () === LogoutUri::PATH_LOGOUT
82- && $ uri ->getQuery () === "returnTo= " . urlencode (" / " )
100+ && $ uri ->getQuery () === "returnTo= " . urlencode ($ currentPath )
83101 ));
84102
85103 $ sut = new Authenticator (
86104 "example-app-id " ,
87105 "test-key " ,
88- " / " ,
106+ $ currentPath ,
89107 AuthUri::DEFAULT_BASE_REMOTE_URI ,
90108 null ,
91109 $ redirectHandler
92110 );
93111 $ sut ->logout ();
94- self ::assertEmpty ($ _SESSION );
95112 }
96113
97114 public function testLoginRedirects () {
You can’t perform that action at this time.
0 commit comments