Exemple #1
0
 /**
  * Vector tests for the Bonafide's bcrypt mechanism.
  *
  * @test
  * @dataProvider provider_bcrypt
  * @param string $password     Plaintext password
  * @param string $salt         Salt
  * @param int    $iterations   Iterations
  * @param string $expected     Expected value
  */
 public function test_bcrypt($password, $salt, $iterations, $expected)
 {
     $config = array('cost' => '4');
     $hash = Bonafide::mechanism('bcrypt', $config)->hash($password, $salt, $iterations);
     $this->assertSame($hash, $expected);
 }
Exemple #2
0
 public function before()
 {
     $this->acl = Bonafide::acl('blog')->resource('post', array('add', 'publish', 'delete', 'edit', 'view'))->resource('comment', array('add', 'approve', 'delete', 'view'))->role('guest')->allow('guest', 'view')->allow('guest', 'add', 'comment')->role('author', 'guest')->allow('author', 'add', 'post')->allow('author', 'approve', 'comment')->role('publisher', 'author')->allow('publisher', 'publish')->allow('publisher', 'edit', 'post')->allow('publisher', 'delete', 'comment')->role('admin')->allow('admin')->deny('admin', 'publish');
     return parent::before();
 }
Exemple #3
0
 /**
  * Vector tests for the Bonafide's Pbkdf2 mechanism.
  *
  * @test
  * @dataProvider provider_pbkdf2
  * @param string $password     Plaintext password
  * @param string $salt         Salt
  * @param int    $iterations   Iterations
  * @param int    $key_length   Key length
  * @param string $expected     Expected value
  */
 public function test_pbkdf2($password, $salt, $iterations, $key_length, $expected)
 {
     $config = array('type' => 'sha1', 'iterations' => $iterations, 'length' => $key_length);
     $hash = Bonafide::mechanism('PBKDF2', $config)->hash($password, $salt);
     $this->assertSame(bin2hex(base64_decode($hash)), $expected);
 }
Exemple #4
0
 /**
  * Apply configuration and register prefixes.
  *
  * @param  array  configuration settings
  */
 public function __construct(array $config = array())
 {
     if ($config) {
         // Overload config
         $this->config = $config;
     }
     if (isset($this->config['mechanisms'])) {
         foreach ($this->config['mechanisms'] as $prefix => $data) {
             if (isset($data[1])) {
                 // Format: array(string $name, array $config)
                 list($mechanism, $config) = $data;
             } else {
                 // Supported format: array(string $name)
                 // Supported format: string $name
                 // Supported format: object $mechanism
                 $mechanism = is_array($data) ? array_shift($data) : $data;
                 // No configuration has been supplied
                 $config = NULL;
             }
             if (!is_object($mechanism)) {
                 // Load the mechanism and pass in config
                 $mechanism = Bonafide::mechanism($mechanism, $config);
             }
             if (!$mechanism instanceof Bonafide_Mechanism) {
                 throw new Bonafide_Exception('Mechanism class ":class" must extend Bonafide_Mechanism', array(':class' => get_class($mechanism)));
             }
             // Register the mechanism by its prefix
             $this->mechanisms[$prefix] = $mechanism;
         }
     }
 }
Exemple #5
0
 /**
  * Vector tests for the Bonafide's Hash mechanism.
  *
  * @test
  * @dataProvider provider_hash
  * @param string $password     Plaintext password
  * @param string $salt         Salt
  * @param int    $iterations   Iterations
  * @param string $expected     Expected value
  */
 public function test_hash($password, $salt, $iterations, $expected)
 {
     $config = array('type' => 'sha1', 'key' => 'Unit testing for Bonafide');
     $hash = Bonafide::mechanism('hash', $config)->hash($password, $salt, $iterations);
     $this->assertSame($hash, $expected);
 }