public function AcquiaSearchUnitTestCase::testValidResponse in Acquia Connector 7.3
Same name and namespace in other branches
- 7.2 acquia_search/tests/acquia_search.test \AcquiaSearchUnitTestCase::testValidResponse()
Tests validating a response via the API functions.
File
- acquia_search/
tests/ acquia_search.test, line 115 - Tests for the Acquia Search module.
Class
- AcquiaSearchUnitTestCase
- Unit tests of the functionality of the Acquia Search module.
Code
public function testValidResponse() {
// Generate the expected hash.
$nonce = $this
->randomName(32);
$string = $this
->randomName(32);
$hmac = hash_hmac('sha1', $nonce . $string, $this->derivedKey);
// Pass the expected hmac digest, API function should return TRUE.
$valid = acquia_search_valid_response($hmac, $nonce, $string, $this->derivedKey);
$this
->assertTrue($valid, t('Response flagged as valid when the expected hash is passed.'), 'Acquia Search');
// Invalidate the hmac digest, API function should return FALSE.
$bad_hmac = $hmac . 'invalidateHash';
$invalid_hmac = acquia_search_valid_response($bad_hmac, $nonce, $string, $this->derivedKey);
$this
->assertFalse($invalid_hmac, t('Response flagged as invalid when a malformed hash is passed.'), 'Acquia Search');
// Invalidate the nonce, API function should return FALSE.
$bad_nonce = $nonce . 'invalidateString';
$invalid_nonce = acquia_search_valid_response($hmac, $bad_nonce, $bad_nonce, $this->derivedKey);
$this
->assertFalse($invalid_nonce, t('Response flagged as invalid when a malformed nonce is passed.'), 'Acquia Search');
// Invalidate the string, API function should return FALSE.
$bad_string = $string . 'invalidateString';
$invalid_string = acquia_search_valid_response($hmac, $nonce, $bad_string, $this->derivedKey);
$this
->assertFalse($invalid_string, t('Response flagged as invalid when a malformed string is passed.'), 'Acquia Search');
// Invalidate the derived key, API function should return FALSE.
$bad_key = $this->derivedKey . 'invalidateKey';
$invalid_key = acquia_search_valid_response($hmac, $nonce, $string, $bad_key);
$this
->assertFalse($invalid_key, t('Response flagged as invalid when a malformed derived key is passed.'), 'Acquia Search');
}