Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/serverinfo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Dederichs <kai.dederichs@protonmail.com>2022-05-05 19:13:19 +0300
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2022-05-12 13:01:01 +0300
commitffbadc6c0a9bc1e27c0a70580a684a41d63b3646 (patch)
treedcb28dbf385bb9f5c21893c38c193694605391d8
parent22b9f0dff4a453f6a528eeeae7973f1ea9d263b0 (diff)
Make test throw when requesting a non-valid interfacebackport/372/stable24
Signed-off-by: Kai Dederichs <kai.dederichs@protonmail.com>
-rw-r--r--lib/OperatingSystems/FreeBSD.php12
-rw-r--r--tests/lib/FreeBSDTest.php97
2 files changed, 56 insertions, 53 deletions
diff --git a/lib/OperatingSystems/FreeBSD.php b/lib/OperatingSystems/FreeBSD.php
index a9845fe..b51f0f2 100644
--- a/lib/OperatingSystems/FreeBSD.php
+++ b/lib/OperatingSystems/FreeBSD.php
@@ -160,13 +160,13 @@ class FreeBSD implements IOperatingSystem {
preg_match("/\b[0-9].*?(?=base)/m", $intface, $speed);
preg_match("/(?<=\<).*(?=-)/m", $intface, $duplex);
- if (isset($mac[0])) {
- $iface['mac'] = implode(' ', $mac[0]);
- }
+ if (isset($mac[0])) {
+ $iface['mac'] = implode(' ', $mac[0]);
+ }
- if (isset($speed[0])) {
- $iface['speed'] = $speed[0];
- }
+ if (isset($speed[0])) {
+ $iface['speed'] = $speed[0];
+ }
if (isset($status[0])) {
$iface['status'] = $status[0];
diff --git a/tests/lib/FreeBSDTest.php b/tests/lib/FreeBSDTest.php
index e2b43f1..2f5c6e0 100644
--- a/tests/lib/FreeBSDTest.php
+++ b/tests/lib/FreeBSDTest.php
@@ -96,53 +96,56 @@ class FreeBSDTest extends TestCase {
$this->assertEquals(new Memory(), $this->os->getMemory());
}
- public function testGetNetworkInterfacesNoDuplex(): void {
- $this->os->method('executeCommand')
- ->willReturnCallback(static function ($command) {
- if ($command === '/sbin/ifconfig -a') {
- return file_get_contents(__DIR__ . '/../data/freebsd_interfaces');
- }
- if ($command === '/sbin/ifconfig lo0') {
- return file_get_contents(__DIR__ . '/../data/freebsd_interface_lo0');
- }
- if ($command === '/sbin/ifconfig pflog0') {
- return file_get_contents(__DIR__ . '/../data/freebsd_interface_pflog0');
- }
- if ($command === '/sbin/ifconfig epair0b') {
- return file_get_contents(__DIR__ . '/../data/freebsd_interface_epair0b');
- }
- });
-
- $interfaces = $this->os->getNetworkInterfaces();
- $this->assertEquals([
- [
- "interface" => "lo0",
- "ipv4" => "127.0.0.1",
- "ipv6" => "::1 fe80::1",
- "status" => "active",
- "speed" => "unknown",
- "duplex" => "",
- ],
- [
- "interface" => "pflog0",
- "ipv4" => "",
- "ipv6" => "",
- "mac" => "",
- "status" => "active",
- "speed" => "unknown",
- "duplex" => "",
- ],
- [
- "interface" => "epair0b",
- "ipv4" => "192.168.178.150",
- "ipv6" => "",
- "mac" => "1a:c0:4d:ba:b5:82",
- "speed" => "10 Gbps",
- "status" => "active",
- "duplex" => "Duplex: full",
- ]
- ], $interfaces);
- }
+ public function testGetNetworkInterfaces(): void {
+ $this->os->method('executeCommand')
+ ->willReturnCallback(static function ($command) {
+ if ($command === '/sbin/ifconfig -a') {
+ return file_get_contents(__DIR__ . '/../data/freebsd_interfaces');
+ }
+ if ($command === '/sbin/ifconfig lo0') {
+ return file_get_contents(__DIR__ . '/../data/freebsd_interface_lo0');
+ }
+ if ($command === '/sbin/ifconfig pflog0') {
+ return file_get_contents(__DIR__ . '/../data/freebsd_interface_pflog0');
+ }
+ if ($command === '/sbin/ifconfig epair0b') {
+ return file_get_contents(__DIR__ . '/../data/freebsd_interface_epair0b');
+ }
+
+ // Regex matches way more than the interface names, so if it doesn't match any of the defined ones, throw.
+ throw new \RuntimeException();
+ });
+
+ $interfaces = $this->os->getNetworkInterfaces();
+ $this->assertEquals([
+ [
+ "interface" => "lo0",
+ "ipv4" => "127.0.0.1",
+ "ipv6" => "::1 fe80::1",
+ "status" => "active",
+ "speed" => "unknown",
+ "duplex" => "",
+ ],
+ [
+ "interface" => "pflog0",
+ "ipv4" => "",
+ "ipv6" => "",
+ "mac" => "",
+ "status" => "active",
+ "speed" => "unknown",
+ "duplex" => "",
+ ],
+ [
+ "interface" => "epair0b",
+ "ipv4" => "192.168.178.150",
+ "ipv6" => "",
+ "mac" => "1a:c0:4d:ba:b5:82",
+ "speed" => "10 Gbps",
+ "status" => "active",
+ "duplex" => "Duplex: full",
+ ]
+ ], $interfaces);
+ }
public function testSupported(): void {
$this->assertFalse($this->os->supported());