From 8487dcd0b9565657e1e6e89c7d8467d54a7c41ba Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 11 Aug 2017 13:17:37 -0400 Subject: [feature] allow manual gateway selection for vpn For now, the way to select a gateway is to add a section in bitmaskd.cfg: [vpn_prefs] locations = ["frankfurt", "seattle__wa"] countries = ["DE", "US"] Note that the location indication has priority over country code. This will be exposed by the UI in release 0.11 - Resolves: #8855 --- tests/unit/vpn/test_gateways.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/vpn/test_gateways.py b/tests/unit/vpn/test_gateways.py index cc7fbca..58b2676 100644 --- a/tests/unit/vpn/test_gateways.py +++ b/tests/unit/vpn/test_gateways.py @@ -126,3 +126,41 @@ class GatewaySelectorTestCase(unittest.TestCase): 14) gateways = selector.select_gateways() assert gateways == [ips[4], ips[2], ips[3], ips[1]] + + def test_apply_user_preferences(self): + preferred = { + 'loc': ['anarres', 'paris__fr', 'montevideo'], + 'cc': ['BR', 'AR', 'UY'], + } + selector = GatewaySelector(preferred=preferred) + pre = [ + ('Seattle', '1.1.1.1', 'US'), + ('Rio de Janeiro', '1.1.1.1', 'BR'), + ('Montevideo', '1.1.1.1', 'UY'), + ('Cordoba', '1.1.1.1', 'AR')] + ordered = selector.apply_user_preferences(pre) + locations = [x[0] for x in ordered] + # first the preferred location, then order by country + assert locations == ['Montevideo', 'Rio de Janeiro', 'Cordoba', 'Seattle'] + + pre = [ + ('Seattle', '', ''), + ('Montevideo', '', ''), + ('Paris, FR', '', ''), + ('AnaRreS', '', '')] + ordered = selector.apply_user_preferences(pre) + locations = [x[0] for x in ordered] + # first the preferred location, then order by country (test normalization) + assert locations == ['AnaRreS', 'Paris, FR', 'Montevideo', 'Seattle'] + + pre = [ + ('Rio De Janeiro', '', 'BR'), + ('Tacuarembo', '', 'UY'), + ('Sao Paulo', '', 'BR'), + ('Cordoba', '', 'AR')] + ordered = selector.apply_user_preferences(pre) + locations = [x[0] for x in ordered] + # no matching location, order by country + assert locations == ['Rio De Janeiro', 'Sao Paulo', 'Cordoba', 'Tacuarembo'] + + -- cgit v1.2.3