Skip to content

Commit

Permalink
Merge pull request #633 from nextcloud/backport/630/stable29
Browse files Browse the repository at this point in the history
[stable29] fix: handle getNetInterfaces error
  • Loading branch information
kesselb authored Jun 25, 2024
2 parents e271395 + ea244b2 commit e4a2fae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ public function getNetworkInfo(): array {
public function getNetworkInterfaces(): array {
$data = [];

foreach ($this->getNetInterfaces() as $interfaceName => $interface) {
try {
$interfaces = $this->getNetInterfaces();
} catch (RuntimeException) {
return $data;
}

foreach ($interfaces as $interfaceName => $interface) {
$netInterface = new NetInterface($interfaceName, $interface['up']);
$data[] = $netInterface;

Expand Down
8 changes: 7 additions & 1 deletion lib/OperatingSystems/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ public function getNetworkInfo(): array {
public function getNetworkInterfaces(): array {
$data = [];

foreach ($this->getNetInterfaces() as $interfaceName => $interface) {
try {
$interfaces = $this->getNetInterfaces();
} catch (RuntimeException) {
return $data;
}

foreach ($interfaces as $interfaceName => $interface) {
$netInterface = new NetInterface($interfaceName, $interface['up']);
$data[] = $netInterface;

Expand Down
10 changes: 10 additions & 0 deletions tests/lib/FreeBSDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ public function testGetNetworkInterfaces(): void {
$this->assertEquals($expected, $actual);
}

public function testGetNetworkInterfacesError(): void {
$this->os->method('getNetInterfaces')
->willThrowException(new RuntimeException('Unable to get network interfaces'));

$expected = [];
$actual = $this->os->getNetworkInterfaces();

$this->assertEquals($expected, $actual);
}

public function testSupported(): void {
$this->assertFalse($this->os->supported());
}
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/LinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,14 @@ public function testGetNetworkInterfaces(): void {

$this->assertEquals($expected, $actual);
}

public function testGetNetworkInterfacesError(): void {
$this->os->method('getNetInterfaces')
->willThrowException(new RuntimeException('Unable to get network interfaces'));

$expected = [];
$actual = $this->os->getNetworkInterfaces();

$this->assertEquals($expected, $actual);
}
}

0 comments on commit e4a2fae

Please sign in to comment.