public function UbercartCreditCardTestCase::testSecuritySettings in Ubercart 7.3
Same name and namespace in other branches
- 6.2 payment/uc_credit/uc_credit.test \UbercartCreditCardTestCase::testSecuritySettings()
Tests security settings configuration.
File
- payment/
uc_credit/ tests/ uc_credit.test, line 181 - Credit card payment method tests.
Class
- UbercartCreditCardTestCase
- Tests credit card payments with the test gateway.
Code
public function testSecuritySettings() {
// TODO: Still need tests with existing key file
// where key file is not readable or doesn't contain a valid key
// Create key directory, make it readable and writeable.
drupal_mkdir('sites/default/files/testkey', 0755);
// Try to submit settings form without a key file path.
// Save current variable, reset to its value when first installed.
$temp_variable = variable_get('uc_credit_encryption_path', '');
variable_set('uc_credit_encryption_path', '');
$this
->drupalGet('admin/store/settings/payment/method/credit');
$this
->assertText(t('Credit card security settings must be configured in the security settings tab.'));
$this
->drupalPost('admin/store/settings/payment/method/credit', array(), t('Save configuration'));
$this
->assertFieldByName('uc_credit_encryption_path', t('Not configured.'), t('Key file has not yet been configured.'));
// Restore variable setting.
variable_set('uc_credit_encryption_path', $temp_variable);
// Try to submit settings form with an empty key file path.
$this
->drupalPost('admin/store/settings/payment/method/credit', array(
'uc_credit_encryption_path' => '',
), t('Save configuration'));
$this
->assertText('Key path must be specified in security settings tab.');
// Specify non-existent directory
$this
->drupalPost('admin/store/settings/payment/method/credit', array(
'uc_credit_encryption_path' => 'sites/default/ljkh/asdfasfaaaaa',
), t('Save configuration'));
$this
->assertText('You have specified a non-existent directory.');
// Next, specify existing directory that's write protected.
// Use /dev, as that should never be accessible.
$this
->drupalPost('admin/store/settings/payment/method/credit', array(
'uc_credit_encryption_path' => '/dev',
), t('Save configuration'));
$this
->assertText('Cannot write to directory, please verify the directory permissions.');
// Next, specify writeable directory, but with excess whitespace
// and trailing /
$this
->drupalPost('admin/store/settings/payment/method/credit', array(
'uc_credit_encryption_path' => ' sites/default/files/testkey/ ',
), t('Save configuration'));
// See that the directory has been properly re-written to remove
// whitespace and trailing /
$this
->assertFieldByName('uc_credit_encryption_path', 'sites/default/files/testkey', t('Key file path has been set.'));
$this
->assertText('Credit card encryption key file generated.');
// Check that warning about needing key file goes away.
$this
->assertNoText(t('Credit card security settings must be configured in the security settings tab.'));
// Remove key file.
drupal_unlink('sites/default/files/testkey/' . UC_CREDIT_KEYFILE_NAME);
// Finally, specify good directory
$this
->drupalPost('admin/store/settings/payment/method/credit', array(
'uc_credit_encryption_path' => 'sites/default/files/testkey',
), t('Save configuration'));
$this
->assertText('Credit card encryption key file generated.');
// Test contents - must contain 32-character hexadecimal string.
$this
->assertTrue(file_exists('sites/default/files/simpletest.keys/' . UC_CREDIT_KEYFILE_NAME), t('Key has been generated and stored.'));
$this
->assertTrue(preg_match("([0-9a-fA-F]{32})", uc_credit_encryption_key()), t('Valid key detected in key file.'));
// Cleanup keys directory after test.
drupal_unlink('sites/default/files/testkey/' . UC_CREDIT_KEYFILE_NAME);
drupal_rmdir('sites/default/files/testkey');
}