From 43337d58c0be097ca510f2abd1497f13f25bda5b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 2 Jul 2016 17:44:45 -0400 Subject: Preserve role for existing users when using ReverseProxy authentication --- tests/units/Auth/ReverseProxyAuthTest.php | 111 ++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/units/Auth/ReverseProxyAuthTest.php (limited to 'tests/units/Auth') diff --git a/tests/units/Auth/ReverseProxyAuthTest.php b/tests/units/Auth/ReverseProxyAuthTest.php new file mode 100644 index 00000000..cdbc247d --- /dev/null +++ b/tests/units/Auth/ReverseProxyAuthTest.php @@ -0,0 +1,111 @@ +container['request'] = $this + ->getMockBuilder('\Kanboard\Core\Http\Request') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getRemoteUser')) + ->getMock(); + } + + public function testGetName() + { + $provider = new ReverseProxyAuth($this->container); + $this->assertEquals('ReverseProxy', $provider->getName()); + } + + public function testAuthenticateSuccess() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('admin')); + + $provider = new ReverseProxyAuth($this->container); + $this->assertTrue($provider->authenticate()); + } + + public function testAuthenticateFailure() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('')); + + $provider = new ReverseProxyAuth($this->container); + $this->assertFalse($provider->authenticate()); + } + + public function testValidSession() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('admin')); + + $this->container['sessionStorage']->user = array( + 'username' => 'admin' + ); + + $provider = new ReverseProxyAuth($this->container); + $this->assertTrue($provider->isValidSession()); + } + + public function testInvalidSession() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('foobar')); + + $this->container['sessionStorage']->user = array( + 'username' => 'admin' + ); + + $provider = new ReverseProxyAuth($this->container); + $this->assertFalse($provider->isValidSession()); + } + + public function testRoleForNewUser() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('someone')); + + $provider = new ReverseProxyAuth($this->container); + $this->assertTrue($provider->authenticate()); + + $user = $provider->getUser(); + $this->assertEquals(Role::APP_USER, $user->getRole()); + } + + public function testRoleIsPreservedForExistingUser() + { + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('someone')); + + $provider = new ReverseProxyAuth($this->container); + $userModel = new UserModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'someone', 'role' => Role::APP_MANAGER))); + + $this->assertTrue($provider->authenticate()); + + $user = $provider->getUser(); + $this->assertEquals(Role::APP_MANAGER, $user->getRole()); + } +} -- cgit v1.2.3 From 34d0995d55e61474023bbd003d16ac3441d753b6 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 10 Jul 2016 14:18:10 -0400 Subject: Cherry-pick from PR #2435 (Show TOTP Issuer) --- ChangeLog | 4 ++++ app/Auth/TotpAuth.php | 6 ++++-- app/constants.php | 2 ++ tests/units/Auth/TotpAuthTest.php | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'tests/units/Auth') diff --git a/ChangeLog b/ChangeLog index e9407314..9004af40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ New features: * New automated action to close tasks without activity in a specific column * Added the possibility to hide tasks in dashboard for a specific column +Improvements: + +* Display TOTP issuer for 2FA + Version 1.0.31 -------------- diff --git a/app/Auth/TotpAuth.php b/app/Auth/TotpAuth.php index f4304930..8e1ebe35 100644 --- a/app/Auth/TotpAuth.php +++ b/app/Auth/TotpAuth.php @@ -123,7 +123,8 @@ class TotpAuth extends Base implements PostAuthenticationProviderInterface return ''; } - return GoogleAuthenticator::getQrCodeUrl('totp', $label, $this->secret); + $options = array('issuer' => TOTP_ISSUER); + return GoogleAuthenticator::getQrCodeUrl('totp', $label, $this->secret, null, $options); } /** @@ -139,6 +140,7 @@ class TotpAuth extends Base implements PostAuthenticationProviderInterface return ''; } - return GoogleAuthenticator::getKeyUri('totp', $label, $this->secret); + $options = array('issuer' => TOTP_ISSUER); + return GoogleAuthenticator::getKeyUri('totp', $label, $this->secret, null, $options); } } diff --git a/app/constants.php b/app/constants.php index fc120692..40b88fe9 100644 --- a/app/constants.php +++ b/app/constants.php @@ -134,3 +134,5 @@ defined('HTTP_PROXY_PORT') or define('HTTP_PROXY_PORT', '3128'); defined('HTTP_PROXY_USERNAME') or define('HTTP_PROXY_USERNAME', ''); defined('HTTP_PROXY_PASSWORD') or define('HTTP_PROXY_PASSWORD', ''); defined('HTTP_VERIFY_SSL_CERTIFICATE') or define('HTTP_VERIFY_SSL_CERTIFICATE', true); + +defined('TOTP_ISSUER') or define('TOTP_ISSUER', 'Kanboard'); diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php index c8dcfb28..3a82c01c 100644 --- a/tests/units/Auth/TotpAuthTest.php +++ b/tests/units/Auth/TotpAuthTest.php @@ -35,16 +35,17 @@ class TotpAuthTest extends Base public function testGetUrl() { $provider = new TotpAuth($this->container); + $this->assertEmpty($provider->getQrCodeUrl('me')); $this->assertEmpty($provider->getKeyUrl('me')); $provider->setSecret('mySecret'); $this->assertEquals( - 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret', + 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret%26issuer%3DKanboard', $provider->getQrCodeUrl('me') ); - $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me')); + $this->assertEquals('otpauth://totp/me?secret=mySecret&issuer=Kanboard', $provider->getKeyUrl('me')); } public function testAuthentication() -- cgit v1.2.3