Skip to content

Commit

Permalink
testHash for OpauthStrategyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
uzyn committed Jun 8, 2012
1 parent 2ed11ce commit ecbf424
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/Opauth/OpauthStrategyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* OpauthStrategyTest
*
* @copyright Copyright © 2012 U-Zyn Chua (http://uzyn.com)
* @link http://opauth.org
* @package Opauth.OpauthStrategyTest
* @license MIT License
*/

require './lib/Opauth/OpauthStrategy.php';
//require './tests/Opauth/OpauthTest.php';

/**
* OpauthTest class
*/
class OpauthStrategyTest extends PHPUnit_Framework_TestCase{

public function testHash(){
$input = 'random string';
$timestamp = date('c');
$iteration = 250;
$salt = 'sodium chrloride';
$control = OpauthStrategy::hash($input, $timestamp, $iteration, $salt);
$this->assertFalse(empty($control));

// Ensure iteration is taken into account and producing different hash
$diffIteration = OpauthStrategy::hash($input, $timestamp, 888, $salt);
$this->assertFalse(empty($diffIteration));
$this->assertFalse($diffIteration == $control);

$diffIteration2 = OpauthStrategy::hash($input, $timestamp, 99999, $salt);
$this->assertFalse(empty($diffIteration2));
$this->assertFalse($diffIteration2 == $control);
$this->assertFalse($diffIteration2 == $diffIteration);

$diffIteration3 = OpauthStrategy::hash($input, $timestamp, 0, $salt);
$this->assertFalse($diffIteration3);

// Ensure salt is taken into account and producing different hash
$diffSalt = OpauthStrategy::hash($input, $timestamp, $iteration, 'a98woj34 89789&SFDIU(@&*#(*@$');
$this->assertFalse(empty($diffSalt));
$this->assertFalse($diffSalt == $control);

$diffSalt2 = OpauthStrategy::hash($input, $timestamp, $iteration, null);
$this->assertFalse(empty($diffSalt2));
$this->assertFalse($diffSalt2 == $control);
$this->assertFalse($diffSalt2 == $diffSalt);
}

}

0 comments on commit ecbf424

Please sign in to comment.