I'm working on a module that has some business logic around the user agent, but I cannot write functional tests for this because changing the user agent breaks the drupal_valid_test_ua
function which validates if a Drupal request originates from a test.
BrowserTestBase has this code that is called before each request:
protected function prepareRequest() {
$session = $this->getSession();
$session->setCookie('SIMPLETEST_USER_AGENT', drupal_generate_test_ua($this->databasePrefix));
}
Sprinkled throughout core are calls to drupal_valid_test_ua
which has a regex for checking the user agent is valid for a test:
preg_match("/^simple(\w+\d+):(.+):(.+):(.+)$/", $user_agent, $matches)
I propose that the regex be changed to something like this, so other user agent text can be added to the end, separated by a space:
preg_match("/^simple(\w+\d+):(.+):(.+):([^ ]+)/", $user_agent, $matches)
Comment | File | Size | Author |
---|---|---|---|
#14 | allow-user-agent-spoofing-2820515-14.patch | 768 bytes | Nikhil_110 |
#2 | allow-user-agent-spoofing-2820515-2.patch | 850 bytes | bkosborne |
Comments
Comment #2
bkosborneComment #7
pfrenssenWe should add a test that verifies that we can now use custom user agents in tests.
Comment #14
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedAttached patch against Drupal 9.5.x