Skip to content

Commit

Permalink
Merge pull request #249 from matomo-org/PG-3714-allow-setting-port-zero
Browse files Browse the repository at this point in the history
Fix unable to configure redis socket with port 0, #PG-3714
  • Loading branch information
AltamashShaikh authored Jul 31, 2024
2 parents b03e000 + 65d8b4d commit 04b4df8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ private function createRedisPortSetting()
$self->checkMultipleServersOnlyConfiguredWhenSentinelIsEnabled($value);

if (!$self->isUsingSentinelBackend()) {
(new NumberRange(1, 65535))->validate($value);
(new NumberRange(0, 65535))->validate($value);
} else {
$ports = explode(',', $value);
foreach ($ports as $port) {
(new NumberRange(1, 65535))->validate(trim($port));
(new NumberRange(0, 65535))->validate(trim($port));
}
}
};
Expand Down
16 changes: 11 additions & 5 deletions tests/Integration/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function test_redisHost_ShouldFail_IfMoreThan300CharctersGiven()
public function test_redisPort_ShouldFail_IfPortIsTooLow()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The value needs to be at least 1');
$this->expectExceptionMessage('The value needs to be at least 0');

$this->settings->redisPort->setValue(0);
$this->settings->redisPort->setValue(-1);
}

public function test_redisPort_ShouldFail_IfPortIsTooHigh()
Expand All @@ -63,6 +63,12 @@ public function test_redisPort_ShouldFail_IfPortIsTooHigh()
$this->settings->redisPort->setValue(65536);
}

public function test_redisPort_ShouldNotFail_IfPortIsZero()
{
$this->settings->redisPort->setValue(0);
$this->assertEquals(0, $this->settings->redisPort->getValue());
}

public function test_redisTimeout_ShouldFail_IfTooLong()
{
$this->expectException(\Exception::class);
Expand Down Expand Up @@ -250,8 +256,8 @@ public function test_redisPort_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEn
public function test_redisPort_ShouldNotFailAndConvertToIntWhenMultipleValuesGiven_IfSentinelIsEnabled()
{
$this->enableRedisSentinel();
$this->settings->redisPort->setValue('55 , 44.34 ');
$this->assertSame('55,44', $this->settings->redisPort->getValue());
$this->settings->redisPort->setValue('55 , 44.34, 0 ');
$this->assertSame('55,44,0', $this->settings->redisPort->getValue());
}

public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecified()
Expand All @@ -260,7 +266,7 @@ public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecifie
$this->expectExceptionMessage('The value is not a number');

$this->enableRedisSentinel();
$this->settings->redisPort->setValue('55 , 44.34, 4mk ');
$this->settings->redisPort->setValue('55, 0 , 44.34, 4mk ');
$this->assertSame('55,44', $this->settings->redisPort->getValue());
}

Expand Down

0 comments on commit 04b4df8

Please sign in to comment.