+ $this->assertFalse($loginManager->isLoggedIn());
+ }
+
+ /**
+ * Check user login - the client cookie does not match the server token
+ */
+ public function testCheckLoginStateStaySignedInWithInvalidToken()
+ {
+ // simulate a previous login
+ $this->session = [
+ 'ip' => $this->clientIpAddress,
+ 'expires_on' => time() + 100,
+ ];
+ $this->loginManager->generateStaySignedInToken($this->clientIpAddress);
+ $this->cookie[CookieManager::STAY_SIGNED_IN] = 'nope';
+
+ $this->loginManager->checkLoginState($this->clientIpAddress);
+
+ $this->assertTrue($this->loginManager->isLoggedIn());
+ $this->assertTrue(empty($this->session['username']));
+ }
+
+ /**
+ * Check user login - the client cookie matches the server token
+ */
+ public function testCheckLoginStateStaySignedInWithValidToken()
+ {
+ $this->loginManager->generateStaySignedInToken($this->clientIpAddress);
+ $this->cookie[CookieManager::STAY_SIGNED_IN] = $this->loginManager->getStaySignedInToken();
+
+ $this->loginManager->checkLoginState($this->clientIpAddress);
+
+ $this->assertTrue($this->loginManager->isLoggedIn());
+ $this->assertEquals($this->login, $this->session['username']);
+ $this->assertEquals($this->clientIpAddress, $this->session['ip']);
+ }
+
+ /**
+ * Check user login - the session has expired
+ */
+ public function testCheckLoginStateSessionExpired()
+ {
+ $this->loginManager->generateStaySignedInToken($this->clientIpAddress);
+ $this->session['expires_on'] = time() - 100;
+
+ $this->loginManager->checkLoginState($this->clientIpAddress);
+
+ $this->assertFalse($this->loginManager->isLoggedIn());
+ }
+
+ /**
+ * Check user login - the remote client IP has changed
+ */
+ public function testCheckLoginStateClientIpChanged()
+ {
+ $this->loginManager->generateStaySignedInToken($this->clientIpAddress);
+
+ $this->loginManager->checkLoginState('10.7.157.98');
+
+ $this->assertFalse($this->loginManager->isLoggedIn());
+ }
+
+ /**
+ * Check user credentials - wrong login supplied
+ */
+ public function testCheckCredentialsWrongLogin()
+ {
+ $this->assertFalse(
+ $this->loginManager->checkCredentials('', '', 'b4dl0g1n', $this->password)
+ );
+ }
+
+ /**
+ * Check user credentials - wrong password supplied
+ */
+ public function testCheckCredentialsWrongPassword()
+ {
+ $this->assertFalse(
+ $this->loginManager->checkCredentials('', '', $this->login, 'b4dp455wd')
+ );
+ }
+
+ /**
+ * Check user credentials - wrong login and password supplied
+ */
+ public function testCheckCredentialsWrongLoginAndPassword()
+ {
+ $this->assertFalse(
+ $this->loginManager->checkCredentials('', '', 'b4dl0g1n', 'b4dp455wd')
+ );
+ }
+
+ /**
+ * Check user credentials - correct login and password supplied
+ */
+ public function testCheckCredentialsGoodLoginAndPassword()
+ {
+ $this->assertTrue(
+ $this->loginManager->checkCredentials('', '', $this->login, $this->password)
+ );
+ }
+
+ /**
+ * Check user credentials through LDAP - server unreachable
+ */
+ public function testCheckCredentialsFromUnreachableLdap()
+ {
+ $this->configManager->set('ldap.host', 'dummy');
+ $this->assertFalse(
+ $this->loginManager->checkCredentials('', '', $this->login, $this->password)
+ );
+ }
+
+ /**
+ * Check user credentials through LDAP - wrong login and password supplied
+ */
+ public function testCheckCredentialsFromLdapWrongLoginAndPassword()
+ {
+ $this->configManager->set('ldap.host', 'dummy');
+ $this->assertFalse(
+ $this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function() { return null; }, function() { return false; })
+ );
+ }
+
+ /**
+ * Check user credentials through LDAP - correct login and password supplied
+ */
+ public function testCheckCredentialsFromLdapGoodLoginAndPassword()
+ {
+ $this->configManager->set('ldap.host', 'dummy');
+ $this->assertTrue(
+ $this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function() { return null; }, function() { return true; })