class AcquiaSearchUnitTestCase in Acquia Search 6.3
Unit tests of the functionality of the Acquia Search module.
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
- class \AcquiaSearchUnitTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of AcquiaSearchUnitTestCase
File
- tests/
acquia_search.test, line 13
View source
class AcquiaSearchUnitTestCase extends DrupalUnitTestCase {
protected $id;
protected $key;
protected $salt;
protected $derivedKey;
public static function getInfo() {
return array(
'name' => 'Acquia Search unit tests',
'description' => 'Tests the low level Acquia Search functions.',
'group' => 'Acquia',
);
}
/**
* Overrides DrupalTestCase::setUp().
*/
public function setUp() {
parent::setUp();
require_once dirname(dirname(__FILE__)) . '/acquia_search.module';
// Generate and store a random set of credentials.
// Make them as close to the production values as possible
// Something like AAAA-1234
$this->id = $this
->randomAcquiaSearchName(10);
// Most of the keys and salts have a 32char lenght
$this->key = $this
->randomAcquiaSearchName(32);
$this->salt = $this
->randomAcquiaSearchName(32);
// Create a derived key from these values
$this->derivedKey = _acquia_search_create_derived_key($this->salt, $this->id, $this->key);
}
/**
* Tests derived key generation.
*/
public function testDerivedKey() {
// Mimic the hashing code in the API function.
$derivation_string = $this->id . 'solr' . $this->salt;
// str_pad extends the string with the same string in this case
// until it has filled 80 chars.
$derived_key = hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $this->key);
// $this->derivedKey is generated from the API function.
// @see setUp()
$this
->assertEqual($this->derivedKey, $derived_key, t('Derived key API function generates the expected hash.'), 'Acquia Search');
}
/**
* Original randomName function of simpletest did not produce correct results
* so we backported the Drupal 7 simpletest function to Drupal 6 to genuinely
* test the exact same scenario.
*
* @param type $length
* @return string
*/
public static function randomAcquiaSearchName($length = 8) {
$values = array_merge(range(65, 90), range(97, 122), range(48, 57));
$max = count($values) - 1;
$str = chr(mt_rand(97, 122));
for ($i = 1; $i < $length; $i++) {
$str .= chr($values[mt_rand(0, $max)]);
}
return $str;
}
/**
* Tests HMAC generation.
*/
public function testHMACCookie() {
// Generate the expected hash.
$time = REQUEST_TIME;
$nonce = $this
->randomAcquiaSearchName(32);
$string = $time . $nonce . $this
->randomAcquiaSearchName();
$hmac = hash_hmac('sha1', $time . $nonce . $string, $this->derivedKey);
// @todo Make the API function more testable.
$authenticator = acquia_search_authenticator($string, $nonce, $this->derivedKey);
preg_match('/acquia_solr_hmac=([a-zA-Z0-9]{40});/', $authenticator, $matches);
$this
->assertEqual($hmac, $matches[1], t('HMAC API function generates the expected hmac hash.'), 'Acquia Search');
preg_match('/acquia_solr_time=([0-9]{10});/', $authenticator, $matches);
$this
->assertNotNull($matches, t('HMAC API function generates a timestamp.'), 'Acquia Search');
preg_match('/acquia_solr_nonce=([a-zA-Z0-9]{32});/', $authenticator, $matches);
$this
->assertEqual($nonce, $matches[1], t('HMAC API function generates the expected nonce.'), 'Acquia Search');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaSearchUnitTestCase:: |
protected | property | ||
AcquiaSearchUnitTestCase:: |
protected | property | ||
AcquiaSearchUnitTestCase:: |
protected | property | ||
AcquiaSearchUnitTestCase:: |
protected | property | ||
AcquiaSearchUnitTestCase:: |
public static | function | ||
AcquiaSearchUnitTestCase:: |
public static | function | Original randomName function of simpletest did not produce correct results so we backported the Drupal 7 simpletest function to Drupal 6 to genuinely test the exact same scenario. | |
AcquiaSearchUnitTestCase:: |
public | function |
Overrides DrupalTestCase::setUp(). Overrides DrupalUnitTestCase:: |
|
AcquiaSearchUnitTestCase:: |
public | function | Tests derived key generation. | |
AcquiaSearchUnitTestCase:: |
public | function | Tests HMAC generation. | |
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
protected | property | The original database prefix, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | |
DrupalTestCase:: |
public | function | Handle errors during test runs. | |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs verbose message in a text file. | |
DrupalUnitTestCase:: |
protected | function | ||
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |