diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-08-18 09:27:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 09:27:07 +0300 |
commit | 17ec9004f99b6f7092740558bca71cca6c1ac23c (patch) | |
tree | c583444ac5e163641ac80ac185a8bec40824699c /tests | |
parent | b5dd5fbdeaf855b55c2817352d5654d8aca0c64b (diff) |
Add feature to exclude tracking requests via config file (#16302)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/RequestTest.php | 165 | ||||
-rw-r--r-- | tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png | 4 |
2 files changed, 167 insertions, 2 deletions
diff --git a/tests/PHPUnit/Integration/Tracker/RequestTest.php b/tests/PHPUnit/Integration/Tracker/RequestTest.php index 1a70f4b90b..a9b017c6ef 100644 --- a/tests/PHPUnit/Integration/Tracker/RequestTest.php +++ b/tests/PHPUnit/Integration/Tracker/RequestTest.php @@ -87,6 +87,171 @@ class RequestTest extends IntegrationTestCase $this->assertSame($this->time, $request->getCurrentTimestamp()); } + private function setTrackerExcludedConfig($exclude) + { + $config = Config::getInstance(); + $tracker = $config->Tracker; + $tracker['exclude_requests'] = $exclude; + $config->Tracker = $tracker; + } + + public function test_isRequestExcluded_nothingConfigured() + { + $request = $this->buildRequest(array('cdt' => '' . ($this->time - 86500))); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_notValidExpression() + { + $this->setTrackerExcludedConfig('foo=bar'); + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_emptyRightValue() + { + $this->setTrackerExcludedConfig('foo=='); + + $request = $this->buildRequest(array('foo' => '')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array()); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'b')); + $this->assertFalse($request->isRequestExcluded()); + + $this->setTrackerExcludedConfig('foo!='); + + $request = $this->buildRequest(array('foo' => '')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array()); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'b')); + $this->assertTrue($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_equals() + { + $this->setTrackerExcludedConfig('foo==bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_not_equals() + { + $this->setTrackerExcludedConfig('foo!=bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_contains() + { + $this->setTrackerExcludedConfig('foo=@bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'fffbar1')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_notContains() + { + $this->setTrackerExcludedConfig('foo!@bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'fffbar1')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'hello')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'ba')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_startsWith() + { + $this->setTrackerExcludedConfig('foo=^bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'fffbar1')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_endsWith() + { + $this->setTrackerExcludedConfig('foo=$bar'); + + $request = $this->buildRequest(array('foo' => 'bar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'bar1')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo' => 'fffbar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('foo1' => 'bar')); + $this->assertFalse($request->isRequestExcluded()); + } + + public function test_isRequestExcluded_multipleComparisons() + { + $this->setTrackerExcludedConfig('foo==test,bar==foo%2Cbar'); + + $request = $this->buildRequest(array('foo' => 'test')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('bar' => 'foo,bar')); + $this->assertTrue($request->isRequestExcluded()); + + $request = $this->buildRequest(array('bar' => 'foo%2Cbar')); + $this->assertFalse($request->isRequestExcluded()); + + $request = $this->buildRequest(array('bar' => 'foo')); + $this->assertFalse($request->isRequestExcluded()); + } + public function test_cdt_ShouldReturnTheCustomTimestamp_IfNotAuthenticatedButTimestampIsRecent() { $request = $this->buildRequest(array('cdt' => '' . ($this->time - 5))); diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png index 183d50f357..ce1f7079ce 100644 --- a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png +++ b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e48f0ab68a157e15ad5f27cea5c1b263ce9fb5f434e9d80f2fb190b31f2952e2 -size 4335592 +oid sha256:6838f53f6909d39435278279e6c578b2242a320009a4989f56ec87ed1f541f40 +size 4421252 |