~fkooman/vpn-user-portal

865f19902500a449e94b02a70d9248d1b50fab1d — François Kooman 3 months ago 8311aff
fix port order, fix tests
2 files changed, 41 insertions(+), 11 deletions(-)

M src/ClientConfig.php
M tests/ClientConfigTest.php
M src/ClientConfig.php => src/ClientConfig.php +6 -1
@@ 160,11 160,16 @@ class ClientConfig
        }

        $clientPortList = [];
        // we use twice the conditional, to keep the same order of ports, we
        // may have to reconsider this though at some point? i.e. first try
        // all available UDP options, and only then try TCP...
        if (!$tcpOnly) {
            self::getItem($clientPortList, $normalUdpPorts, $remoteStrategy);
            self::getItem($clientPortList, $specialUdpPorts, $remoteStrategy);
        }
        self::getItem($clientPortList, $normalTcpPorts, $remoteStrategy);
        if (!$tcpOnly) {
            self::getItem($clientPortList, $specialUdpPorts, $remoteStrategy);
        }
        self::getItem($clientPortList, $specialTcpPorts, $remoteStrategy);

        return $clientPortList;

M tests/ClientConfigTest.php => tests/ClientConfigTest.php +35 -10
@@ 23,7 23,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 37,7 38,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194'],
            ClientConfig::remotePortProtoList(
                ['udp/1194'],
                ClientConfig::STRATEGY_RANDOM
                ClientConfig::STRATEGY_RANDOM,
                false
            )
        );
    }


@@ 51,7 53,8 @@ class ClientConfigTest extends TestCase
            ['udp/443'],
            ClientConfig::remotePortProtoList(
                ['udp/443'],
                ClientConfig::STRATEGY_RANDOM
                ClientConfig::STRATEGY_RANDOM,
                false
            )
        );
    }


@@ 65,7 68,8 @@ class ClientConfigTest extends TestCase
            [],
            ClientConfig::remotePortProtoList(
                [],
                ClientConfig::STRATEGY_RANDOM
                ClientConfig::STRATEGY_RANDOM,
                false
            )
        );
    }


@@ 79,7 83,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/1195', 'tcp/1195'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 93,7 98,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194', 'tcp/443'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/1195', 'tcp/443'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 107,7 113,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194', 'udp/53'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/53', 'tcp/1195'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 121,7 128,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/1195', 'tcp/1195', 'udp/1196', 'tcp/1196', 'udp/1197', 'tcp/1197'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 135,7 143,8 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'tcp/1194', 'udp/443', 'tcp/443'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/443', 'tcp/443'],
                ClientConfig::STRATEGY_FIRST
                ClientConfig::STRATEGY_FIRST,
                false
            )
        );
    }


@@ 149,7 158,23 @@ class ClientConfigTest extends TestCase
            ['udp/1194', 'udp/1195', 'udp/1196', 'udp/1197', 'tcp/1194', 'tcp/1195', 'tcp/1196', 'tcp/443'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/1195', 'tcp/1195', 'udp/1196', 'tcp/1196', 'udp/1197', 'tcp/443'],
                ClientConfig::STRATEGY_ALL
                ClientConfig::STRATEGY_ALL,
                false
            )
        );
    }

    /**
     * @return void
     */
    public function testTcpOnly()
    {
        $this->assertSame(
            ['tcp/1194', 'tcp/1195', 'tcp/1196', 'tcp/443'],
            ClientConfig::remotePortProtoList(
                ['udp/1194', 'tcp/1194', 'udp/1195', 'tcp/1195', 'udp/1196', 'tcp/1196', 'udp/1197', 'tcp/443'],
                ClientConfig::STRATEGY_ALL,
                true
            )
        );
    }