You are here

public function SecureSiteFunctionDigestValidateUnitTest::testSecureSiteFunctionDigestValidateData in Secure Site 7.2

Same name and namespace in other branches
  1. 6.2 securesite.test \SecureSiteFunctionDigestValidateUnitTest::testSecureSiteFunctionDigestValidateData()

Check output with data.

File

./securesite.test, line 670
Tests for Secure Site module.

Class

SecureSiteFunctionDigestValidateUnitTest
Unit tests for _securesite_digest_validate().

Code

public function testSecureSiteFunctionDigestValidateData() {
  variable_set('securesite_type', array(
    SECURESITE_DIGEST,
  ));
  $user = $this
    ->drupalCreateUser();
  module_load_include('inc', 'securesite');
  $challenge = _securesite_parse_directives(exec($this->digest_md5 . ' realm=' . escapeshellarg($this->realm)));
  $ha1 = md5("{$user->name}:{$challenge['realm']}:{$user->pass_raw}");
  $data = array(
    'username="' . $user->name . '"',
    'realm="' . $challenge['realm'] . '"',
    'uri=/',
    'nonce="' . $challenge['nonce'] . '"',
    'response="' . md5("{$ha1}:{$challenge['nonce']}:" . md5('GET:/')) . '"',
  );
  _securesite_digest_validate($status, array(
    'data' => implode(', ', $data),
    'method' => 'GET',
  ));
  $this
    ->assertTrue(strpos(_securesite_digest_validate($status), 'Authentication-Info') === 0 && $status === 0, t('Checking output with data.'));
}