summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Psecio/Gatekeeper/GroupModelTest.php28
-rw-r--r--tests/Psecio/Gatekeeper/PermissionModelTest.php28
-rw-r--r--tests/Psecio/Gatekeeper/PolicyCollectionTest.php45
-rw-r--r--tests/Psecio/Gatekeeper/SecurityQuestionCollectionTest.php24
-rw-r--r--tests/Psecio/Gatekeeper/UserModelTest.php106
5 files changed, 165 insertions, 66 deletions
diff --git a/tests/Psecio/Gatekeeper/GroupModelTest.php b/tests/Psecio/Gatekeeper/GroupModelTest.php
index ef25e90..aa264ad 100644
--- a/tests/Psecio/Gatekeeper/GroupModelTest.php
+++ b/tests/Psecio/Gatekeeper/GroupModelTest.php
@@ -178,4 +178,32 @@ class GroupModelTest extends \Psecio\Gatekeeper\Base
$group = new GroupModel($ds);
$this->assertFalse($group->removeChild(1));
}
+
+ /**
+ * Test that a group is not expired
+ */
+ public function testGroupNotExpired()
+ {
+ $ds = $this->buildMock(true);
+ $group = new GroupModel($ds, [
+ 'id' => 1234,
+ 'expire' => strtotime('+1 day')
+ ]);
+
+ $this->assertFalse($group->isExpired());
+ }
+
+ /**
+ * Test that a group is marked as expired
+ */
+ public function testGroupIsExpired()
+ {
+ $ds = $this->buildMock(true);
+ $group = new GroupModel($ds, [
+ 'id' => 1234,
+ 'expire' => strtotime('-1 day')
+ ]);
+
+ $this->assertTrue($group->isExpired());
+ }
}
diff --git a/tests/Psecio/Gatekeeper/PermissionModelTest.php b/tests/Psecio/Gatekeeper/PermissionModelTest.php
index 989983e..e47f8be 100644
--- a/tests/Psecio/Gatekeeper/PermissionModelTest.php
+++ b/tests/Psecio/Gatekeeper/PermissionModelTest.php
@@ -87,4 +87,32 @@ class PermissionModelTest extends \Psecio\Gatekeeper\Base
$perm = new PermissionModel($ds);
$this->assertFalse($perm->removeChild(1));
}
+
+ /**
+ * Test that a permission is not expired
+ */
+ public function testPermissionNotExpired()
+ {
+ $ds = $this->buildMock(true);
+ $perm = new PermissionModel($ds, [
+ 'id' => 1234,
+ 'expire' => strtotime('+1 day')
+ ]);
+
+ $this->assertFalse($perm->isExpired());
+ }
+
+ /**
+ * Test that a permission is marked as expired
+ */
+ public function testPermissionIsExpired()
+ {
+ $ds = $this->buildMock(true);
+ $perm = new PermissionModel($ds, [
+ 'id' => 1234,
+ 'expire' => strtotime('-1 day')
+ ]);
+
+ $this->assertTrue($perm->isExpired());
+ }
} \ No newline at end of file
diff --git a/tests/Psecio/Gatekeeper/PolicyCollectionTest.php b/tests/Psecio/Gatekeeper/PolicyCollectionTest.php
new file mode 100644
index 0000000..afa9e7a
--- /dev/null
+++ b/tests/Psecio/Gatekeeper/PolicyCollectionTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Psecio\Gatekeeper;
+
+class PolicyCollectionTest extends \Psecio\Gatekeeper\Base
+{
+ /**
+ * Test the location of policies in the system
+ */
+ public function testFindPoliciesList()
+ {
+ $return = array(
+ array('name' => 'policy1', 'expression' => 'test expression'),
+ array('name' => 'policy2', 'expression' => '"group1" in user.groups.getName()')
+ );
+
+ $ds = $this->buildMock($return, 'fetch');
+ $policies = new PolicyCollection($ds);
+
+ $policies->getList();
+ $this->assertCount(2, $policies);
+
+ $policies = $policies->toArray();
+ $this->assertTrue($policies[0] instanceof PolicyModel);
+ }
+
+ /**
+ * Test the location of policies in the system
+ */
+ public function testFindPoliciesListLimit()
+ {
+ $return = array(
+ array('name' => 'policy1', 'expression' => 'test expression')
+ );
+
+ $ds = $this->buildMock($return, 'fetch');
+ $policies = new PolicyCollection($ds);
+
+ $policies->getList(1);
+ $this->assertCount(1, $policies);
+
+ $policies = $policies->toArray();
+ $this->assertTrue($policies[0] instanceof PolicyModel);
+ }
+} \ No newline at end of file
diff --git a/tests/Psecio/Gatekeeper/SecurityQuestionCollectionTest.php b/tests/Psecio/Gatekeeper/SecurityQuestionCollectionTest.php
new file mode 100644
index 0000000..6ea2ccd
--- /dev/null
+++ b/tests/Psecio/Gatekeeper/SecurityQuestionCollectionTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Psecio\Gatekeeper;
+
+class SecurityQuestionCollectionTest extends \Psecio\Gatekeeper\Base
+{
+ /**
+ * Test the location of security questions of a user by ID
+ */
+ public function testFindQuestionsByUserId()
+ {
+ $userId = 1;
+ $return = [
+ ['question' => 'Arthur', 'answer' => 'Dent', 'user_id' => $userId],
+ ['name' => 'Ford', 'description' => 'Prefect', 'user_id' => $userId]
+ ];
+
+ $ds = $this->buildMock($return, 'fetch');
+ $questions = new SecurityQuestionCollection($ds);
+
+ $questions->findByUserId($userId);
+ $this->assertCount(2, $questions);
+ }
+} \ No newline at end of file
diff --git a/tests/Psecio/Gatekeeper/UserModelTest.php b/tests/Psecio/Gatekeeper/UserModelTest.php
index 1e7b671..d1ea4b5 100644
--- a/tests/Psecio/Gatekeeper/UserModelTest.php
+++ b/tests/Psecio/Gatekeeper/UserModelTest.php
@@ -4,6 +4,30 @@ namespace Psecio\Gatekeeper;
class UserModelTest extends \Psecio\Gatekeeper\Base
{
+ private $permissions = array(1, 2, 3);
+ private $groups = array(1, 2, 3);
+
+
+ private function buildPermissionGroupUserMock()
+ {
+ $user = $this->getMockBuilder('\Psecio\Gatekeeper\UserModel')
+ ->disableOriginalConstructor()
+ ->setMethods(array('grantPermissions', 'grantGroups'))
+ ->getMock();
+
+ return $user;
+ }
+
+ private function buildMysqlDataSourceMock($method = 'save')
+ {
+ $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
+ ->disableOriginalConstructor()
+ ->setMethods(array($method))
+ ->getMock();
+
+ return $ds;
+ }
+
/**
* Test that a 0 is returned when no throttle record is found (null)
*/
@@ -279,11 +303,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
$data = array(
array('username' => $username)
);
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('fetch'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock('fetch');
$ds->method('fetch')
->willReturn($data);
@@ -312,11 +332,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantPermissionsByIdValid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(true);
$perms = array(1, 2, 3);
@@ -329,11 +345,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantPermissionsByIdInalid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(false);
$user = new UserModel($ds);
$this->assertFalse($user->grantPermissions(array(1, 2, 3)));
@@ -344,11 +356,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantPermissionsByModelValid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(true);
$perms = array(
@@ -365,11 +373,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantGroupsByIdValid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(true);
$groups = array(1, 2, 3);
@@ -382,11 +386,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantGroupsByIdInvalid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(false);
$user = new UserModel($ds);
@@ -398,11 +398,7 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantGroupsByModelValid()
{
- $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
- ->disableOriginalConstructor()
- ->setMethods(array('save'))
- ->getMock();
-
+ $ds = $this->buildMysqlDataSourceMock();
$ds->method('save')->willReturn(true);
$groups = array(
@@ -419,20 +415,13 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantGroupsAndPermissionsAllValid()
{
- $permissions = array(1, 2, 3);
- $groups = array(1, 2, 3);
-
- $user = $this->getMockBuilder('\Psecio\Gatekeeper\UserModel')
- ->disableOriginalConstructor()
- ->setMethods(array('grantPermissions', 'grantGroups'))
- ->getMock();
-
+ $user = $this->buildPermissionGroupUserMock();
$user->method('grantPermissions')->willReturn(true);
$user->method('grantGroups')->willReturn(true);
$result = $user->grant(array(
- 'permissions' => $permissions,
- 'groups' => $groups
+ 'permissions' => $this->permissions,
+ 'groups' => $this->groups
));
$this->assertTrue($result);
}
@@ -442,20 +431,13 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantGroupsInvalid()
{
- $permissions = array(1, 2, 3);
- $groups = array(1, 2, 3);
-
- $user = $this->getMockBuilder('\Psecio\Gatekeeper\UserModel')
- ->disableOriginalConstructor()
- ->setMethods(array('grantPermissions', 'grantGroups'))
- ->getMock();
-
+ $user = $this->buildPermissionGroupUserMock();
$user->method('grantPermissions')->willReturn(true);
$user->method('grantGroups')->willReturn(false);
$result = $user->grant(array(
- 'permissions' => $permissions,
- 'groups' => $groups
+ 'permissions' => $this->permissions,
+ 'groups' => $this->groups
));
$this->assertFalse($result);
}
@@ -465,20 +447,13 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
*/
public function testGrantPermissionsInvalid()
{
- $permissions = array(1, 2, 3);
- $groups = array(1, 2, 3);
-
- $user = $this->getMockBuilder('\Psecio\Gatekeeper\UserModel')
- ->disableOriginalConstructor()
- ->setMethods(array('grantPermissions', 'grantGroups'))
- ->getMock();
-
+ $user = $this->buildPermissionGroupUserMock();
$user->method('grantPermissions')->willReturn(false);
$user->method('grantGroups')->willReturn(true);
$result = $user->grant(array(
- 'permissions' => $permissions,
- 'groups' => $groups
+ 'permissions' => $this->permissions,
+ 'groups' => $this->groups
));
$this->assertFalse($result);
}
@@ -528,6 +503,5 @@ class UserModelTest extends \Psecio\Gatekeeper\Base
'question' => 'Question #1',
'answer' => 'mypass'
));
- var_export($result);
}
} \ No newline at end of file