[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/sso-kde-org] app: Fix view defaults issue
From:       Sayak Banerjee <sayakb () kde ! org>
Date:       2014-10-26 9:40:56
Message-ID: E1XiKJk-0005gJ-4u () scm ! kde ! org
[Download RAW message or body]

Git commit 62ee3f2120491bf0d2ba16498e5c4e84b35a35ea by Sayak Banerjee.
Committed on 26/10/2014 at 09:40.
Pushed by sayakb into branch 'master'.

Fix view defaults issue

M  +18   -6    app/lib/components/Access.php
M  +2    -2    app/lib/components/Verifier.php
M  +2    -9    app/lib/facades/View.php
M  +20   -0    app/tests/helpers/TestHelper.php
M  +4    -4    app/tests/steps/AuthTest.php
A  +63   -0    app/tests/steps/TokenTest.php

http://commits.kde.org/websites/sso-kde-org/62ee3f2120491bf0d2ba16498e5c4e84b35a35ea

diff --git a/app/lib/components/Access.php b/app/lib/components/Access.php
index 7c59180..99d633f 100755
--- a/app/lib/components/Access.php
+++ b/app/lib/components/Access.php
@@ -237,15 +237,27 @@ class Access {
 	 */
 	public static function manager()
 	{
-		return Cache::tags('security.user.'.Auth::user()->id)->remember('manager', 60, function()
+		if (Auth::check())
+		{
+			return Cache::tags('security.user.'.Auth::user()->id)->remember('manager', 60, function()
+			{
+				return (object) array(
+					'acl' => static::check(ACLFlags::ACL_MANAGE),
+					'field' => static::check(ACLFlags::FIELD_MANAGE),
+					'group' => static::check(ACLFlags::GROUP_MANAGE),
+					'user' => static::check(ACLFlags::USER_MANAGE),
+				);
+			});
+		}
+		else
 		{
 			return (object) array(
-				'acl' => static::check(ACLFlags::ACL_MANAGE),
-				'field' => static::check(ACLFlags::FIELD_MANAGE),
-				'group' => static::check(ACLFlags::GROUP_MANAGE),
-				'user' => static::check(ACLFlags::USER_MANAGE),
+				'acl' => false,
+				'field' => false,
+				'group' => false,
+				'user' => false,
 			);
-		});
+		}
 	}
 
 	/**
diff --git a/app/lib/components/Verifier.php b/app/lib/components/Verifier.php
index 584509e..927901a 100755
--- a/app/lib/components/Verifier.php
+++ b/app/lib/components/Verifier.php
@@ -92,10 +92,10 @@ class Verifier {
 	 * @param  string  $hash
 	 * @return bool
 	 */
-	public static function check($hash)
+	public static function check($token)
 	{
 		// Fetch the token
-		$token = Token::where('token', $hash)->firstOrFail();
+		$token = Token::where('token', $token)->firstOrFail();
 
 		// Get the associated user and email
 		$email = UserEmail::findOrFail($token->permits_id);
diff --git a/app/lib/facades/View.php b/app/lib/facades/View.php
index 0084187..88361ca 100755
--- a/app/lib/facades/View.php
+++ b/app/lib/facades/View.php
@@ -54,16 +54,9 @@ class View extends \Illuminate\Support\Facades\View {
 				'info'      => Session::get('messages.info'),
 				'appconfig' => Config::get('app'),
 				'title'     => null,
+				'auth'      => Auth::user(),
+				'manager'   => Access::manager(),
 			);
-
-			// Assign keys for logged in users
-			if (Auth::check())
-			{
-				static::$defaults = array_merge(static::$defaults, array(
-					'auth'    => Auth::user(),
-					'manager' => Access::manager(),
-				));
-			}
 		}
 
 		return static::$defaults;
diff --git a/app/tests/helpers/TestHelper.php b/app/tests/helpers/TestHelper.php
index 710934c..624cba7 100755
--- a/app/tests/helpers/TestHelper.php
+++ b/app/tests/helpers/TestHelper.php
@@ -177,6 +177,26 @@ class TestHelper {
 		return $field;
 	}
 
+	/**
+	 * Creates a token in the test database
+	 *
+	 * @static
+	 * @access public
+	 * @param  int  $type
+	 * @param  UserEmail  $email
+	 * @return Token
+	 */
+	public static function createToken($type, $email)
+	{
+		$token = Token::create(array(
+			'token'        => str_random(10),
+			'permits_id'   => $email->id,
+			'permits_type' => $type,
+		));
+
+		return $token;
+	}
+
 }
 
 ?>
diff --git a/app/tests/steps/AuthTest.php b/app/tests/steps/AuthTest.php
index bf05b3c..ed1399f 100755
--- a/app/tests/steps/AuthTest.php
+++ b/app/tests/steps/AuthTest.php
@@ -96,7 +96,7 @@ class AuthTest extends KeychainTestCase {
 		));
 
 		$this->assertFalse(Auth::check());
-		$this->assertEquals(Lang::get('auth.account_inactive'), Session::get('messages.error'));
+		$this->assertSessionHas('messages.error', Lang::get('auth.account_inactive'));
 	}
 
 	/**
@@ -117,7 +117,7 @@ class AuthTest extends KeychainTestCase {
 		));
 
 		$this->assertFalse(Auth::check());
-		$this->assertEquals(Lang::get('auth.account_inactive'), Session::get('messages.error'));
+		$this->assertSessionHas('messages.error', Lang::get('auth.account_inactive'));
 	}
 
 	/**
@@ -138,7 +138,7 @@ class AuthTest extends KeychainTestCase {
 		));
 
 		$this->assertFalse(Auth::check());
-		$this->assertEquals(Lang::get('auth.account_blocked'), Session::get('messages.error'));
+		$this->assertSessionHas('messages.error', Lang::get('auth.account_blocked'));
 	}
 
 	/**
@@ -158,7 +158,7 @@ class AuthTest extends KeychainTestCase {
 		));
 
 		$this->assertFalse(Auth::check());
-		$this->assertEquals(Lang::get('auth.login_failed'), Session::get('messages.error'));
+		$this->assertSessionHas('messages.error', Lang::get('auth.login_failed'));
 	}
 
 }
diff --git a/app/tests/steps/TokenTest.php b/app/tests/steps/TokenTest.php
new file mode 100755
index 0000000..0a052d9
--- /dev/null
+++ b/app/tests/steps/TokenTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Keychain
+ *
+ * SSO login provider for enterprise.
+ *
+ * @package     Keychain
+ * @copyright   (c) Keychain Developers
+ * @license     http://opensource.org/licenses/BSD-3-Clause
+ * @link        https://github.com/keychain-sso/keychain
+ * @since       Version 1.0
+ * @filesource
+ */
+
+/**
+ * TokenTest class
+ *
+ * Unit test cases for TokenController
+ *
+ * @package     Keychain
+ * @subpackage  UnitTests
+ */
+class TokenTest extends KeychainTestCase {
+
+	/**
+	 * Tests the getVerify method of the controller with an email token
+	 *
+	 * @access public
+	 * @return void
+	 */
+	public function testGetVerifyEmail()
+	{
+		$email = TestHelper::createUser(UserStatus::ACTIVE, true, false)->emailPrimary;
+		$token = TestHelper::createToken(TokenTypes::EMAIL, $email);
+
+		$this->call('GET', "token/verify/{$token->token}");
+
+		$this->assertResponseOk();
+		$this->assertViewHas('return');
+		$this->assertEquals(Flags::YES, UserEmail::find($email->id)->verified);
+		$this->assertEquals(null, Token::find($token->id));
+	}
+
+	/**
+	 * Tests the getVerify method of the controller with a password token
+	 *
+	 * @access public
+	 * @return void
+	 */
+	public function testGetVerifyPassword()
+	{
+		$email = TestHelper::createUser(UserStatus::ACTIVE, true, false)->emailPrimary;
+		$token = TestHelper::createToken(TokenTypes::PASSWORD, $email);
+
+		$this->call('GET', "token/verify/{$token->token}");
+
+		$this->assertRedirectedTo('auth/reset');
+		$this->assertSessionHas('security.reset.account');
+		$this->assertEquals(null, Token::find($token->id));
+	}
+
+}
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic