|
35 | 35 | use OCP\ISession;
|
36 | 36 | use OCP\Session\Exceptions\SessionNotAvailableException;
|
37 | 37 | use Test\TestCase;
|
| 38 | +use function json_encode; |
38 | 39 |
|
39 | 40 | class StoreTest extends TestCase {
|
40 | 41 |
|
@@ -140,6 +141,81 @@ public function testGetLoginCredentialsInvalidToken() {
|
140 | 141 | $this->store->getLoginCredentials();
|
141 | 142 | }
|
142 | 143 |
|
| 144 | + public function testGetLoginCredentialsPartialCredentialsAndSessionName() { |
| 145 | + $uid = 'id987'; |
| 146 | + $user = 'user987'; |
| 147 | + $password = '7389374'; |
| 148 | + |
| 149 | + $this->session->expects($this->once()) |
| 150 | + ->method('getId') |
| 151 | + ->willReturn('sess2233'); |
| 152 | + $this->tokenProvider->expects($this->once()) |
| 153 | + ->method('getToken') |
| 154 | + ->with('sess2233') |
| 155 | + ->will($this->throwException(new InvalidTokenException())); |
| 156 | + $this->session->expects($this->once()) |
| 157 | + ->method('exists') |
| 158 | + ->with($this->equalTo('login_credentials')) |
| 159 | + ->willReturn(true); |
| 160 | + $this->session->expects($this->exactly(2)) |
| 161 | + ->method('get') |
| 162 | + ->willReturnMap([ |
| 163 | + [ |
| 164 | + 'login_credentials', |
| 165 | + json_encode([ |
| 166 | + 'uid' => $uid, |
| 167 | + 'password' => $password, |
| 168 | + ]) |
| 169 | + ], |
| 170 | + [ |
| 171 | + 'loginname', |
| 172 | + $user, |
| 173 | + ], |
| 174 | + ]); |
| 175 | + $expected = new Credentials($uid, $user, $password); |
| 176 | + |
| 177 | + $actual = $this->store->getLoginCredentials(); |
| 178 | + |
| 179 | + $this->assertEquals($expected, $actual); |
| 180 | + } |
| 181 | + |
| 182 | + public function testGetLoginCredentialsPartialCredentials() { |
| 183 | + $uid = 'id987'; |
| 184 | + $password = '7389374'; |
| 185 | + |
| 186 | + $this->session->expects($this->once()) |
| 187 | + ->method('getId') |
| 188 | + ->willReturn('sess2233'); |
| 189 | + $this->tokenProvider->expects($this->once()) |
| 190 | + ->method('getToken') |
| 191 | + ->with('sess2233') |
| 192 | + ->will($this->throwException(new InvalidTokenException())); |
| 193 | + $this->session->expects($this->once()) |
| 194 | + ->method('exists') |
| 195 | + ->with($this->equalTo('login_credentials')) |
| 196 | + ->willReturn(true); |
| 197 | + $this->session->expects($this->exactly(2)) |
| 198 | + ->method('get') |
| 199 | + ->willReturnMap([ |
| 200 | + [ |
| 201 | + 'login_credentials', |
| 202 | + json_encode([ |
| 203 | + 'uid' => $uid, |
| 204 | + 'password' => $password, |
| 205 | + ]) |
| 206 | + ], |
| 207 | + [ |
| 208 | + 'loginname', |
| 209 | + null, |
| 210 | + ], |
| 211 | + ]); |
| 212 | + $expected = new Credentials($uid, $uid, $password); |
| 213 | + |
| 214 | + $actual = $this->store->getLoginCredentials(); |
| 215 | + |
| 216 | + $this->assertEquals($expected, $actual); |
| 217 | + } |
| 218 | + |
143 | 219 | public function testGetLoginCredentialsInvalidTokenLoginCredentials() {
|
144 | 220 | $uid = 'id987';
|
145 | 221 | $user = 'user987';
|
|
0 commit comments