Ejemplo n.º 1
0
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new Policy();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 /**
  * Test the evaluation of all policies when no policy name is given
  */
 public function testAllPolicyEvaluateAllAny()
 {
     $set = PolicySet::instance()->add('policy1', Policy::instance()->hasUsername('ccornutt'));
     $user = (object) ['username' => 'ccornutt'];
     $subject = new Subject($user);
     $subject->setAuth(true);
     $context = new Context(['policies' => $set]);
     $gateway = new Gateway($subject, $context);
     // Evaluate the result of the policy above, true because they're:
     //  1. set correctly, 2. policy passes
     $result = $gateway->evaluate();
     $this->assertTrue($result);
 }
Ejemplo n.º 3
0
 /**
  * Test that a false is returned when the user is not allowed
  * 	by the policy
  */
 public function testAllowsSubjectInvalid()
 {
     $policy = Policy::instance()->hasUsername('notrightuser');
     $policySet = PolicySet::instance()->add('policy1', $policy);
     $subject = new Subject((object) ['username' => 'ccornutt']);
     $en = new Enforcer($policySet);
     $this->assertFalse($en->allows('policy1', $subject));
 }
Ejemplo n.º 4
0
 /**
  * Test the creation of a new Policy object with the instance method
  */
 public function testCreateNewInstance()
 {
     $policy = Policy::instance();
     $this->assertInstanceOf('\\Psecio\\PropAuth\\Policy', $policy);
 }