@@ -64,16 +64,19 @@ public function testIsLoggedInTrueWhenSessionDataSet() {
64
64
self ::assertTrue ($ sut ->isLoggedIn ());
65
65
}
66
66
67
- // TODO: Session shouldn't be cleared on call to logout - instead it should
68
- // redirect to the provider, and a new test should asset the response data
69
- // contains a logout confirmation.
70
- public function TODO_UPDATE_testLogoutClearsSession () {
67
+ public function testLogoutCallsLogoutUri () {
71
68
$ sessionData = self ::createMock (SessionData::class);
72
69
$ _SESSION = [
73
70
Authenticator::SESSION_KEY => $ sessionData
74
71
];
75
72
76
73
$ redirectHandler = self ::createMock (RedirectHandler::class);
74
+ $ redirectHandler ->expects (self ::once ())
75
+ ->method ("redirect " )
76
+ ->with (self ::callback (fn (UriInterface $ uri ) =>
77
+ $ uri ->getHost () === "login.authwave.com "
78
+ && $ uri ->getPath () === "/logout "
79
+ ));
77
80
78
81
$ sut = new Authenticator (
79
82
"test-key " ,
@@ -83,6 +86,44 @@ public function TODO_UPDATE_testLogoutClearsSession() {
83
86
$ redirectHandler
84
87
);
85
88
$ sut ->logout ();
89
+ self ::assertNotEmpty ($ _SESSION );
90
+ }
91
+
92
+ public function testCompleteAuthFromLogoutClearsSession () {
93
+ $ token = self ::createMock (Token::class);
94
+
95
+ $ sessionData = self ::createMock (SessionData::class);
96
+ $ sessionData ->method ("getToken " )
97
+ ->willReturn ($ token );
98
+
99
+ $ _SESSION = [
100
+ Authenticator::SESSION_KEY => $ sessionData ,
101
+ ];
102
+
103
+ $ responseCipher = "abcdef " ;
104
+
105
+ $ currentUri = "/example-page- " . uniqid ();
106
+ $ currentUri .= "? " ;
107
+ $ currentUri .= http_build_query ([
108
+ Authenticator::RESPONSE_QUERY_PARAMETER => $ responseCipher ,
109
+ ]);
110
+
111
+ $ redirectHandler = self ::createMock (RedirectHandler::class);
112
+ $ redirectHandler ->expects (self ::once ())
113
+ ->method ("redirect " )
114
+ ->with (self ::callback (fn (UriInterface $ uri ) =>
115
+ $ uri ->getHost () == ""
116
+ && $ uri ->getPath () == $ currentUri
117
+ ));
118
+
119
+ new Authenticator (
120
+ "test-key " ,
121
+ "/ " ,
122
+ LoginUri::DEFAULT_BASE_REMOTE_URI ,
123
+ null ,
124
+ $ redirectHandler
125
+ );
126
+
86
127
self ::assertEmpty ($ _SESSION );
87
128
}
88
129
0 commit comments