Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Improve isValidSession() to handle LDAP_USERNAME_CASE_SENSITIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Mar 27, 2016
1 parent c52c371 commit 57e5c5f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Auth/ReverseProxyLdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@ public function authenticate()

return false;
}

/**
* Check if the user session is valid
*
* @access public
* @return boolean
*/
public function isValidSession()
{
if (LDAP_USERNAME_CASE_SENSITIVE) {
return $this->request->getRemoteUser() === $this->userSession->getUsername();
}

return strtolower($this->request->getRemoteUser()) === strtolower($this->userSession->getUsername());
}
}
2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.0.0';
return '1.0.1';
}

public function getPluginHomepage()
Expand Down
36 changes: 36 additions & 0 deletions Test/ReverseProxyLdapAuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

require_once 'tests/units/Base.php';

use Kanboard\Plugin\ReverseProxyLdap\Auth\ReverseProxyLdapAuth;

class ReverseProxyLdapAuthTest extends Base
{
public function testIsValidSessionWithRemoteUserNotLowercase()
{
$this->container['request'] = $this
->getMockBuilder('\Kanboard\Core\Http\Request')
->setConstructorArgs(array($this->container))
->setMethods(array('getRemoteUser'))
->getMock();

$this->container['userSession'] = $this
->getMockBuilder('\Kanboard\Core\User\UserSession')
->setConstructorArgs(array($this->container))
->setMethods(array('getUsername'))
->getMock();

$this->container['request']
->expects($this->once())
->method('getRemoteUser')
->will($this->returnValue('MyUser'));

$this->container['userSession']
->expects($this->once())
->method('getUsername')
->will($this->returnValue('myuser'));

$provider = new ReverseProxyLdapAuth($this->container);
$this->assertTrue($provider->isValidSession());
}
}

0 comments on commit 57e5c5f

Please sign in to comment.