Skip to content

Commit

Permalink
Merge pull request #91 from antedebaas/warning-on-no-licence
Browse files Browse the repository at this point in the history
Do not download when licence is not set
  • Loading branch information
peter-gribanov authored Nov 19, 2024
2 parents 5259f9f + 4fe67ed commit 52abe3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Command/UpdateDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->section(sprintf('Update "%s" database', $database));

$this->downloader->download($this->databases[$database]['url'], $this->databases[$database]['path']);

$io->comment(sprintf('Database <info>%s</info> updated', $database));
if (empty($this->databases[$database]['license'])) {
$io->warning(sprintf('GeoIP Database %s has no maxmind license key', $database));
} else {
$this->downloader->download($this->databases[$database]['url'], $this->databases[$database]['path']);
$io->comment(sprintf('Database <info>%s</info> updated', $database));
}
}

$io->success('Finished updating');
Expand Down
25 changes: 25 additions & 0 deletions tests/Command/UpdateDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ public function testInvalidDatabasePath(): void
$command->run($this->input, $this->output);
}

public function testDownloadWithoutLicense(): void
{
$this->input
->expects($this->at(4))
->method('getArgument')
->with('databases')
->willReturn(['default']);

$databases = ['default' => [
'url' => 'https://example.com/GeoIP2.tar.gz',
'path' => '/tmp/GeoIP2.mmdb',
]];

$this->downloader
->expects($this->never())
->method('download')
->with($databases['default']['url'], $databases['default']['path']);

$command = new UpdateDatabaseCommand($this->downloader, $databases);
$command->run($this->input, $this->output);
}

public function testDownloadOneDatabases(): void
{
$this->input
Expand All @@ -201,6 +223,7 @@ public function testDownloadOneDatabases(): void
$databases = ['default' => [
'url' => 'https://example.com/GeoIP2.tar.gz',
'path' => '/tmp/GeoIP2.mmdb',
'license' => 'license',
]];

$this->downloader
Expand All @@ -224,10 +247,12 @@ public function testDownloadSeveralDatabases(): void
'first' => [
'url' => 'https://example.com/GeoIP2-First.tar.gz',
'path' => '/tmp/GeoIP2-First.mmdb',
'license' => 'license',
],
'second' => [
'url' => 'https://example.com/GeoIP2-Second.tar.gz',
'path' => '/tmp/GeoIP2-Second.mmdb',
'license' => 'license',
],
];

Expand Down

0 comments on commit 52abe3d

Please sign in to comment.