From bfcccd8c33d4c35ad5c65bd1f12451cceb46b270 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 30 May 2021 12:36:58 +0200 Subject: [PATCH] Added test to check for GeoLite db update disabling based on tracking options --- CHANGELOG.md | 17 ++++++++++++ .../test/Util/GeolocationDbUpdaterTest.php | 27 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7df04c1..4e22a961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] +### Added +* *Nothing* + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* [#1100](https://github.com/shlinkio/shlink/issues/1100) Fixed Shlink trying to download GeoLite2 db files even when tracking has been disabled. + + ## [2.7.0] - 2021-05-23 ### Added * [#1044](https://github.com/shlinkio/shlink/issues/1044) Added ability to set names on API keys, which helps to identify them when the list grows. diff --git a/module/CLI/test/Util/GeolocationDbUpdaterTest.php b/module/CLI/test/Util/GeolocationDbUpdaterTest.php index c3897175..0a52660f 100644 --- a/module/CLI/test/Util/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/Util/GeolocationDbUpdaterTest.php @@ -29,11 +29,13 @@ class GeolocationDbUpdaterTest extends TestCase private GeolocationDbUpdater $geolocationDbUpdater; private ObjectProphecy $dbUpdater; private ObjectProphecy $geoLiteDbReader; + private TrackingOptions $trackingOptions; public function setUp(): void { $this->dbUpdater = $this->prophesize(DbUpdaterInterface::class); $this->geoLiteDbReader = $this->prophesize(Reader::class); + $this->trackingOptions = new TrackingOptions(); $locker = $this->prophesize(Lock\LockFactory::class); $lock = $this->prophesize(Lock\LockInterface::class); @@ -46,7 +48,7 @@ class GeolocationDbUpdaterTest extends TestCase $this->dbUpdater->reveal(), $this->geoLiteDbReader->reveal(), $locker->reveal(), - new TrackingOptions(), + $this->trackingOptions, ); } @@ -176,4 +178,27 @@ class GeolocationDbUpdaterTest extends TestCase 'record_size' => 4, ]); } + + /** + * @test + * @dataProvider provideTrackingOptions + */ + public function downloadDbIsSkippedIfTrackingIsDisabled(array $props): void + { + foreach ($props as $prop) { + $this->trackingOptions->{$prop} = true; + } + + $this->geolocationDbUpdater->checkDbUpdate(); + + $this->dbUpdater->databaseFileExists(Argument::cetera())->shouldNotHaveBeenCalled(); + $this->geoLiteDbReader->metadata(Argument::cetera())->shouldNotHaveBeenCalled(); + } + + public function provideTrackingOptions(): iterable + { + yield 'disableTracking' => [['disableTracking']]; + yield 'disableIpTracking' => [['disableIpTracking']]; + yield 'both' => [['disableTracking', 'disableIpTracking']]; + } }