You are here

public function RequestSanitizerTest::requestSanitizerTests in Drupal 7

Data provider for testRequestSanitization.

Return value

array A list of tests to carry out.

1 call to RequestSanitizerTest::requestSanitizerTests()
RequestSanitizerTest::testRequestSanitization in modules/simpletest/tests/request_sanitizer.test
Iterate through all the RequestSanitizerTests.

File

modules/simpletest/tests/request_sanitizer.test, line 124
Tests for the RequestSanitizer class.

Class

RequestSanitizerTest
Tests DrupalRequestSanitizer class.

Code

public function requestSanitizerTests() {
  $tests = array();
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
  ));
  $tests['no sanitization GET'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(), array(
    'field' => 'value',
  ));
  $tests['no sanitization POST'] = array(
    $request,
    array(
      'request' => array(
        'field' => 'value',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(), array(), array(), array(
    'key' => 'value',
  ));
  $tests['no sanitization COOKIE'] = array(
    $request,
    array(
      'cookies' => array(
        'key' => 'value',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
  ), array(
    'field' => 'value',
  ), array(), array(
    'key' => 'value',
  ));
  $tests['no sanitization GET, POST, COOKIE'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
      ),
      'request' => array(
        'field' => 'value',
      ),
      'cookies' => array(
        'key' => 'value',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
  ));
  $tests['no sanitization GET log'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
      ),
    ),
    array(),
  );
  $request = new SanitizerTestRequest(array(), array(
    'field' => 'value',
  ));
  $tests['no sanitization POST log'] = array(
    $request,
    array(
      'request' => array(
        'field' => 'value',
      ),
    ),
    array(),
  );
  $request = new SanitizerTestRequest(array(), array(), array(), array(
    'key' => 'value',
  ));
  $tests['no sanitization COOKIE log'] = array(
    $request,
    array(
      'cookies' => array(
        'key' => 'value',
      ),
    ),
    array(),
  );
  $request = new SanitizerTestRequest(array(
    '#q' => 'index.php',
  ));
  $tests['sanitization GET'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(), array(
    '#field' => 'value',
  ));
  $tests['sanitization POST'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(), array(), array(), array(
    '#key' => 'value',
  ));
  $tests['sanitization COOKIE'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(
    '#q' => 'index.php',
  ), array(
    '#field' => 'value',
  ), array(), array(
    '#key' => 'value',
  ));
  $tests['sanitization GET, POST, COOKIE'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(
    '#q' => 'index.php',
  ));
  $tests['sanitization GET log'] = array(
    $request,
    array(),
    array(
      'Potentially unsafe keys removed from query string parameters (GET): #q',
    ),
  );
  $request = new SanitizerTestRequest(array(), array(
    '#field' => 'value',
  ));
  $tests['sanitization POST log'] = array(
    $request,
    array(),
    array(
      'Potentially unsafe keys removed from request body parameters (POST): #field',
    ),
  );
  $request = new SanitizerTestRequest(array(), array(), array(), array(
    '#key' => 'value',
  ));
  $tests['sanitization COOKIE log'] = array(
    $request,
    array(),
    array(
      'Potentially unsafe keys removed from cookie parameters (COOKIE): #key',
    ),
  );
  $request = new SanitizerTestRequest(array(
    '#q' => 'index.php',
  ), array(
    '#field' => 'value',
  ), array(), array(
    '#key' => 'value',
  ));
  $tests['sanitization GET, POST, COOKIE log'] = array(
    $request,
    array(),
    array(
      'Potentially unsafe keys removed from query string parameters (GET): #q',
      'Potentially unsafe keys removed from request body parameters (POST): #field',
      'Potentially unsafe keys removed from cookie parameters (COOKIE): #key',
    ),
  );
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
    'foo' => array(
      '#bar' => 'foo',
    ),
  ));
  $tests['recursive sanitization log'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
        'foo' => array(),
      ),
    ),
    array(
      'Potentially unsafe keys removed from query string parameters (GET): #bar',
    ),
  );
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
    'foo' => array(
      '#bar' => 'foo',
    ),
  ));
  $tests['recursive no sanitization whitelist'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
        'foo' => array(
          '#bar' => 'foo',
        ),
      ),
    ),
    array(),
    array(
      '#bar',
    ),
  );
  $request = new SanitizerTestRequest(array(), array(
    '#field' => 'value',
  ));
  $tests['no sanitization POST whitelist'] = array(
    $request,
    array(
      'request' => array(
        '#field' => 'value',
      ),
    ),
    array(),
    array(
      '#field',
    ),
  );
  $request = new SanitizerTestRequest(array(
    'q' => 'index.php',
    'foo' => array(
      '#bar' => 'foo',
      '#foo' => 'bar',
    ),
  ));
  $tests['recursive multiple sanitization log'] = array(
    $request,
    array(
      'query' => array(
        'q' => 'index.php',
        'foo' => array(),
      ),
    ),
    array(
      'Potentially unsafe keys removed from query string parameters (GET): #bar, #foo',
    ),
  );
  $request = new SanitizerTestRequest(array(
    '#q' => 'index.php',
  ));
  $tests['already sanitized request'] = array(
    $request,
    array(
      'query' => array(
        '#q' => 'index.php',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever?%23test=value',
  ));
  $tests['destination removal GET'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever?%23test=value',
  ));
  $tests['destination removal GET log'] = array(
    $request,
    array(),
    array(
      'Potentially unsafe destination removed from query string parameters (GET) because it contained the following keys: #test',
    ),
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever?q[%23test]=value',
  ));
  $tests['destination removal subkey'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever?q[%23test]=value',
  ));
  $tests['destination whitelist'] = array(
    $request,
    array(
      'query' => array(
        'destination' => 'whatever?q[%23test]=value',
      ),
    ),
    array(),
    array(
      '#test',
    ),
  );
  $request = new SanitizerTestRequest(array(
    'destination' => "whatever?\0bar=base&%23test=value",
  ));
  $tests['destination removal zero byte'] = array(
    $request,
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever?q=value',
  ));
  $tests['destination kept'] = array(
    $request,
    array(
      'query' => array(
        'destination' => 'whatever?q=value',
      ),
    ),
  );
  $request = new SanitizerTestRequest(array(
    'destination' => 'whatever',
  ));
  $tests['destination no query'] = array(
    $request,
    array(
      'query' => array(
        'destination' => 'whatever',
      ),
    ),
  );
  return $tests;
}